bzoj 1692 字尾陣列

2021-06-28 23:26:55 字數 802 閱讀 6685

將乙個字串進行如下操作:每次拿去首或尾,放在新字串尾,問新字串字典序最小的情況。

直覺貪心,但情況複雜。可以用字尾陣列,每次比較當前剩餘串正序和倒序哪種字典序小,可以如下構建:

abcd -> abcd0dcba

#include #include #include #include #include #include #define rep(i, x, y) for (int i = x; i <= y; i ++)

#define repe(i, x) for (int i = pos[x]; i; i = g[i].nex)

#define dwn(i, x, y) for (int i = x; i >= y; i --)

using namespace std;

typedef long long ll;

const int n = 60005;

int n, a[n], t1[n], t2[n], c[n], n0, sa[n], rk[n], az;

char s[n], ans[n];

bool cmp(int *r, int x, int y, int l)

void bsa(int *a, int n, int m)

rep(i, 0, n) rk[ sa[i] ] = i;

}int main()

for (int i = 1; i <= n0; i ++)

if (az % 80 != 0) puts("");

return 0;

}

bzoj1692 佇列變換

題目鏈結 首先肯定想到貪心,從隊尾和隊首取更小的那個。但是如果遇到隊尾和隊首一樣大的情況呢,總不能再挨個往前比較。所以就把整個字串倒過來再掛到現在字串的後面,也就是把當前字串對稱過去。然後求出字尾陣列,給每個字尾都求個排名。然後每次取得時候取排名更小的就行了。注意這個題的輸出格式,每80個字元輸出為...

bzoj 2119 字尾陣列

題意 給乙個串,求形如aba,其中b的長度為m,a的長度不限的子串的數量。求正串反串的字尾陣列和對於h的rmq。列舉a串長度len,對於每個長度為len的區間處理在這段區間開始的子串個數。每隔len列舉i,然後用rmq求i和i len m的最長公共字首字尾l,r。統計長度為len的在區間 i l 1...

BZOJ1031(字尾陣列)

題意 給出乙個字串,求出所有全排列後,按字典序從小到大排序,每個串的最後一位組成的字串 題解 字尾陣列搞一搞,將他複製一遍,跑乙個sa,那麼對於長度n以後的字串在sa中可以不管,算是個模板題吧 include include include include include include inclu...