QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#483176#7364. 回文yb13558h45 229ms95316kbC++14925b2024-07-18 12:40:452024-07-18 12:40:45

Judging History

你现在查看的是最新测评结果

  • [2024-07-18 12:40:45]
  • 评测
  • 测评结果:45
  • 用时:229ms
  • 内存:95316kb
  • [2024-07-18 12:40:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
char s[1100000];
int n,q,p[1100000];
int mst[21][1100000];
void init(){
	for(int i=1;i<=n;i++)mst[0][i]=p[i];
	for(int j=1;j<=20;j++)
		for(int i=1;i+(1<<j)-1<=n;i++)
			mst[j][i]=max(mst[j-1][i],mst[j-1][i+(1<<j-1)]);
}
int get(int l,int r){
	if(l>r)return -0x3f3f3f3f;
	int k=__lg(r-l+1);
	return max(mst[k][l],mst[k][r-(1<<k)+1]);
}
int main(){
	scanf("%s",s+1),n=strlen(s+1)*2+1,s[0]='&',s[n+1]='%';
	for(int i=n;i>=1;i--)s[i]=i%2?'$':s[i/2];
	for(int i=1,r,mid;i<=n;i++){
		if(i<=r)p[i]=min(r-i+1,p[r*2-i]);
		else p[i]=1;
		while(s[i+p[i]]==s[i-p[i]])p[i]++;
		if(i+p[i]-1>r)r=i+p[i]-1,mid=i;
	}
	init();
	scanf("%d",&q);
	for(int i=1,l,r;i<=q;i++){
		scanf("%d%d",&l,&r);
		int L=2,R=r-l+1,ans=1;l*=2,r*=2;
		while(L<=R){
			int mid=L+R>>1;
			if(get(l+mid-1,r-mid+1)>mid)ans=mid,L=mid+1;
			else R=mid-1;
		}
		printf("%d\n",ans);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

kmojliclywcyevunhgfnumdzvncnmzbkxjsrkzlyguvjwqmyamvwvidqvfcwnkoolupcrjhynrnlmncqwntqaqtnwqcnmlnrnyhjrcpulooknwcfvqdivwvmaymqwjvugylzkrsmlabbmjltopjasklgawfdbosdlmwahaygutogtvoenkxddmehwokwybkpireouiqqlsfbuqslxjlusnwkzgadxtagewjlchtcezugeguzecthcljwegatxdagzkwnsuljxlsqwlkpvoajknflirxpqcxmyhcgimr
293
...

output:


result:


Test #2:

score: 5
Accepted
time: 4ms
memory: 24316kb

input:

vesjaxxsumewkbahmdfohuzggavsskdplrjqgonwnvtqhqdvxwdvbbvdwxtostthmmzqckepyglcysblxcbcxlbsyclgylyqtthedcqvuoghiyfekmaycoiiumirusuzosmaijqpgrwgcnxtojzyxpnjzyzjnpxyzjotxncgwrgpqjiamsozusurimuiiocyamkefyihgouvpxqdkybihtpmfqfzlwzylmtpgzvzhcrygruvzztttbofobtttzzvurgyrchzvzgptmlyzwlzfqfmpthibykdqxpegpbglnzk...

output:

81
101
71
49
41
59
101
81
87
101
3
21
101
21
101
101
43
101
59
63
23
19
13
101
25
101
21
75
101
27
3
55
101
27
10
23
87
21
23
39
67
1
3
21
101
21
101
3
3
1
55
10
51
7
101
21
35
2
61
41
15
77
21
10
101
89
101
101
1
4
101
3
101
2
101
101
101
47
3
1
3
101
3
59
3
23
101
1
21
101
101
101
1
19
101
1
3
101...

result:

ok 290 lines

Test #3:

score: 5
Accepted
time: 0ms
memory: 34604kb

input:

anuahqplebjsacgumhxqolpgrxqcqzlhxrdthilfysevwdukoaksysixdggqzfjifopilugpdlrihgriaedgcjljuzdyqnyplpovdlvsitjcizogkcjkipzwnbdugpkkcghcpcioksqbnvfeggpzdfcxddppanaqnjdrtczcurvgdhnhuuxmktusuykwqrpjgauznlzcgxahiumnbeendsvdoflmuqaylnmsxgfdelfljnvlkeftwsvqhrxpnyjfwohdomcrqcxhvfvksfkjaihqiksfwdlopmwyhagelhju...

output:

5
1272
594
117
5
5
1666
5
1666
956
1666
5
1438
1666
1666
4
544
258
928
1666
3
5
3
669
5
1666
3
796
1666
4
1666
5
1666
3
1272
1666
746
1272
1666
862
436
590
289
1666
764
576
4
1506
5
1272
1326
638
5
1666
1272
5
3
1666
1064
606
164
752
1272
5
4
1666
804
1666
5
1272
3
5
1666
3
1666
80
5
4
5
1272
298
16...

result:

ok 4991 lines

Test #4:

score: 0
Runtime Error

input:

mfvckuykhckfuqmontrmfcfttxsqnaenocsvdxafpwkpftcwtqwgtsihvaquaudwebxmdijlcrenvivcwbwccmjyxmgmuhdkesgmkcbasghbbwlutayipathsvawcdkkmbdkdiurfsytgjasgsrebgtyjlclkycanipjqlpvxtusmetaxpkwvgilcqnspilinqanxofgxjwqzphraildqdewozyndxbekdknrvbdjgwwvulxfdaqpsziqmrtvlzcabcnouwilynyrbzktbfsfaepmyfjbwuuhvxihiyjicox...

output:


result:


Test #5:

score: 5
Accepted
time: 0ms
memory: 34668kb

input:

piliegnejflgljiidtifmgpcwttkfqexweatzcfecoyuyzpyayapbnenfvjbimyuttkjimtuzpoyhfugdivlxyebblrvgkwowzftkjxjopepbcdkcrioyjjscqnvycmaicuijcdkzizgtyskrkgyflmfvtntfnuikjqyblajyhygopbgpmxruwkkkuqszuuxhorfzsyzgpnxcuifrlvieeeavsrrgthetamjemxekupmclxitasqoqrokhtvomrjlksomhagdxyarqqoqhzuiqlhinhizujhkziqnabxnguz...

output:

4
96
1667
3
1667
1
791
791
603
3
3
1407
96
3
4
1667
583
4
319
757
1667
1319
791
563
725
1667
791
901
1667
1221
791
182
1667
1667
1667
1563
5
291
96
179
119
3
1045
4
1249
845
1667
1667
1667
753
96
9
1667
182
291
95
182
791
205
96
182
263
1667
1667
527
291
1445
1667
1667
1667
1
1667
791
281
291
1667
7...

result:

ok 4995 lines

Test #6:

score: 0
Runtime Error

input:

syucmgkigdlpevdxsshewqirqqcdljqjgaugkvzplmidhvwxeuhuzmzscczopnaviqlgnavpezpquyupilccvjsqfxjmpcsefwerqlgfitezkaffvdwlyhilzflbjecsikzvyecgpjkucqukkrauolgzffotznjxmbvcmsuzrwstehxgqzygfjfybzmyuoxvshelxlpzfxwalgxzlwvhsbaikzsgjkzvzjmlbhgubzcunksleqdgulmysfjashpwjymspmtoxiwaiimcbdqbbudlwbptrusyumtszzwbpmgg...

output:


result:


Test #7:

score: 5
Accepted
time: 11ms
memory: 47600kb

input:

acfojkhxkvgskemxswoddjrxylgurlpfkpkhssmaqavonpjkhozprsffoslcluvabbpmynaucitshgbfrhilbxuyvdeilculqepksnsosdruqnzkrismdmpypuwigcwmlrynryysiazxaikbsvsxhwobtxuriupwxfmotimszqrfqqcfcukzmghijkeibpndndbodgzpuzqyznrjpzykhzmgrcxhexbsjmanfybqvojzbwpyttmrneejcpdncuzcjdmgxevqmbltpkotcywnfglumjpldxytuaahbgdcnges...

output:

5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
5769
...

result:

ok 49991 lines

Test #8:

score: 5
Accepted
time: 19ms
memory: 49368kb

input:

aaxvxlcltrlilgqvklenrxdcqzouiizataquwymdxtkzyenpdefayzmwugrysrxpwznxpesvcglwqokoajclkeiadelfupalmwhpceexzuzethlcuidgwekhrzvacntvtfmlqptdszlphlewmmwzwcdmjwpefntdlcdrrhejjhakjpkglpbyooqkdhkzrswpmlseuqobyzrquhtdqlbfegkolncwaqoyxrmelvysykpsschwcghzecwneoklalscjqgxoqilbisabofjebktbbzomfupjqcupolpowbtazlq...

output:

3297
12041
5
7
11677
1437
12041
5
87
14909
139
5
9
12041
15139
1157
5
12041
14913
12743
16665
7
16665
12041
5
3
7
5401
7
16665
16665
12041
8959
12041
5
5
11759
12041
7313
16665
12041
16665
4495
2954
11105
16665
7855
8511
12041
2954
1351
14139
2954
12041
16665
5
6633
4971
13327
7
2954
16473
5
16665
1...

result:

ok 49995 lines

Test #9:

score: 0
Runtime Error

input:

bydjourdrgeaxhanforissxtcbtoqpcslsmsuipplgpyitlspqplflboqptqnahqwzchrjhifexlgnmbsehwkwjzojfwvhmmuatwkozdvqwxcorhmhirdgzkztmzegneseslmxuuoifnakuwsycrcgkzpnspyvvfrcbutiknycrvsqgglsvritrrmilxhhrtclxzslysblwsimexxkodgizphdapogypdudlssdispudgxhnfidsyivbvgamsujzzelovuilauyzmstgpgqipmhnbqskffrjjfnzhotbnlzk...

output:


result:


Test #10:

score: 0
Runtime Error

input:

hsfcfbhlqerzkkwsyslalaslnahwpqqhkflavreluedfhcprzyfaipqyzaupdypfannefsdhimxnxoxbaqfktuqcgkjhskocyzeyyvbimybpixxgygccyqjcysqsylrhqrblfqrvheoolimkvqejywdjeuzbhhqdafuybfkarmacprqkqadbrfsrehhthtginqqhwdukdzjfrtgyepxmrnpmrokehpzxtnbigekjlvwkeofqrayiodxshtdbiisdyrboacqktisjtdkfuzmuzrmhgdqewukdcufjrqtskxjk...

output:


result:


Test #11:

score: 0
Runtime Error

input:

uqgylihdxuhtoedyzgzsnwjfaxxdrbadecbkxhbwvzztggrcvorlbgdobvnlswamdnehzepqdqeajrhfwkavapzqvbivztnsqtqnjxjejpgokdyyfxrsuxblzpftwbdkxvrczcerpjadlkqxieyslegpwgwuvzixavdbbtzcvuvnyjpjqvzfzcdnypukljhlspedodczoamlqokdljxdwtonfavmwxemmwicpfbcxfriiqymwizfjghzskzsxyzpluyjwvwyjjzjdddhoflaizakyjzmjmucfxrowqmiiiqp...

output:


result:


Test #12:

score: 5
Accepted
time: 24ms
memory: 47240kb

input:

senpfhuxjnjduvkehgshpecrhtmrsjqaeosajatkkrtdwodqmsfmvoxyipcqjddyxbrroqpkhujinzclqudwqhehxvbpsdqnxzhkjoipcqkqddetmordwjpsuqzoerllzmzbwuorrbmwbzjoycmpeyotbhcwdxygeeqgxbwcqlrywyruatywmmvgckvaowvjpeegwhzarnabqopxpkbtrkhyqauthnzkdmmfdxxfawxygtuzmmbdzhxhstkgtjgzaprjstmssfpczmyyqryfxycoimzobpbihnnmsocfegkc...

output:

5
7
8596
12104
5
7
7
5
7
5
13534
7568
2650
5
5
22962
7
4
5
8622
7
5
11326
5
5
7
5
3642
16368
5
7
7634
15868
7
10216
5
7
7
7
7
7
11442
5
384
23390
5
22920
24996
5
7
6482
8236
11560
5
7
7
6
7
6442
7
6
7
5
7
4280
7
5
684
13156
5
3002
5
7
7
7
14064
5
5
5
5418
5
14086
2900
5
5
7
7114
5
19688
8098
5
5
192...

result:

ok 49996 lines

Test #13:

score: 5
Accepted
time: 17ms
memory: 49232kb

input:

nwsiebavjnlnjifvaylnhfzybafysczcmrzplqehpgkavzaddjbltazcotufbdzxetxrwhshlxgoqdvbwrkeqkhsbujudbcjhahwkbluvnvdvdxnwocvdkjilwcziqdivzvdlbfwzdenmqlienvoqveubtdoszndqutfsguooniomoyblyxteyhpwommzvnumpwmzqafvfgmnokjwwnkdofoikamvlrxrfkvmrxmsrknmojvaumkrsrlgnpriipbnsbqvglegyhjdefpjngwtbknuivlyftjlsxgffnsjvib...

output:

5
2502
5830
2502
10753
2502
10753
759
9947
3990
2502
2502
4987
2502
10753
3723
10753
3489
759
7
10753
5
5830
5830
7
5
5830
7517
7
5830
2502
5
2428
10753
10753
10753
2502
10753
10753
2502
833
7299
5
6371
2502
5
10753
10753
5
2
5830
5
10753
6891
10753
5
7
5830
10753
10753
5481
5
2502
3014
8619
2502
25...

result:

ok 49992 lines

Test #14:

score: 0
Runtime Error

input:

uoqxubtwiuvrweemnisntsggdzuataqgegovblspuctnszgscxridxjlgibfbtdetqrhkfzzvbkbufeisycazjudefsyvgraenfjynszhdjtzidepogsvltustouvnviyrdsncubobnlkruzcsxsabwayfldakyslzfprixpbgpzlfneokxjtnmgtwipkddbmmeahowhndbnuymxryrkgolobkenugcpyfcelqpnpwwphnufpjcxwjyxlcsutfogqlepvyfcjohvhqivjefwtkwubjgtlsabqnpdpixgnrvw...

output:


result:


Test #15:

score: 0
Runtime Error

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaakkeiauuzvxheynhjstrlmdjuyadlukikotjzhqkfxlyabcfwkdyqkgsrkeqcpingbwuhlvlqcwrnotohwdcteumlrepoccfdfznrdltjbjkjzqkdiglyqxwbukxvlivpbhdtzdxsiaqyoqsykspneectkcrlupikmvnqqtbvicmjgwzonahfpytentjnwqunjlpalkwpcskwlqcarzzlktnklalcmplozonpmfpysuyqviwslsfhnzcbplzhyhs...

output:


result:


Test #16:

score: 0
Runtime Error

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaytvhrajhtxhttnnlmeqimzzsjscccivbyritmiznnvgksdehrtmiwacnbixkxnjytuzimzssogvxaemlcpkdtimzfxqreghsbnsqpkwcfepbisgnmispquhyzeqapvpjdfjelclvezqsdjxndhuwxloghiljexxirocvfcpgrilpxspmzjkvhyifkptzguxohzyyjuxqahbblayluiktzmrsgrhthdypkigvjqngfuwkchfepqfvhyuyunfrhluvcdyhvbpktdfoyy...

output:


result:


Test #17:

score: 0
Runtime Error

input:

aaaazkvsgnabokhungreeglngwrtynocgzehwlqgkiiiqdloxdezdcdbhriugyqfqhhaproemijuhymtacrerxmwdzzputjzucaygdskcwpvxdvuafnpfttarbksdowftsieylqlmpcvyrvhtdorechiduhgxkicaicbrcploefuuzmucorweejnscoepoijalirxzxrxbkksvuimwavmhxhhwndfkwocguaojzgtpxwtjmlrkbpbwvjtcilnyjjkmymvwaylhgmobosditopkpmmsawqlricifwcnwvxqac...

output:


result:


Test #18:

score: 5
Accepted
time: 215ms
memory: 95316kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaebhhrvkfkvewwgcwzupqagltrbvbpsmrzhqqrzpphdatdovtqcskottjjaijncilycjoqvhjbvaorrczwefumogmkipliwrjgjcmcksniyjpowbzpezlmkkiivhadolbahzjlelwurmdhfktndmcqndtbimufcsilykijsbmlqrxlfkimnzghkxgtqgznzgcgmrkygvzbdizbraghkncugpszudehqyuhkywdzdbitixbamapwgzbzknwypluul...

output:

166667
166667
7
34769
7
166667
24819
76849
166667
46449
48105
108561
4533
86703
46253
149297
7
7
68287
27049
166667
44129
166667
6
112091
64755
166667
7
7
162109
44129
7
32987
146665
166667
5
7
7
142777
7
4533
47363
7
7
7
163333
161803
7
52177
166667
73871
119293
166667
7
35455
7
22301
7
30599
67517...

result:

ok 499995 lines

Test #19:

score: 0
Runtime Error

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalvgbspddxrtwkccxskalmiaahvuaaevjkzxskmumnesqsjfqlgkanmmdinkbiabnrmvocequrnicjqzdatwwdzpgyoumwymnsjnklvbjrswytpqejlgxcmoaqqvpihlghjrsyvcoxhvprkfusafjsdrgopnfufkoopyqetppxuciqcwjxldgtwcthdepfcxdvrrhxcxdmsjnukgpdgkknnwzwmtavzvynhsapujivwmjlsaybeuaftemhzpmuexavqmhvpfou...

output:


result:


Test #20:

score: 5
Accepted
time: 229ms
memory: 92900kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaairvzomrstpfklvpyiboqxtnqbjazhstswwhmrdgbzsstvkrtencmmeqjfclkztnlsrrghcfrfrivxfrrpnwehishsneqljlmqwkugitnkuotmncikpvxzvgxcvdppekdbomsvqupgpjdcowzqfoxcivupvucxstsjlrlylvlzmqcxtqdwztpxmzetubgxllckejlkwjytrvdwmimdencuffcdifrllsoihxnbhoyy...

output:

7
5
7
133041
6061
55837
133041
55837
7
55837
61641
53009
5
30553
133041
133041
115561
133041
132637
7
133041
55837
44822
1541
133041
133041
1551
6
1541
64617
33701
5
4013
132119
6
133041
1541
44822
44822
36611
55837
133041
90091
133041
1541
1541
1541
9
2511
133041
133041
82999
6
133041
7
55837
5
133...

result:

ok 499995 lines