QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22873#2135. How Many Strings Are LessLFCode#WA 2ms18148kbC++142.6kb2022-03-10 18:59:142022-04-30 01:53:50

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:53:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:18148kb
  • [2022-03-10 18:59:14]
  • 提交

answer

#include<bits/stdc++.h>
#include<cstdio>
#include<cctype>
#define ll long long
#define PI pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define ui unsigned int
#define pb push_back
#define llu long long unsigned
using namespace std;
const int MB=1<<20;
struct FastIO{
	char ib[MB+100],*p,*q;
	char ob[MB+100],*r,stk[128];
	int tp;
	FastIO(){p=q=ib,r=ob,tp=0;}
	~FastIO(){fwrite(ob,1,r-ob,stdout);}
	char read_char(){if(p==q){p=ib,q=ib+fread(ib,1,MB,stdin);if(p==q)return 0;}return *p++;}
	template<typename T>
	void read_int(T& x){char c=read_char(),l=0;for(x=0;!isdigit(c);c=read_char())l=c;for(;isdigit(c);c=read_char())x=x*10-'0'+c;if(l=='-')x=-x;}
	void write_char(char c){if(r-ob==MB)r=ob,fwrite(ob,1,MB,stdout);*r++=c;}
	template<typename T>
	void write_int(T x){if(x<0)write_char('-'),x=-x;do stk[++tp]=x%10+'0';while(x/=10);while(tp)write_char(stk[tp--]);}
}IO;
//IO.read_int(a);c=IO.read_char();IO.write_int(a);//IO.write_char(c);
const int N=1000010;
int T,n,q,a[N];
char yuan[N],usin[N];
int id;
int cc[N][26],siz[N],siz2[N],dk[N][26];
int st[N][21];
int dep[N],lyt[N][26];
void ins(char *s){
	int now=0;
	int len=strlen(s+1);
	for(int i=1;i<=len;i++){
		if(cc[now][s[i]-'a']){
			now=cc[now][s[i]-'a'];
		}
		else{
			now=cc[now][s[i]-'a']=++id;
		}
	}
	siz[now]++;
}
int ss;
void dfs(int u){
	ss+=siz[u];
	siz2[u]=ss;
	for(int i=1;i<=20;i++){
		st[u][i]=st[st[u][i-1]][i-1];
	}
	for(int i=0;i<26;i++){
		if(cc[u][i]){
			dep[cc[u][i]]=dep[u]+1;
			st[cc[u][i]][0]=u;
			dfs(cc[u][i]);
			lyt[u][i]=lyt[cc[u][i]][i];
		}
		else{
			cc[u][i]=++id;
			dep[cc[u][i]]=dep[u]+1;
			st[cc[u][i]][0]=u;
			for(int i=1;i<=20;i++){
				st[id][i]=st[st[id][i-1]][i-1];
			}
			siz2[id]=ss;
			lyt[u][i]=u;
		}
	}
}
int findd(char *s){
	int now=0;
	int len=strlen(s+1);
	for(int i=1;i<=len;i++){
		if(cc[now][s[i]-'a']){
			now=cc[now][s[i]-'a'];
		}
		else{
			return now;
		}
	}
	return now;
}
int main(){
//	scanf("%d",&T);
	T=1;
	while(T--){
		scanf("%d%d",&n,&q);
		scanf("%s",yuan+1);
		int ly=strlen(yuan+1);
		for(int i=1;i<=n;i++){
			scanf("%s",usin+1);
			ins(usin);
		}
		dfs(0);
		int sl=findd(yuan);
		printf("%d\n",siz2[sl]-(dep[sl]==ly?siz[sl]:0));
		for(int i=1;i<=q;i++){
			int num;
			char cc;
			scanf("%d %c",&num,&cc);
			int bb=dep[sl]-num+1;
			if(bb>0)
			for(int o=20;o>=0;o--){
				if((bb>>o)&1){
					sl=st[sl][o];
				}
			}
			sl=lyt[sl][cc-'a'];
			if(dep[sl]>ly){
				for(int o=20;o>=0;o--){
					if(((dep[sl]-ly)>>o)&1){
						sl=st[sl][o];
					}
				}
			}
			printf("%d\n",siz2[sl]-(dep[sl]==ly?siz[sl]:0));
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 18148kb

input:

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

output:

0
0
2
2

result:

wrong answer 4th numbers differ - expected: '3', found: '2'