UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210918#2067. 肉夹馍shiruiheng1002564ms190644kbC++111.8kb2024-08-08 10:21:472024-08-08 14:28:33

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//using LL = __int128
#define pi pair<ll, ll>
#define N 2222222
#define base 1000000093
#define mod 1234429061
int n, nxt[N][24];
ll h[33333], p[33333] = {1};
char s[N];
bool cmp(int l, int r, int x, int y){
	if(x <= r)
		return false;
	for(int i = l, j = x ; i <= r ; i++, j++)
		if(s[i] != s[j])
			return false;
	return true;
}
ll calc(ll l, ll r){
	return ((h[r] - h[l - 1] * p[r - l + 1] % mod) % mod + mod) % mod;
}
void debug(int l, int r){
	cerr << "\n" << l << " " << r << " " << calc(l, r) << "\n";
}
bool check(int tot, int len){
	//debug(1, len);
	//debug(tot - len + 1, tot);
	return calc(1, len) == calc(tot - len + 1, tot);
}
int main(){
	scanf("%s", s + 1);
	n = strlen(s + 1);
	if(n <= 100){
		for(int i = 1 ; i <= n ; i++)
			for(int len = (i - 1) / 2 ; len >= 0 ; len--){
				if(cmp(1, len, i - len + 1, i)){
					printf("%d ", len);
					break;
				}
			}
		return 0;
	}
	if(n <= 3000){
		for(int i = 1 ; i <= n ; i++){
			h[i] = (h[i - 1] * base + s[i]) % mod;
			p[i] = p[i - 1] * base % mod;
		}
		for(int i = 1 ; i <= n ; i++){
			int l = 0, r = ((i - 1) >> 1);
			for(int j = r ; j >= l ; j--){
				if(check(i, j)){
					printf("%d ", j);
					break;
				}
			}
		}
		return 0;
	}
	for(int i = 2 ; i <= n ; i++){
		int x = nxt[i - 1][0];
		while(x && s[x + 1] != s[i]){
			x = nxt[x][0];
		}
		if(s[i] == s[x + 1])
			nxt[i][0] = (x + 1);
		else
			nxt[i][0] = 0;
		if(n <= 2000000){
			for(int j = 1 ; j <= __lg(i) ; j++){
				nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
			}
		}
	}
	if(n <= 2000000){
		for(int i = 1 ; i <= n ; i++){
			int t = i;
			for(int j = __lg(i) ; j >= 0 ; j--)
				if(nxt[t][j] > ((i - 1) >> 1))
					t = nxt[t][j];
			printf("%d ", nxt[t][0]);
		}
		return 0;
	}
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

qpbvqpbvqpbvavdqpbvqpbvqpbvavdqpbvqpbvqpbvavdfnfninqpbvqpbvqpbvavdqpbvqpbvqpbvavdqpbvqpbvqpbvavd

output:

0 0 0 0 1 2 3 0 1 2 3 4 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...

result:

ok 96 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 1184kb

input:

wfalgbgweavpwhfahfewhavweahuwbvbqvuivhuiaehufuaeuvdafuivjafislfhbibcuuiabcuibsv

output:

0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 79 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 1184kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

output:

0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...

result:

ok 100 tokens

Subtask #2:

score: 20
Accepted

Test #4:

score: 20
Accepted
time: 0ms
memory: 1236kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...

result:

ok 3000 tokens

Test #5:

score: 0
Accepted
time: 0ms
memory: 1236kb

input:

cjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcj...

output:

0 0 1 0 1 2 3 2 3 4 5 4 5 6 7 6 7 8 9 8 9 10 11 10 11 12 13 12 13 14 15 14 15 16 17 16 17 18 19 18 1...

result:

ok 3000 tokens

Test #6:

score: 0
Accepted
time: 6ms
memory: 1232kb

input:

ckcckckcckcckckcckcckckcckcckckcsdvhckcckckcckcckckcckcckckcckcckckcsdvhckcckckcckcckckcckcckckcckcc...

output:

0 0 1 1 2 1 2 3 4 2 3 4 5 6 7 3 4 5 6 4 5 6 7 8 9 10 11 12 13 14 15 8 0 0 0 0 1 2 3 4 5 6 7 8 9 10 1...

result:

ok 2828 tokens

Subtask #3:

score: 30
Accepted

Test #7:

score: 30
Accepted
time: 14ms
memory: 10660kb

input:

aocnsaosashoicfaaocnsaosashoicfaqowfwpqgvqvhoabcdoawaocnsaosashoicfaaocnsaosashoicfaqowfwpqgvqvhoabc...

output:

0 0 0 0 0 1 2 0 1 0 0 0 0 0 0 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 ...

result:

ok 100000 tokens

Test #8:

score: 0
Accepted
time: 18ms
memory: 10660kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...

result:

ok 100000 tokens

Test #9:

score: 0
Accepted
time: 26ms
memory: 10660kb

input:

vivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivi...

output:

0 0 1 0 1 2 3 2 3 4 5 4 5 6 7 6 7 8 9 8 9 10 11 10 11 12 13 12 13 14 15 14 15 16 17 16 17 18 19 18 1...

result:

ok 100000 tokens

Subtask #4:

score: 40
Accepted

Test #10:

score: 40
Accepted
time: 569ms
memory: 190644kb

input:

aoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhd...

output:

0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...

result:

ok 2000000 tokens

Test #11:

score: 0
Accepted
time: 577ms
memory: 190644kb

input:

abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabac...

output:

0 0 1 0 1 2 3 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

result:

ok 2000000 tokens

Test #12:

score: 0
Accepted
time: 674ms
memory: 190640kb

input:

gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg...

output:

0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...

result:

ok 2000000 tokens

Test #13:

score: 0
Accepted
time: 680ms
memory: 190640kb

input:

duududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuudu...

output:

0 0 0 1 2 1 2 3 4 2 1 2 3 4 5 6 7 8 9 5 6 7 8 9 10 11 12 13 14 10 11 12 13 14 15 16 17 18 19 15 16 1...

result:

ok 2000000 tokens