LOJ 2065 SDOI 2010 模式字串

2022-04-30 04:27:12 字數 2101 閱讀 6090

題意

hhhhhhhh並不知道為啥,只有三組資料,不過第三組資料夠強,達到了題目描述的\(\sum n\leq10^6\)

實際上\(n=1e6\)才算強吧

只有乙個全域性詢問,考慮點分治,統計串的時候因為\(\)為有序對,所以solve乙個點的時候

要分別記錄x到當前點時作為prefix和suffix的不同hash值,同時對預處理出來的pre和suf值做匹配

如果匹配上了就找對應的在之前子樹裡的殘串,這樣對於每個串匹配前字尾統計答案可以做到\(o(1)\)

這樣的話要開spre和ssuf表示在之前的子樹裡的\(\mod m\)意義下殘串的數量

這樣的話calc每個點複雜度就是線性的,總複雜度\(o(n\log n)\)

注意將乙個子樹的匹配前字尾計入的時候要dfs完整個子樹再進行記錄,不然會有重複答案。

我這裡是把calc的點\(x\)作為字尾計入,所以\(spre_m\)(由\(x\)和其子樹中的一條路徑恰好是模式串的迴圈)一開始為1

當然這樣的話如果\(x\)恰好為模式串最後一位對於缺少\(x\)作為字尾的字首也要計入,即\(ssuf_1\)初始值為1

#include#includeconst int n = 1e5+7;

typedef long long ll;

typedef unsigned long long ull;

#define r register

inline int max(int a, int b)

int last[n], cnt, n, m, up, vis[n];

char a[n];

ull s[n], pre[n], suf[n];

ll ans;

struct edge e[n*2];

inline void add(int u, int v)

int siz, mxson[n], siz[n], rt;

#define base 233ull

#define cerr(x) printf("%d ", x)

//#define cerr(x, y) printf("%d %d\n", x, y)

#define debug printf("gg\n")

void findrt(int x, int fa) mxson[x] = max(siz - siz[x], mxson[x]);

if (mxson[x] < mxson[rt]) rt = x;

}ull spre[n], ssuf[n];

int poi, total;

struct node p[n];

/* inline ull fst(ull x, ull k) return res;

}*/ull fst[n];

void getdis(int x, int fa, ull suffix, ull prefix, ull dep) ;

if (omgy == pre[dep])

ans += ssuf[m - dep % m], p[++total] = (node);

for (int o = last[x]; o; o = e[o].nxt)

}void div(int x)

} while (poi >= 1)

if (s[x] == a[m]) ssuf[1]--;

spre[m]--;

//cerr(ans, x);

//printf("%d %d\n", ans, x);

}void solve(int x)

vis[x] = 0;

}int main() //debug;

}// 97 ~ 122

/* 2

10 4

aaaaaaabbb

2 13 1

4 15 2

6 47 2

8 39 7

10 7

baaa

10 4

aaaaaaabbb

2 13 1

4 15 2

6 47 2

8 39 7

10 7

baaa

*/

Loj2003 SDOI2017 新生舞會

這道題太明顯了,一眼看過去就知道是0 1分數規劃。先用二分列舉mid,假設mid就是c 我們要判斷的是 a 1 a2 a nb1 b2 b n c frac c b1 b2 bn a1 a2 an c 然後我們就可以把分母乘到c上面去,得到 a 1 a2 a n c b1 b2 b n a 1 a ...

SDOI2010 星際競速

10年一度的銀河系賽車大賽又要開始了。作為全銀河最盛大的活動之一,奪得這個專案的冠軍無疑是很多人的夢想,來自傑森座 星的悠悠也是其中之一。賽車大賽的賽場由n顆行星和m條雙向星際航路構成,其中每顆行星都有乙個不同的引力值。大賽要求車手們從一顆與這n顆行星之間沒有任何航路的天體出發,訪問這n顆行星每顆恰...

SDOI2010 星際競速

昨天連續做了兩道網路流 這是第一道 這是道圖論題是肯定的,圖都給你了 那麼問題在於如何建模 問題要求訪問每個點恰好一次 我一開始沒看到這個條件 要求總時間最短,嘗試把問題轉化為一些經典圖論問題比如最短路 很可惜不行,那麼自然想到網路流 組裡面有句戲言叫 一切皆可網路流 比如a b 進一步分析發現單純...