QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22852#2135. How Many Strings Are Lessha114514ha#WA 2ms24148kbC++204.1kb2022-03-10 18:26:302022-04-30 01:48:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 01:48:02]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:24148kb
  • [2022-03-10 18:26:30]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#include<ctime>
#include<random>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define bc(x) __builtin_popcount(x)
#define re register
#define il inline
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mem0(x) memset(x,0,sizeof(x))
#define mem0x3f(x) memset(x,0x3f,sizeof(x))
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n';
// #pragma GCC optimize(3)
//#define int long long
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
namespace IO_BUFF{
	mt19937 rnd(time(0)^(ll)(new char));
	int rend(int x){
		return rnd()%x+1;
	}
	void rendom_shuffle(int *a,int len){
		shuffle(a+1,a+len+1,rnd);
	}
	const int BS=(1<<24)+5;char Buffer[BS],*HD,*TL;
	inline int gc(){
	    if(HD==TL) TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);
	    return (HD==TL)?EOF:*HD++;
	}
	inline int inn(){
	    int x,ch,s=1;while((ch=gc())<'0'||ch>'9')if(ch=='-')s=-1;x=ch^'0';
	    while((ch=gc())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^'0');return x*s;
	}
	char ssss[19999999],tttt[20];int ssl,ttl;
    inline int print(int x)
    {
        if(x<0)ssss[++ssl]='-',x=(-x);
		if(!x) ssss[++ssl]='0';for(ttl=0;x;x/=10) tttt[++ttl]=char(x%10+'0');
        for(;ttl;ttl--) ssss[++ssl]=tttt[ttl];return ssss[++ssl]='\n';
    }
	inline int Flush(){return fwrite(ssss+1,sizeof(char),ssl,stdout),ssl=0,0;}
	int read(){
		char c=getchar();int x=1;int s=0;
		while(c<'0' || c>'9'){if(c=='-')x=-1;c=getchar();}
		while(c>='0' && c<='9'){
			s=s*10+c-'0';c=getchar();
		}
		return s*x;
	}
}using namespace IO_BUFF;
/*namespace CFConTest{
	const int mod=998244353;
	inline int add(const int &x,const int &y){
		return (x+y>=mod?x+y-mod:x+y);
	}
	inline int del(const int &x,const int &y){
		return (x-y<0?x-y+mod:x-y);
	}
	int ksm(int x,int k){
		int base=1;
		while(k){
			if(k&1)base=1ll*base*x%mod;
			k>>=1;
			x=1ll*x*x%mod;
		}
		return base;
	}
};
using namespace CFConTest;*/
const int N=1e6+5;
int n,m,x,len;
char a[N],b[N],c[5];
int rt,tot,ch[N][26],siz[N];
int f[N][21],deep[N],g[N][26],h[N][26],ans[N],ed[N];
void add(int &u,int deep,int len){
	if(!u)u=++tot;siz[u]++;
	if(deep==len){
		ed[u]++;return ;
	}
	add(ch[u][b[deep+1]-'a'],deep+1,len);
}
void dfs(int u,int fa){
	f[u][0]=fa;
	for(int i=1;i<=20;i++)f[u][i]=f[f[u][i-1]][i-1];
	int cnt=0,pre=0;
	if(deep[u]<n)ans[u]+=ed[u];
	if(u==17){
		new char;
	}
	for(int i=0;i<26;i++){
		if(ch[u][i]){
			deep[ch[u][i]]=deep[u]+1;
			ans[ch[u][i]]=ans[u]+pre;
			dfs(ch[u][i],u);
			g[u][i]=g[ch[u][i]][i];
			cnt++;
		}
		else g[u][i]=u;
		h[u][i]=pre;
		pre=pre+siz[ch[u][i]];
	}
	if(!cnt || deep[u]==len){
		for(int i=0;i<26;i++)g[u][i]=u;
	}
	
}
int tiao(int x,int k){
	for(int i=20;i>=0;i--){
		if(k&(1<<i)){
			x=f[x][i];
		}
	}
	return x;
}
int sx[N],sy[N],top;
int las;
int solve(int u){
	if(deep[u]==n)return ans[u];
	if(las!=0)return ans[u]+h[u][las-1];
	return ans[u];
}
int main(){
	#ifdef newbiewzs
		double startt=clock();
		freopen("data.in","r",stdin);
	#else
	#endif
	n=read();m=read();
	scanf("%s",a+1);
	len=strlen(a+1);
	for(int i=1;i<=n;i++){
		scanf("%s",b+1);
		add(rt,0,strlen(b+1));
	}
	dfs(rt,0);
	int u=rt;
	for(int i=1;i<=len;i++){
		if(!ch[u][a[i]-'a']){
			las=a[i]-'a';
			break;
		}
		u=ch[u][a[i]-'a'];
	}
	cout<<solve(u)<<'\n';
//	return 0;
	for(int i=1;i<=m;i++){
		x=read();
		scanf("%s",c+1);
		x=len-x+1;
		if(deep[u]+x>=len){
			int cz=x-(len-deep[u]);
			u=tiao(u,cz);
			u=g[u][c[1]-'a'];
			if(deep[u]!=len){
				las=c[1]-'a';
			}
			else {
				las=0;
			}
		}
		cout<<solve(u)<<'\n';
	}
    #ifdef newbiewzs
		double endd=clock();
		cerr<<'\n';
		cerr<<"Time:"<<endd-startt<<" ms"<<'\n';
	#endif
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 24132kb

input:

4 3
anatoly
boris
anatooo
anbbbbu
anba
5 o
3 b
7 x

output:

0
0
2
3

result:

ok 4 number(s): "0 0 2 3"

Test #2:

score: 0
Accepted
time: 2ms
memory: 24148kb

input:

5 5
abcde
buz
ababa
build
a
aba
1 b
3 z
2 u
4 z
1 a

output:

3
3
3
4
4
1

result:

ok 6 numbers

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 24132kb

input:

1 1
abababababababababababab
ababababababababababababab
23 b

output:

0
0

result:

wrong answer 2nd numbers differ - expected: '1', found: '0'