ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#210939 | #2067. 肉夹馍 | drdilyor | 60 | 88ms | 44288kb | C++11 | 2.2kb | 2024-08-08 11:59:03 | 2024-08-08 14:29:19 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
const int mod=998244353;
struct mint{
int x;mint(int o=0){x=o;}mint&operator+=(mint a){return(x+=a.x)%=mod,*this;}mint&operator-=(mint a){return(x+=mod-a.x)%=mod,*this;}
mint&operator*=(mint a){return(x=1ll*x*a.x%mod),*this;}mint&operator^=( int b){mint a=*this;x=1;while(b)(b&1)&&(*this*=a,1),a*=a,b>>=1;return*this;}
mint&operator/=(mint a){return*this*=(a^=mod-2);}friend mint operator+(mint a,mint b){return a+=b;}friend mint operator-(mint a,mint b){return a-=b;}
friend mint operator*(mint a,mint b){return a*=b;}friend mint operator/(mint a,mint b){return a/=b;}friend mint operator^(mint a,int b){return a^=b;}
mint operator-(){return 0-*this;}bool operator==(const mint b)const{return x==b.x;}
};
char s[2000005];
int rt[2000005];
int n;
int nxt[2000005];
void write(int x){
if(x<10){putchar(x+'0');return;}
write(x/10);
putchar(x%10+'0');
}
struct node{
int ls,rs;
int mx;
}seg[2000005*30];
int tot;
void upd(int &x,int y,int l,int r,int p){
x=++tot;
seg[x]=seg[y];
if(l==r){seg[x].mx=p;return;}
int mid=(l+r)/2;
if(p<=mid)upd(seg[x].ls,seg[y].ls,l,mid,p);
else upd(seg[x].rs,seg[y].rs,mid+1,r,p);
if(seg[seg[x].rs].mx)seg[x].mx=seg[seg[x].rs].mx;
else seg[x].mx=seg[seg[x].ls].mx;
}
int query(int x,int l,int r,int ql,int qr){
if(l==ql&&r==qr)return seg[x].mx;
int mid=(l+r)/2;
if(qr<=mid)return query(seg[x].ls,l,mid,ql,qr);
else if(ql>mid)return query(seg[x].rs,mid+1,r,ql,qr);
int v=query(seg[x].rs,mid+1,r,mid+1,qr);
if(v)return v;
return query(seg[x].ls,l,mid,ql,mid);
}
signed main(){
scanf("%s",s+1);
n=strlen(s+1);
for(int i=2;i<=n;i++){
int b=nxt[i-1];
while(s[i]!=s[b+1]){
if(b==nxt[b])break;
b=nxt[b];
}
if(s[i]!=s[b+1]){nxt[i]=0;continue;}
nxt[i]=b+1;
}
for(int i=1;i<=n;i++){
upd(rt[i],rt[nxt[i]],0,n,nxt[i]);
write(query(rt[i],0,n,0,(i-1)/2));
putchar(' ');
//最大的 <=(i-1)/2
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 1184kb
input:
qpbvqpbvqpbvavdqpbvqpbvqpbvavdqpbvqpbvqpbvavdfnfninqpbvqpbvqpbvavdqpbvqpbvqpbvavdqpbvqpbvqpbvavd
output:
0 0 0 0 1 2 3 0 1 2 3 4 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
result:
ok 96 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 1176kb
input:
wfalgbgweavpwhfahfewhavweahuwbvbqvuivhuiaehufuaeuvdafuivjafislfhbibcuuiabcuibsv
output:
0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 79 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 1180kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...
result:
ok 100 tokens
Subtask #2:
score: 20
Accepted
Test #4:
score: 20
Accepted
time: 1ms
memory: 2104kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...
result:
ok 3000 tokens
Test #5:
score: 0
Accepted
time: 0ms
memory: 2100kb
input:
cjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcj...
output:
0 0 1 0 1 2 3 2 3 4 5 4 5 6 7 6 7 8 9 8 9 10 11 10 11 12 13 12 13 14 15 14 15 16 17 16 17 18 19 18 1...
result:
ok 3000 tokens
Test #6:
score: 0
Accepted
time: 0ms
memory: 2048kb
input:
ckcckckcckcckckcckcckckcckcckckcsdvhckcckckcckcckckcckcckckcckcckckcsdvhckcckckcckcckckcckcckckcckcc...
output:
0 0 1 1 2 1 2 3 4 2 3 4 5 6 7 3 4 5 6 4 5 6 7 8 9 10 11 12 13 14 15 8 0 0 0 0 1 2 3 4 5 6 7 8 9 10 1...
result:
ok 2828 tokens
Subtask #3:
score: 30
Accepted
Test #7:
score: 30
Accepted
time: 29ms
memory: 44288kb
input:
aocnsaosashoicfaaocnsaosashoicfaqowfwpqgvqvhoabcdoawaocnsaosashoicfaaocnsaosashoicfaqowfwpqgvqvhoabc...
output:
0 0 0 0 0 1 2 0 1 0 0 0 0 0 0 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 ...
result:
ok 100000 tokens
Test #8:
score: 0
Accepted
time: 34ms
memory: 44280kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...
result:
ok 100000 tokens
Test #9:
score: 0
Accepted
time: 24ms
memory: 44280kb
input:
vivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivi...
output:
0 0 1 0 1 2 3 2 3 4 5 4 5 6 7 6 7 8 9 8 9 10 11 10 11 12 13 12 13 14 15 14 15 16 17 16 17 18 19 18 1...
result:
ok 100000 tokens
Subtask #4:
score: 0
Memory Limit Exceeded
Test #10:
score: 0
Memory Limit Exceeded
input:
aoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhd...
output:
0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...