QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#227460#7400. Digital RootCrysflyWA 1ms13864kbC++173.2kb2023-10-27 16:14:092023-10-27 16:14:09

Judging History

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

  • [2023-10-27 16:14:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:13864kb
  • [2023-10-27 16:14:09]
  • 提交

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 ull unsigned long long
#define int long long
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 200005
#define inf 0x3f3f3f3f

int toint(char c){
	if(isdigit(c))return c&15;
	return c-'a'+10;
}

int n,m,k;
char s[maxn];
int a[maxn],aa[maxn],sum[maxn][17];

int pre[17],id[17];
pii tmp[17];

int ask(int x,int l,int r){
	int res=sum[r][x];
	if(l>0)res-=sum[l-1][x];
	return res;
}

int f[17][1<<17];
void fwt(int*f,int k){
	For(i,0,k-1)
		For(j,0,(1<<k)-1)
			if(j>>i&1) f[j]+=f[j^(1<<i)];
}

int res0,res1[19],res10[19];

signed main()
{
	n=read(),m=read(),k=read(),cin>>(s+1);
	sum[0][0]=1;
	For(i,1,n){
		a[i]=a[i-1]+toint(s[i]),a[i]%=(k-1);
		aa[i]=aa[i-1]+(toint(s[i])!=0);
		res10[toint(s[i])]++;
		For(j,0,k-2)sum[i][j]=sum[i-1][j]+(j==a[i]);
	}
	memset(pre,-1,sizeof pre);
	For(j,0,k) id[j]=j;
//	For(i,1,n){
//		pre[toint(s[i])%(k-1)]=i;
//		sort(id,id+k-1,[&](int x,int y){
//			return pre[x]>pre[y];
//		});
//		int S=0;
//		For(j,0,k-2){
//			int r=pre[id[j]];
//			int l=pre[id[j+1]]+1;
//			l=max(l,1ll);
//			S|=(1<<id[j]);
//			if(l>r)continue;
//		//	cout<<"i,l,r, "<<i<<" "<<l<<" "<<r<<" "<<S<<"\n";
//			For(x,0,k-2)
//				f[(a[i]-x+k-1)%(k-1)][S]+=ask(x,l-1,r-1);
//		}
//	}
	
	For(i,1,n)For(j,i,n){
		int S=0,T=0;
		For(p,i,j)S|=(1<<(toint(s[p])%(k-1))),T|=(1<<toint(s[p]));
	//	cout<<(a[j]-a[i-1]+k-1)%(k-1)<<" "<<S<<"\n";
		f[(a[j]-a[i-1]+k-1)%(k-1)][S]+=1;
		
		if(aa[j]-aa[i-1]<=1){
			if(aa[j]-aa[i-1]==0) ++res0;
			else {
				int x=0;
				For(_,1,k-1) if(T>>_&1) x=_;
				res1[x]++;
			}
		}
	}
	
	For(x,0,k-2) fwt(f[x],k-1);
	For(_,1,m){
		int y=read();
		string str; cin>>str;
		int S=0;
		for(auto c:str){
			int o=toint(c);
			S|=(1<<(o%(k-1)));
		}
		int res=n*(n+1)/2;
		For(x,0,k-2)if(x!=y%(k-1)){
			// if have j,x-i+j==y
			// j==y+i-x
			int T=0;
			For(i,0,k-2){
		//		cout<<(((y+i-x+k-1)%(k-1)))<<"\n";
				if(!(S>>((y+i-x+k-1)%(k-1))&1)) T|=(1<<i);
			}
		//	cout<<"x,T "<<x<<' '<<T<<" "<<f[x][T]<<"\n";
			res-=f[x][T];
		}
		if(y==0||y==k-1){
			if(y==0){
				res=res0;
				bool fl0=0;
				for(auto c:str) if(toint(c)==0) fl0=1;
				if(fl0){
					For(j,1,k-1) res+=res1[j];
				}
			}else{
			//	cout<<"ans "<<res<<"\n";
				bool fl=0,fl0=0;
				for(auto c:str){
					if(toint(c)==k-1)fl=1;
					if(toint(c)==0)fl0=1;
				}
				if(!fl){
					res-=res0;
				//	cout<<"QWQ "<<res<<"\n";
					For(j,1,k-2) {
						if(fl0) res-=res10[j];
						if(!(S>>(k-1-j)&1)){
							if(fl0) res-=res1[j];
						}
					}
				}
			}
		}
		cout<<res<<"\n";
	}
    return 0;
}
/*
5 10 5
01234
0 1

01234

*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 13864kb

input:

9 2 10
123456789
9 12
8 123456789

output:

24
45

result:

ok 2 tokens

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7856kb

input:

5 10 5
01234
0 1
1 1
2 1
3 1
4 1
0 1
1 0
2 0
3 0
4 0

output:

1
13
9
9
9
1
10
9
10
3

result:

wrong answer 10th words differ - expected: '6', found: '3'