QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#461966#5037. 回文grass8cow#0 90ms47196kbC++172.1kb2024-07-03 11:21:342024-07-03 11:21:34

Judging History

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

  • [2024-07-03 11:21:34]
  • 评测
  • 测评结果:0
  • 用时:90ms
  • 内存:47196kb
  • [2024-07-03 11:21:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,q;
char c[201000],b[401000],a[400100];
int kmp[401000];
int bru(int m){
    for(int i=1;i<=m;i++)a[m-i+1]=a[i+m]=b[i];
    for(int i=2,j=0;i<=m*2;i++){
        while(j&&a[j+1]!=a[i])j=kmp[j];
        if(a[j+1]==a[i])j++;kmp[i]=j;
    }
    int u=m*2,s=0;while(u)s+=(u<=m),u=kmp[u];
    return s;
}
int OP[200100];
int L[200100],R[200100],X[200100];
char E[201000];
int ch[201000][26],fail[201000],len[201000],id[201000],f[201000][20],d[200100];
int gf(int p,int r){while(r-len[p]-1<=0||c[r-len[p]-1]!=c[r])p=fail[p];return p;}
int main(){
    scanf("%s",c+1);n=strlen(c+1);
    scanf("%d",&q);
    /*if(n<=5000&&q<=5000){
        int lans=0;
        for(int i=1,op,x,l,r;i<=q;i++){
            char e[2];
            scanf("%d",&op);
            if(op==1){scanf("%d%s",&x,e),x^=lans;c[x]=e[0];}
            else{
                scanf("%d%d",&l,&r);
                l^=lans,r^=lans;
                for(int j=l;j<=r;j++)b[j-l+1]=c[j];
                printf("%d\n",lans=bru(r-l+1));
            }
        }
        return 0;
    }*/
    bool fla=0;
    for(int i=1;i<=q;i++){
        scanf("%d",&OP[i]);
        if(OP[i]==1){fla=1;char o[2];scanf("%d%s",&X[i],o),E[i]=o[0];}
        else scanf("%d%d",&L[i],&R[i]);
    }
    if(!fla){
        int cn=1,p=1;
        len[1]=-1,fail[0]=1;
        for(int i=1;i<=n;i++){
            p=gf(p,i);int z=c[i]-'a';
            if(!ch[p][z]){
                fail[++cn]=ch[gf(fail[p],i)][z],ch[p][z]=cn;
                d[cn]=d[fail[cn]]+1;
                len[cn]=len[p]+2;
            }
            p=ch[p][z];
            id[i]=p;
        }
        for(int i=2;i<=cn;i++){
            f[i][0]=max(1,fail[i]);
            for(int j=1;j<20;j++)f[i][j]=f[f[i][j-1]][j-1];
        }
        int lans=0;
        for(int i=1,l,r;i<=q;i++){
            l=L[i],r=R[i],l^=lans,r^=lans;
            int u=id[r];
            if(len[u]>r-l+1){
                for(int j=19;j>=0;j--)if(f[u][j]&&len[f[u][j]]>r-l+1)u=f[u][j];
                u=f[u][0];
            }
            printf("%d\n",d[u]);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7920kb

input:

aabbbabbbaaaaaaabbabbbaaaabaaaabbaabbaabbaaababbbabbbbabbbbaaaabbbabbbbbaaabbbabbaaaaabbbbbaaababbabbaaaaabaabbbbaaababaaabbaabbabbbabbbbaaaaabbbbbbbabbbaabbbabbabbbababbabbbbaaaaabbaababbbbaabbaaaaaabaaabbbaaababbbbaabaaaaababababbbbbbaaaabbbbaaababaaabbaabbbbbaaaabbaaaabaaaaaababbababaaaabaaababaa...

output:


result:

wrong answer Unexpected EOF in the participants output

Subtask #2:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 90ms
memory: 47196kb

input:

aabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabbababaabbbaaabbaabbbbaabbaaabbbaabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabbababaabbaaabaaaaaabaaabbaabababbabbbbbbabbababaaaabababbabbbbbbabbababaaaabababbabbbbbbabb...

output:

41
45
153
119
60
167
50
166
118
204
148
143
29
70
118
123
159
10
105
307
101
74
37
362
78
182
55
34
84
263
72
112
79
192
152
153
155
50
130
137
142
26
308
9
12
258
257
137
356
49
115
332
17
126
19
35
117
157
40
93
285
90
351
168
61
150
46
181
102
283
166
24
84
177
32
123
64
125
282
22
81
213
120
144...

result:

wrong answer 2nd words differ - expected: '43', found: '45'

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 20ms
memory: 9904kb

input:

abbaaaabbabaaaaaabaabbaabbababbaaabbabbbabaabaabaaaaabaabbbbabbabbabbbababbbababababbbbabaabbaaababbbbbababbbbaabbbaaabaababababaabbbbbbaababaabbaaabaabbaaababbabbabbbbaaaaabaaabbbabbbbbbabbbabbabaabbbbbbbaaaabbaaaababbbaaaaaaababaabbbbaaabaaabbaabbbbbbababbaabbaaabbabbbbbabaababbaabaaaabbbbabababba...

output:


result:

wrong answer Unexpected EOF in the participants output

Subtask #4:

score: 0
Wrong Answer

Test #27:

score: 0
Wrong Answer
time: 27ms
memory: 10156kb

input:

babbaaabbbbbbbabbbababaabbbbbababababbaabaabbbbbbabbbbbbbbbbababbbbabbaabbbaabaabbabbbaabbabbbabbababaababbbabbbbaabbabbabbaaaabbbaaabbbbaabbaaaaaaabbbabbbaaabaababaaabaaaabaaaababaaaaababaaaabaabbaaaabbbabbaabaabbbabbbbbaaabaababbbaaaaabbbbaaabbbbaabbabbbbabbbabbaaaaabaabaaaabbbabbbbbaabbbbabbbbaab...

output:


result:

wrong answer Unexpected EOF in the participants output

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%