QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227451 | #7400. Digital Root | Crysfly | WA | 2ms | 13732kb | C++17 | 3.2kb | 2023-10-27 16:06:59 | 2023-10-27 16:06:59 |
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 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];
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]);
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(T&1){
if(aa[j]-aa[i-1]==0) ++res0;
else if(__builtin_popcount(T)==2){
int x=0;
For(_,1,k-1) if(T>>_&1) x=_;
res1[x]++;
}
}else if(__builtin_popcount(T)==1){
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;
if(S&1){
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(!(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: 2ms
memory: 13732kb
input:
9 2 10 123456789 9 12 8 123456789
output:
24 45
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 9752kb
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 6
result:
ok 10 tokens
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 5672kb
input:
19 6 2 0010111001010011111 0 0 0 1 0 01 1 0 1 1 1 01
output:
190 190 190 179 190 190
result:
wrong answer 1st words differ - expected: '42', found: '190'