QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455298#7008. Rikka with Nice Counting Striking BackKalenistAC ✓7663ms143580kbC++142.4kb2024-06-26 08:23:242024-06-26 08:23:26

Judging History

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

  • [2024-06-26 08:23:26]
  • 评测
  • 测评结果:AC
  • 用时:7663ms
  • 内存:143580kb
  • [2024-06-26 08:23:24]
  • 提交

answer

#include<bits/stdc++.h>
#define N 1000010
#pragma GCC optimize("Ofast")
#define For(i,a,b) for(register int i=a;i<=b;i++)
using namespace std;
int n,lnk[N],len[N],lst=1,a[N],occ[N],dfn[N];
int nxt[N][26],tot=1,en[N],sz[N],son[N],cnt1,cnt2;
long long ans;
char s[N];
vector<int> go[N];
set<int> pos,val;
inline void insert(int v,int pos)
{
    int nw=++tot,nd=lst;
    len[nw]=len[nd]+1,lst=nw,en[nw]=pos;
    while(nd && !nxt[nd][v]) nxt[nd][v]=nw,nd=lnk[nd];
    if(!nd) {lnk[nw]=1;return;}
    int q=nxt[nd][v];
    if(len[q] == len[nd]+1) {lnk[nw]=q;return;}
    int clone=++tot;
    len[clone]=len[nd]+1,lnk[clone]=lnk[q];
    memcpy(nxt[clone],nxt[q],sizeof(nxt[q]));
    while(nd && nxt[nd][v] == q) nxt[nd][v]=clone,nd=lnk[nd];
    return void(lnk[nw]=lnk[q]=clone);
}

inline void prework(int x)
{
    a[dfn[x]=++a[0]]=x,sz[x]=1;
    for(int to:go[x])
    {
        prework(to),sz[x]+=sz[to];
        if(sz[to] > sz[son[x]]) son[x]=to;
    }
    return;
}

inline void add(int x)
{
    auto it=pos.upper_bound(x);
    int l=0,r=it==pos.end()?0:*it;
    if(it != pos.begin()) l=*(--it);
    if(l && r) {occ[r-l]--;if(!occ[r-l]) val.erase(r-l);}
    if(l) {if(!occ[x-l]) val.insert(x-l);occ[x-l]++;}
    if(r) {if(!occ[r-x]) val.insert(r-x);occ[r-x]++;}
    pos.insert(x);
    return;
}

inline void solve(int x,bool flag)
{
    for(int to:go[x]) if(to^son[x])
        solve(to,false);
    if(son[x]) solve(son[x],true);
    if(en[x]) add(en[x]);
    for(int to:go[x]) if(to^son[x])
    {
        int l=dfn[to],r=dfn[to]+sz[to]-1;
        For(i,l,r) if(en[a[i]]) add(en[a[i]]);
    }for(int v:val) if(v) ans-=len[x]/v-len[lnk[x]]/v;
    if(!flag) 
    {
        auto it=pos.begin();
        while(it!=pos.end())
            {int l=*(it++);occ[(*it)-l]--;}
        pos.clear(),val.clear();
    }
    return;
}

int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
		scanf("%s",s+1),n=strlen(s+1);
        //scanf("%d%s",&n,s+1);
        lst=tot=1,ans=a[0]=0;
        For(i,1,n) insert(s[i]-'a',i);
        For(i,1,tot) ans+=len[i]-len[lnk[i]];
        For(i,2,tot) go[lnk[i]].push_back(i);
        prework(1),solve(1,false);
        printf("%lld\n",ans);
        For(i,1,n) occ[i]=0;
        For(i,1,tot)
        {
            go[i].clear(),dfn[i]=a[i]=0;
            son[i]=sz[i]=en[i]=lnk[i]=len[i]=0;
            memset(nxt[i],0,sizeof(nxt[i]));
        }
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 38600kb

input:

6
rikkasuggeststoallthecontestants
thisisaproblemdesignedforgrandmasters
ifyoudidnotachievethat
youdbetterskiptheproblem
wishyouahighrank
enjoytheexperience

output:

500
679
244
290
132
163

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 7179ms
memory: 143580kb

input:

1000
mxsslrrxtwwnwlsrxxxbsmtxxwwntsbrwlxnbxunutnlmrrlubturuwmbnobrolwunwurtbnmlumxmwtwrsulruxslsnltsstmmxbsmuonroubrnnmu
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
glggglgg
yykkyyyykykykyyyykyykykkkyyyykkyykkkyyykykyykyyykkykky...

output:

6522
1
20
9443
11294
1
8619
26
7898
260905
9048
6
22114
52
20
45
7
39
10
1
28
26
10
47
32
12977
30
13
7473
12
8402
1
8083
16
1
10462
16
9278
1
1
8968
7858
11148
8130
6
8516
12223
9266
8374
26
45
14
10150
9
10175
298758
203677
11522
12
8985
10687
12
1
6613277686
10
10
1
5794
28
1
280529
7874
13
10564...

result:

ok 1000 lines

Test #3:

score: 0
Accepted
time: 7146ms
memory: 102812kb

input:

26
hihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihh...

output:

9523687993
9529757593
9537405289
9539347561
9533035177
9528058105
564250
9522959641
9542382361
9518953705
9519439273
9534977449
9519803449
9535705801
9519560665
9534249097
9527572537
9523687993
9539468953
9532064041
9525873049
9532185433
9541168441
9524901913
9531092905
9518832313

result:

ok 26 lines

Test #4:

score: 0
Accepted
time: 7157ms
memory: 100112kb

input:

26
oohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohoohooohoohoohooohoohooohoohoohooohoohooohooh...

output:

9625902365
9628810517
9622671085
9626467839
9628891299
9626306275
9630668503
9620409189
9618228075
9622428739
9628406607
9625336891
9630426157
9626871749
9620086061
9626144711
9616935563
9617177909
9626790967
9627194877
9626467839
354971
9616370089
9618308857
9617824165
9616773999

result:

ok 26 lines

Test #5:

score: 0
Accepted
time: 7663ms
memory: 103580kb

input:

26
vggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvvggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvvggvgvggvgvvgvggvgvggvgvvggvgvggvgvvgvggvgvggvgvvgvggvgvvggvgvggvgvvgvggvgvggvg...

output:

13085098340
13073668733
13071665606
13067070197
13077910649
13074964874
13078735466
13070840789
13072726085
13067895014
669720
13065891887
13065302732
13076496677
13068484169
13064242253
13065420563
13063181774
13080502931
13067070197
13072490423
13070015972
13083802199
13064831408
13075671860
13085...

result:

ok 26 lines