QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22865#2135. How Many Strings Are LessWhybullYMe#WA 10ms61452kbC++201.5kb2022-03-10 18:52:262022-04-30 01:53:06

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:06]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:61452kb
  • [2022-03-10 18:52:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ri int
typedef long long ll;
const int maxn=1e6+10;
template<class T>inline bool ckmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T>inline bool ckmax(T &x,const T &y){return x<y?x=y,1:0;}
template<class T>inline void clear(T *arr,int siz,int val=0){memset(arr,val,sizeof(T)*(siz+1));}
vector<int>a[maxn];
int ans[maxn][26],cnt,ed[maxn],f[maxn][26],id[maxn],n,pos[maxn],q,sum,trie[maxn][26];
string s,t[maxn];
void dfs(int p){
	sum+=ed[p];
	for(ri i=0;i<26;++i){
		ans[p][i]=sum;
		if(pos[p]+1==s.size())ans[p][i]-=ed[p];
		if(trie[p][i])dfs(trie[p][i]);
	}
	if(pos[p]>=s.size())return;
	for(ri i=0;i<26;++i)f[p][i]=(trie[p][i]?max(p,f[trie[p][i]][i]):p);
}
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q>>s;
    for(ri i=1;i<=n;++i){
		cin>>t[i];
		ri cur=0,now=0;
		a[i].push_back(now);
		for(char ch:t[i]){
			ri &nxt=trie[now][ch-'a'];
			if(!nxt)nxt=++cnt;
			now=nxt;
			a[i].push_back(now),id[now]=i,pos[now]=cur++;
		}
		++ed[now];
	}
	pos[0]=-1;
	dfs(0);
	ri now=0;
	for(char ch:s){
		ri nxt=trie[now][ch-'a'];
		if(!nxt)break;
		now=nxt;
	}
	char mx=(pos[now]+1==s.size()?'a':s[pos[now]+1]);
	cout<<ans[now][mx-'a']<<endl;
	while(q--){
		ri k;
		char c;
		cin>>k>>c;
		if(pos[now]+2>=k){
			if(pos[now]+2>k)now=a[id[now]][k-1];
			now=f[now][c-'a'],mx=(pos[now]+1==s.size()?'a':c);
		}
		cout<<ans[now][mx-'a']<<endl;
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 10ms
memory: 61452kb

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

input:

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

output:

3
3
3
3
3
0

result:

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