QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#430557#7008. Rikka with Nice Counting Striking BackAFewSunsWA 7223ms110356kbC++205.3kb2024-06-03 22:54:442024-06-03 22:54:45

Judging History

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

  • [2024-06-03 22:54:45]
  • 评测
  • 测评结果:WA
  • 用时:7223ms
  • 内存:110356kb
  • [2024-06-03 22:54:44]
  • 提交

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 10007
	ll head[10007],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;
		if(t==26){
			clr();
			writeln(cnt);
			continue;
		}
		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
*/ 

详细

Test #1:

score: 100
Accepted
time: 16ms
memory: 38596kb

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: 7223ms
memory: 110356kb

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: -100
Wrong Answer
time: 4624ms
memory: 108076kb

input:

26
hihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihhihhihihhihihhihhihihhihihhihhihihh...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

wrong answer 1st lines differ - expected: '9523687993', found: '0'