QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#383814 | #8223. 字符串游戏 | Crysfly | 10 | 615ms | 80020kb | C++17 | 2.8kb | 2024-04-09 17:48:32 | 2024-04-09 17:48:32 |
Judging History
answer
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 2000005
#define inf 0x3f3f3f3f
int n,m;
char s[maxn];
int len[maxn],fa[maxn],ch[maxn][26],sz[maxn];
int pos[maxn],edp[maxn],anc[maxn][21];
int tot=1,lst=1;
vi e[maxn];
void append(int c,int id)
{
int u=++tot,p=lst;
pos[id]=u,edp[u]=id;
sz[u]=1,len[u]=len[p]+1;
for(;p&&!ch[p][c];p=fa[p])ch[p][c]=u;
if(!p)fa[u]=1;
else{
int q=ch[p][c];
if(len[q]==len[p]+1)fa[u]=q;
else{
int nq=++tot;
len[nq]=len[p]+1; fa[nq]=fa[q]; edp[nq]=edp[q];
memcpy(ch[nq],ch[q],sizeof ch[q]);
for(;p&&ch[p][c]==q;p=fa[p])ch[p][c]=nq;
fa[u]=fa[q]=nq;
}
}lst=u;
}
int c[maxn],b[maxn];
void radixsort(){
memset(c,0,sizeof c);
For(i,2,tot)e[fa[i]].pb(i);
For(i,1,tot)++c[len[i]];
For(i,1,tot)c[i]+=c[i-1];
For(i,1,tot)b[c[len[i]]--]=i;
Rep(i,tot,2)sz[fa[b[i]]]+=sz[b[i]];
For(i,1,tot){
int u=b[i];
anc[u][0]=fa[u];
For(j,1,20)anc[u][j]=anc[anc[u][j-1]][j-1];
}
}
int jump(int u,int l){
Rep(i,20,0)if(anc[u][i]&&len[anc[u][i]]>=l)u=anc[u][i];
return u;
}
int dfn[maxn],idx,out[maxn];
void dfs(int u){
dfn[u]=++idx;
for(int v:e[u])dfs(v);
out[u]=idx;
}
struct bit{
vector<int>tr;
int n;
void init(int N){n=N,tr=vector<int>(N+1,0);}
void add(int x,int y){for(;x<=n;x+=x&-x)tr[x]+=y;}
int ask(int x){
int s=0;
for(;x;x^=x&-x)s+=tr[x];
return s;
}
void down(){For(i,1,n)tr[i]+=tr[i^(i&-i)];}
}tr;
int occ(int l,int r){
int u=jump(pos[r],r-l+1);
return tr.ask(out[u])-tr.ask(dfn[u]-1);
}
ll f[maxn];
int st[maxn],tp;
signed main()
{
scanf("%s",s+1),n=strlen(s+1);
reverse(s+1,s+n+1);
For(i,1,n) append(s[i]-'a',i);
radixsort(),dfs(1);
tr.init(tot);
For(i,1,n){
tr.add(dfn[pos[i]],1);
// For(j,1,i)cout<<occ(j,i)<<" "; cout<<"\n";
f[i]=1;
For(j,1,i-1) f[i]=max(f[i],occ(j+1,i)-f[j]);
// while(tp){
// int j=st[tp];
// f[i]=max(f[i],occ(j+1,i)-f[j]);
// if(f[i]<=f[j])--tp;
// else break;
// }
// st[++tp]=i;
}
cout<<f[n];
return 0;
}
/*
1 2 3
*/
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 358ms
memory: 76860kb
input:
abbabbbbabbaaaaabbbaabaaaaaabbbaabbabababaabababaababaaaaaabaaabaaabbbbababaaabbbabababbbabbbaabaaababbbaabaabbaaabbababaaaaabbbaabaaabbaabaabaaabaaabaababaabbbbbbbbabbbbbabbbaabababbaababbbbbabbbbaaabbaabaabaaabbabbaaabbaaababaabbbaabbbaaaabbababbabaababababaaaabbaaaabaabaaaababaaabababbbaaabababbb...
output:
1281
result:
ok single line: '1281'
Test #2:
score: 0
Accepted
time: 360ms
memory: 77904kb
input:
aaaabababbabbbbbabbbbbbbbbbbabbbbbabbbaaabbbbaababaabbbbbbbbbbbbbabaabbaaabaababaabaaabbabbbabbbabaabbaabaababbbbbbaaabbbbaaabaabbbabbbabbabaabbbbabbbaabaaaabbbbbabaaaabaabbabaaabbaabbabbaaabbabaaababbababababaabaaaabaabaabaaabaabbbabbbbbaababbabbbabbbbababaaabbabbaaaabbbaaabaabbbaaaaaababaababbbbba...
output:
1483
result:
ok single line: '1483'
Test #3:
score: 0
Accepted
time: 374ms
memory: 76856kb
input:
bbaaababbbabbbaabbbbbbababbbabbbbbbbbaabbbbbbbbbbaaabbbbbbbbbbbbbbbabbabbbabaababbbabbbbabbabbabbbbabbbbbbbbbaaababbaaabbbaabbabbbbbbbbbbbbbbbbbbbbabbbbbbababababbbbbbbbbabababaabbbbbbabbbbaabbababbaaababbbbabbbbabbbabbbbbabbbbbabbbbbbbbbbabbaabbbabababbbbaababbbababbbbabbabbaabbbbbbabbbbbababbbbaba...
output:
2310
result:
ok single line: '2310'
Test #4:
score: 0
Accepted
time: 375ms
memory: 76812kb
input:
abbbbbbbbababbbbbbbbbabbbbbbbbabbbabbbbbaaabbbbbabbbbababbbabbbbbbaabbabbbbbaabbbbabbabbbbbbbabbbbaaabbbbbbaabbbbbbbbbbbbbbbbbbbbbabbbabbbabbbbbbbabbbbbbbabbbabbbbbbbbabbbabbbbbbbbbbbbbbbbbaababbbbbbbbbbabbbbbbbbbbbbbababbbbbbbabbbbbbababbbabbbbbaabbbbbbbbbaabbabbbbaabbbabbbbbbbbbbbbbabbbbbbbbbbbbbb...
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 403ms
memory: 76800kb
input:
bbbabbbbbbbbbbbbbbbbbbbbabbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbabbbabbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbabbbbabbabbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbabbbbbbabbabbbbbbaabbbabbbbbbbbbbbbbbbbabbbbbabbbabbbbbbbabbbababbabbbbba...
output:
3680
result:
ok single line: '3680'
Test #6:
score: 0
Accepted
time: 454ms
memory: 76724kb
input:
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbb...
output:
2454
result:
ok single line: '2454'
Test #7:
score: 0
Accepted
time: 479ms
memory: 78028kb
input:
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
output:
2702
result:
ok single line: '2702'
Test #8:
score: 0
Accepted
time: 615ms
memory: 76840kb
input:
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
output:
2499
result:
ok single line: '2499'
Test #9:
score: 0
Accepted
time: 292ms
memory: 80020kb
input:
amahaaajakalaiacabararasafaxasagamajaqagaqaeauauayagasadazavaeagabaaajalajavalatauapacaearaeagafawaaapawadaiaaapalahanavazasayamaiafagabahaxanacaaagaoadasakayagawaiaharanamaraiaramazaoagajataoazasalavatafaoalacaqavanafatajawauayakaoaqawawayasatasazagafacayasasawaqayadasaiazaxamaaaragataxawazadalaxak...
output:
2475
result:
ok single line: '2475'
Test #10:
score: 0
Accepted
time: 311ms
memory: 76476kb
input:
afabagadaeaeacaeaeafagafagababaaagacabaaagadacafadabaaaaacadaaagafacagadaeacacacabadagadaaabafadafadadaeafaaagadafabaeaaafaeaeaaaeabaaabaaaeafagadaaaaacaeaaaaacabaeacadagafafacacabaeaaagagaeaaadagabadaaaaagafagaaabaaaaafacafacadaaagabaaafadagacaaafafadadadacadadaaacagabacaaabacaeadabacagaeagagafafag...
output:
2807
result:
ok single line: '2807'
Subtask #2:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
aaaaaaabbaaabbbbabbabbbababaabaaabaabbaaababaaaaaabbbbbaabbbabbbaabbabaababaababaabbbababbbabaaaaaaaaabaaaaabbbabbbbbabaaabaaaababbabbbbbbaabbbbbaababbbbababbbbbbbbbbbaaabbabbaababbaaaabbabaaabbaaabbbbaaababbbbbabbaababbaaababaaabbabaabbbbabbaaabbababbaabbaaaaaaaaaabababbbaaaababbabbbabbababbabbabbb...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #16:
score: 0
Time Limit Exceeded
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #17:
score: 0
Time Limit Exceeded
input:
bbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbabaabaaabbabbaaababaaabaaaabababbbbbbbaabbaaabbabbbbbabbbaaaaababbbaaabaabababbabbabababbabbabaaaaabaaaaaabbbabaabbbaaaabbabababaaababaabbbbbbbaaabbbabaabaaaabaabaababbaaaabababaabbbaaaababaaababbbbbbabbbbbbaabbabbaaa...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%