QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#430558 | #7008. Rikka with Nice Counting Striking Back | AFewSuns | AC ✓ | 5704ms | 118128kb | C++20 | 5.3kb | 2024-06-03 22:55:53 | 2024-06-03 22:55:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
#define bs1 29
#define bs2 31
#define mod1 998244853
#define mod2 1000000007
ll t,n,hsh1[200020],hsh2[200020],pw1[200020],pw2[200020],f[200020];
ll st[200020],top=0,cnt=0,ans=0;
char s[200020];
struct node{
ll l,r,p;
}a[400040];
struct HASH{
#define mod 1000003
ll head[1000010],nxt[400040],cnt=0;
pair<ll,ll> to[400040];
il void clr(){
fr(i,1,cnt){
ll X=to[i].fir*to[i].sec%mod;
head[X]=0;
}
cnt=0;
}
il void ins(pair<ll,ll> x){
ll X=x.fir*x.sec%mod;
nxt[++cnt]=head[X];
to[cnt]=x;
head[X]=cnt;
}
il bl find(pair<ll,ll> x){
ll X=x.fir*x.sec%mod;
for(ll i=head[X];i;i=nxt[i]) if(to[i]==x) return 1;
return 0;
}
}H;
struct SA{
ll m,cnt[200020],x[200020],y[200020],sa[200020],rk[200020],h[200020];
ll lg[200020],minn[200020][18];
il void build(){
m=26;
fr(i,1,m) cnt[i]=0;
fr(i,1,n) x[i]=s[i]-'a'+1;
fr(i,1,n) cnt[x[i]]++;
fr(i,1,m) cnt[i]+=cnt[i-1];
pfr(i,n,1) sa[cnt[x[i]]--]=i;
for(ll k=1;k<=n;k<<=1){
fr(i,1,m) cnt[i]=0;
ll tmp=0;
fr(i,n-k+1,n) y[++tmp]=i;
fr(i,1,n) if(sa[i]>k) y[++tmp]=sa[i]-k;
fr(i,1,n) cnt[x[i]]++;
fr(i,1,m) cnt[i]+=cnt[i-1];
pfr(i,n,1) sa[cnt[x[y[i]]]--]=y[i];
swap(x,y);
x[sa[1]]=m=1;
fr(i,2,n){
if((sa[i]+k)<=n&&(sa[i-1]+k)<=n&&y[sa[i]]==y[sa[i-1]]&&y[sa[i]+k]==y[sa[i-1]+k]) x[sa[i]]=m;
else x[sa[i]]=++m;
}
}
fr(i,1,n) rk[sa[i]]=i;
fr(i,1,n){
if(rk[i]==1) continue;
ll tmp=max(0ll,h[rk[i-1]]-1);
while((i+tmp)<=n&&(sa[rk[i]-1]+tmp)<=n&&s[i+tmp]==s[sa[rk[i]-1]+tmp]) tmp++;
h[rk[i]]=tmp;
}
fr(i,2,n) lg[i]=lg[i>>1]+1;
fr(i,2,n) minn[i][0]=h[i];
fr(j,1,lg[n]) fr(i,2,n-(1ll<<j)+1) minn[i][j]=min(minn[i][j-1],minn[i+(1ll<<(j-1))][j-1]);
}
il ll query(ll l,ll r){
if(l==r) return n-l+1;
l=rk[l];
r=rk[r];
if(l>r) swap(l,r);
l++;
ll tmp=lg[r-l+1];
return min(minn[l][tmp],minn[r-(1ll<<tmp)+1][tmp]);
}
}S1,S2;
il bl operator<(const node &x,const node &y){
if(x.l!=y.l) return x.l<y.l;
return x.r<y.r;
}
il pair<ll,ll> get_hash(ll l,ll r){
return MP((hsh1[r]-hsh1[l-1]*pw1[r-l+1]%mod1+mod1)%mod1,(hsh2[r]-hsh2[l-1]*pw2[r-l+1]%mod2+mod2)%mod2);
}
il ll get_lcp(ll x,ll y){
return S1.query(x,y);
}
il ll get_lcs(ll x,ll y){
return S2.query(n-x+1,n-y+1);
}
il void clr(){
H.clr();
top=cnt=ans=0;
}
int main(){
// freopen("1.in","r",stdin);
// freopen("wa.out","w",stdout);
t=read();
fr(_,1,t){
scanf("%s",s+1);
n=strlen(s+1);
S1.build();
reverse(s+1,s+n+1);
S2.build();
reverse(s+1,s+n+1);
fr(i,1,n) ans+=i;
fr(i,2,n) ans-=S1.h[i];
pw1[0]=pw2[0]=1;
fr(i,1,n) pw1[i]=pw1[i-1]*bs1%mod1;
fr(i,1,n) pw2[i]=pw2[i-1]*bs2%mod2;
fr(i,1,n) hsh1[i]=(hsh1[i-1]*bs1+s[i]-'a'+1)%mod1;
fr(i,1,n) hsh2[i]=(hsh2[i-1]*bs2+s[i]-'a'+1)%mod2;
st[0]=n+1;
pfr(i,n,1){
while(top){
ll tmp=get_lcp(i,st[top]);
if(tmp<(n-st[top]+1)&&s[i+tmp]<s[st[top]+tmp]) top--;
else break;
}
f[i]=st[top]-1;
st[++top]=i;
}
fr(i,1,n){
ll l=i,r=f[i];
if(l>1) l-=get_lcs(i-1,f[i]);
if(r<n) r+=get_lcp(i,f[i]+1);
if((r-l+1)>=2*(f[i]-i+1)) a[++cnt]=(node){l,r,f[i]-i+1};
}
top=0;
pfr(i,n,1){
while(top){
ll tmp=get_lcp(i,st[top]);
if(tmp<(n-st[top]+1)&&s[i+tmp]>s[st[top]+tmp]) top--;
else break;
}
f[i]=st[top]-1;
st[++top]=i;
}
fr(i,1,n){
ll l=i,r=f[i];
if(l>1) l-=get_lcs(i-1,f[i]);
if(r<n) r+=get_lcp(i,f[i]+1);
if((r-l+1)>=2*(f[i]-i+1)) a[++cnt]=(node){l,r,f[i]-i+1};
}
sort(a+1,a+cnt+1);
ll cntt=0;
fr(i,1,cnt) if(!cntt||a[cntt]<a[i]) a[++cntt]=a[i];
cnt=cntt;
fr(i,1,cnt){
fr(j,a[i].l+a[i].p-1,a[i].r-a[i].p){
ll k=(j-a[i].l+1)/a[i].p;
pair<ll,ll> tmp=get_hash(j-a[i].p*k+1,j);
if(!H.find(tmp)){
ans--;
H.ins(tmp);
}
}
}
writeln(ans);
clr();
}
}
/*
6
rikkasuggeststoallthecontestants
thisisaproblemdesignedforgrandmasters
ifyoudidnotachievethat
youdbetterskiptheproblem
wishyouahighrank
enjoytheexperience
*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 40760kb
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: 5704ms
memory: 118128kb
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: 5168ms
memory: 115932kb
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: 5194ms
memory: 115884kb
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: 4431ms
memory: 115876kb
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