QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#483714 | #7364. 回文 | Include_Z_F_R_ | 70 | 18ms | 39724kb | C++14 | 2.1kb | 2024-07-19 09:16:29 | 2024-07-19 09:16:29 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll Read() {
int sig = 1;
ll num = 0;
char c = getchar();
while(!isdigit(c)) {
if(c == '-') {
sig = -1;
}
c = getchar();
}
while(isdigit(c)) {
num = (num << 3) + (num << 1) + (c ^ 48);
c = getchar();
}
return num * sig;
}
void Write(ll x) {
if(x < 0) {
putchar('-');
x = -x;
}
if(x >= 10) {
Write(x / 10);
}
putchar((x % 10) ^ 48);
}
const int N = 500005;
int f[N];
void Manacher(string s) {
int i, n = s.size(), l = 0, r = -1;
for(i = 0; i < n; i++) {
int k = (i > r) ? 1 : min(f[l + r - i], r - i + 1);
while(k <= i && i + k < n && s[i - k] == s[i + k]) {
k++;
}
f[i] = k--;
if(i + k > r) {
l = i - k;
r = i + k;
}
}
}
int lg[N];
void Init_lg(int n) {
int i;
for(i = 2; i <= n; i++) {
lg[i] = lg[i >> 1] + 1;
}
}
struct ST_Table {
int f[25][N];
void Init(int n, int a[]) {
int i, j;
for(i = 1; i <= n; i++) {
f[0][i] = a[i];
}
for(j = 1; j <= lg[n]; j++) {
for(i = 1; i + (1 << j) - 1 <= n; i++) {
f[j][i] = max(f[j - 1][i], f[j - 1][i + (1 << (j - 1))]);
}
}
}
int Query(int l, int r) {
int len = lg[r - l + 1];
return max(f[len][l], f[len][r - (1 << len) + 1]);
}
}st;
bool Check(int l, int r, int x) {
int res = 0;
if(x & 1) {
res = st.Query(2 * (l + x / 2) - 1, 2 * (r - x / 2) - 1);
}
else {
res = st.Query(2 * (l + x / 2 - 1), 2 * (r - x / 2));
}
return res >= x + 1;
}
int Solve(int ql, int qr) {
int l = 0, r = qr - ql + 1, mid, res = 0;
while(l <= r) {
mid = (l + r) >> 1;
if(Check(ql, qr, mid)) {
res = mid, l = mid + 1;
}
else {
r = mid - 1;
}
}
return res;
}
int main() {
string s;
cin >> s;
Manacher(s);
Init_lg(N - 5);
string t = "$";
int n = s.size(), i;
for(i = 0; i < n; i++) {
t.push_back(s[i]), t.push_back('$');
}
Manacher(t);
st.Init(2 * n - 1, f);
int q = Read();
while(q--) {
int l = Read(), r = Read();
Write(Solve(l, r)), putchar('\n');
}
return 0;
}
/*
aaacbdccccadaadabbdbadcbcbbadcadb
6
5 22
1 18
15 33
1 33
8 12
15 27
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 0ms
memory: 25440kb
input:
kmojliclywcyevunhgfnumdzvncnmzbkxjsrkzlyguvjwqmyamvwvidqvfcwnkoolupcrjhynrnlmncqwntqaqtnwqcnmlnrnyhjrcpulooknwcfvqdivwvmaymqwjvugylzkrsmlabbmjltopjasklgawfdbosdlmwahaygutogtvoenkxddmehwokwybkpireouiqqlsfbuqslxjlusnwkzgadxtagewjlchtcezugeguzecthcljwegatxdagzkwnsuljxlsqwlkpvoajknflirxpqcxmyhcgimr 293 ...
output:
101 75 83 63 3 2 101 3 3 3 39 3 1 41 3 23 2 1 63 45 1 63 31 1 101 83 3 41 13 63 63 3 2 2 3 1 1 1 1 3 2 63 23 15 15 101 2 31 63 71 101 49 37 2 101 101 3 71 1 63 3 31 85 1 2 63 101 2 3 3 63 3 63 65 63 3 101 63 41 3 3 3 73 7 1 25 63 37 29 17 1 3 3 2 3 101 1 101 1 3 3 63 1 1 31 77 101 89 31 41 101 15 59...
result:
ok 293 lines
Test #2:
score: 5
Accepted
time: 4ms
memory: 24476kb
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: 33120kb
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: 5
Accepted
time: 3ms
memory: 30520kb
input:
mfvckuykhckfuqmontrmfcfttxsqnaenocsvdxafpwkpftcwtqwgtsihvaquaudwebxmdijlcrenvivcwbwccmjyxmgmuhdkesgmkcbasghbbwlutayipathsvawcdkkmbdkdiurfsytgjasgsrebgtyjlclkycanipjqlpvxtusmetaxpkwvgilcqnspilinqanxofgxjwqzphraildqdewozyndxbekdknrvbdjgwwvulxfdaqpsziqmrtvlzcabcnouwilynyrbzktbfsfaepmyfjbwuuhvxihiyjicox...
output:
3 1193 698 128 857 3 698 903 5 1665 698 698 93 389 698 625 698 3 3 1665 4 3 1239 435 765 1665 76 537 1665 5 698 5 3 178 625 698 393 698 698 698 3 106 316 1033 651 625 713 1665 698 401 698 1305 1031 5 1097 3 1351 625 119 1393 698 3 625 5 194 698 698 698 321 625 3 421 698 3 698 698 747 1665 885 5 27 6...
result:
ok 4997 lines
Test #5:
score: 5
Accepted
time: 0ms
memory: 33020kb
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: 5
Accepted
time: 6ms
memory: 31524kb
input:
syucmgkigdlpevdxsshewqirqqcdljqjgaugkvzplmidhvwxeuhuzmzscczopnaviqlgnavpezpquyupilccvjsqfxjmpcsefwerqlgfitezkaffvdwlyhilzflbjecsikzvyecgpjkucqukkrauolgzffotznjxmbvcmsuzrwstehxgqzygfjfybzmyuoxvshelxlpzfxwalgxzlwvhsbaikzsgjkzvzjmlbhgubzcunksleqdgulmysfjashpwjymspmtoxiwaiimcbdqbbudlwbptrusyumtszzwbpmgg...
output:
495 495 3 7 741 741 1541 1541 495 741 1231 187 7 5 741 5 741 1221 741 551 495 1541 495 741 1541 1051 741 495 1229 741 495 1541 1081 689 1541 277 1259 4 385 4 495 4 495 741 4 805 7 1093 547 741 4 843 741 741 741 7 1403 7 5 451 7 7 495 741 741 371 4 7 399 741 741 281 495 495 3 1541 4 3 4 741 577 4 3 1...
result:
ok 4999 lines
Test #7:
score: 5
Accepted
time: 9ms
memory: 37180kb
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: 15ms
memory: 38380kb
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: 5
Accepted
time: 18ms
memory: 37252kb
input:
bydjourdrgeaxhanforissxtcbtoqpcslsmsuipplgpyitlspqplflboqptqnahqwzchrjhifexlgnmbsehwkwjzojfwvhmmuatwkozdvqwxcorhmhirdgzkztmzegneseslmxuuoifnakuwsycrcgkzpnspyvvfrcbutiknycrvsqgglsvritrrmilxhhrtclxzslysblwsimexxkodgizphdapogypdudlssdispudgxhnfidsyivbvgamsujzzelovuilauyzmstgpgqipmhnbqskffrjjfnzhotbnlzk...
output:
10655 5 9091 6 16665 7 9295 12693 6 6 16665 16665 6 5009 2038 751 12693 12693 2187 7341 6 16665 8431 12693 3687 7 12693 16665 7471 7 7 9287 12693 12693 4786 4786 12693 16665 4786 16665 3185 16665 10381 6 4786 12693 12279 2475 7 5 12693 3923 12693 6 4786 887 5425 5 6 16665 12693 11703 4681 4786 16665...
result:
ok 49998 lines
Test #10:
score: 5
Accepted
time: 12ms
memory: 37180kb
input:
hsfcfbhlqerzkkwsyslalaslnahwpqqhkflavreluedfhcprzyfaipqyzaupdypfannefsdhimxnxoxbaqfktuqcgkjhskocyzeyyvbimybpixxgygccyqjcysqsylrhqrblfqrvheoolimkvqejywdjeuzbhhqdafuybfkarmacprqkqadbrfsrehhthtginqqhwdukdzjfrtgyepxmrnpmrokehpzxtnbigekjlvwkeofqrayiodxshtdbiisdyrboacqktisjtdkfuzmuzrmhgdqewukdcufjrqtskxjk...
output:
10616 8341 978 13844 6130 152 978 978 7182 7 9920 8061 5 152 12438 7 11894 5 978 152 5510 6384 5 7171 16664 5 1356 978 5 16664 13082 978 7867 6078 5 5 5 16664 152 11516 5 11356 16664 7 5 14120 13922 2550 2263 5 3863 978 8341 14292 7 1145 4 5 6340 8341 4 5 13622 5 16664 8341 152 16664 3186 978 5 5 11...
result:
ok 49990 lines
Test #11:
score: 5
Accepted
time: 17ms
memory: 38044kb
input:
uqgylihdxuhtoedyzgzsnwjfaxxdrbadecbkxhbwvzztggrcvorlbgdobvnlswamdnehzepqdqeajrhfwkavapzqvbivztnsqtqnjxjejpgokdyyfxrsuxblzpftwbdkxvrczcerpjadlkqxieyslegpwgwuvzixavdbbtzcvuvnyjpjqvzfzcdnypukljhlspedodczoamlqokdljxdwtonfavmwxemmwicpfbcxfriiqymwizfjghzskzsxyzpluyjwvwyjjzjdddhoflaizakyjzmjmucfxrowqmiiiqp...
output:
5370 6 6 3 10494 14090 3 5 9804 2462 5 17758 5 17758 17758 17758 6686 12530 17758 16620 5 5 13894 300 5 17758 17758 17758 12582 15746 6686 5 1634 17758 1262 12772 5 5 5 978 17758 4 5 17758 492 12486 17758 5 7246 5 5 17758 5 5 1786 5 5 5 2528 17758 5 2058 5724 388 5 840 17758 6686 5 5 5 17758 17758 1...
result:
ok 49990 lines
Test #12:
score: 5
Accepted
time: 12ms
memory: 39724kb
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: 18ms
memory: 38532kb
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: 5
Accepted
time: 17ms
memory: 37424kb
input:
uoqxubtwiuvrweemnisntsggdzuataqgegovblspuctnszgscxridxjlgibfbtdetqrhkfzzvbkbufeisycazjudefsyvgraenfjynszhdjtzidepogsvltustouvnviyrdsncubobnlkruzcsxsabwayfldakyslzfprixpbgpzlfneokxjtnmgtwipkddbmmeahowhndbnuymxryrkgolobkenugcpyfcelqpnpwwphnufpjcxwjyxlcsutfogqlepvyfcjohvhqivjefwtkwubjgtlsabqnpdpixgnrvw...
output:
5 5 1762 5 5271 1429 104 6190 3087 3087 6146 5 3087 3087 3087 4421 3087 1613 5 5 5 4 5 3087 3087 6266 5271 5271 3087 5271 3257 104 5 104 1365 5 3087 3087 5 3087 7 3087 4404 2088 16 3087 3087 3087 5 5271 6124 5 5 5271 3087 3087 3087 5271 5 4 5271 5 5271 3087 3087 4669 4 3087 1739 4 104 2088 3721 3087...
result:
ok 49999 lines
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: 0
Runtime Error
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaebhhrvkfkvewwgcwzupqagltrbvbpsmrzhqqrzpphdatdovtqcskottjjaijncilycjoqvhjbvaorrczwefumogmkipliwrjgjcmcksniyjpowbzpezlmkkiivhadolbahzjlelwurmdhfktndmcqndtbimufcsilykijsbmlqrxlfkimnzghkxgtqgznzgcgmrkygvzbdizbraghkncugpszudehqyuhkywdzdbitixbamapwgzbzknwypluul...
output:
result:
Test #19:
score: 0
Runtime Error
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalvgbspddxrtwkccxskalmiaahvuaaevjkzxskmumnesqsjfqlgkanmmdinkbiabnrmvocequrnicjqzdatwwdzpgyoumwymnsjnklvbjrswytpqejlgxcmoaqqvpihlghjrsyvcoxhvprkfusafjsdrgopnfufkoopyqetppxuciqcwjxldgtwcthdepfcxdvrrhxcxdmsjnukgpdgkknnwzwmtavzvynhsapujivwmjlsaybeuaftemhzpmuexavqmhvpfou...
output:
result:
Test #20:
score: 0
Runtime Error
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaairvzomrstpfklvpyiboqxtnqbjazhstswwhmrdgbzsstvkrtencmmeqjfclkztnlsrrghcfrfrivxfrrpnwehishsneqljlmqwkugitnkuotmncikpvxzvgxcvdppekdbomsvqupgpjdcowzqfoxcivupvucxstsjlrlylvlzmqcxtqdwztpxmzetubgxllckejlkwjytrvdwmimdencuffcdifrllsoihxnbhoyy...