QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#22868#2135. How Many Strings Are LessWhybullYMe#TL 79ms237092kbC++201.5kb2022-03-10 18:55:122022-04-30 01:53:23

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:23]
  • 评测
  • 测评结果:TL
  • 用时:79ms
  • 内存:237092kb
  • [2022-03-10 18:55:12]
  • 提交

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],len,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]==len-1)ans[p][i]-=ed[p];
		if(trie[p][i])dfs(trie[p][i]);
	}
	if(pos[p]>=len)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;
    pos[0]=-1;
    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];
	}
	len=s.size();
	dfs(0);
	ri now=0;
	for(char ch:s){
		ri nxt=trie[now][ch-'a'];
		if(!nxt)break;
		now=nxt;
	}
	char mx=(pos[now]==len-1?'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]==len-1?'a':c);
		}
		cout<<ans[now][mx-'a']<<endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 61312kb

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: 14ms
memory: 61376kb

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: 0
Accepted
time: 9ms
memory: 61392kb

input:

1 1
abababababababababababab
ababababababababababababab
23 b

output:

0
1

result:

ok 2 number(s): "0 1"

Test #4:

score: 0
Accepted
time: 3ms
memory: 59328kb

input:

4 100
b
dd
ds
ss
sd
1 d
1 s
1 s
1 d
1 s
1 s
1 s
1 s
1 s
1 d
1 s
1 s
1 d
1 d
1 s
1 d
1 d
1 d
1 s
1 d
1 s
1 d
1 s
1 s
1 d
1 d
1 d
1 d
1 s
1 s
1 d
1 s
1 s
1 d
1 d
1 s
1 s
1 s
1 s
1 s
1 s
1 s
1 d
1 d
1 s
1 d
1 s
1 s
1 s
1 s
1 d
1 s
1 s
1 s
1 s
1 s
1 s
1 s
1 d
1 d
1 s
1 d
1 s
1 s
1 d
1 d
1 d
1 d
1 s
1 d
...

output:

0
0
2
2
0
2
2
2
2
2
0
2
2
0
0
2
0
0
0
2
0
2
0
2
2
0
0
0
0
2
2
0
2
2
0
0
2
2
2
2
2
2
2
0
0
2
0
2
2
2
2
0
2
2
2
2
2
2
2
0
0
2
0
2
2
0
0
0
0
2
0
2
2
0
0
2
2
2
0
2
0
0
2
2
2
2
0
0
0
0
2
2
0
2
2
2
2
0
2
2
2

result:

ok 101 numbers

Test #5:

score: 0
Accepted
time: 4ms
memory: 61456kb

input:

10 10
lvv
lvvl
lll
ll
vvll
vl
vllvv
vll
vllvl
llvl
vv
2 l
1 l
3 v
1 v
1 v
3 l
3 l
1 l
2 v
1 v

output:

3
1
1
2
10
10
9
9
1
3
10

result:

ok 11 numbers

Test #6:

score: 0
Accepted
time: 10ms
memory: 59344kb

input:

20 20
ffffqqqfqq
fffqfff
fq
qqfqff
fqfqqqf
fqfqf
fqfffffqfq
fqffffq
qfffqqfq
f
qq
f
fffffqq
q
qqqqffffq
qfqqqfff
ffqff
qqfqfqf
qqfq
qqqqfqqqf
ffqqfffqf
8 f
5 q
8 f
2 q
2 f
3 f
6 f
4 q
2 f
10 f
9 q
10 q
2 q
10 f
5 f
6 f
5 f
7 f
6 f
3 q

output:

3
3
3
3
11
2
2
2
4
2
2
2
2
11
11
11
11
11
11
11
11

result:

ok 21 numbers

Test #7:

score: 0
Accepted
time: 8ms
memory: 61464kb

input:

4 100
enf
gggppp
ppggpg
pggpgp
gppgpg
2 g
2 p
2 p
3 p
1 p
1 g
3 p
1 g
3 p
2 g
3 g
2 p
3 p
3 p
3 p
3 p
2 g
3 g
1 g
2 p
1 g
3 p
1 p
1 p
1 g
2 g
2 g
1 g
1 p
3 g
1 g
3 p
1 g
2 g
1 g
3 g
1 p
3 p
1 p
2 g
2 g
2 g
1 p
3 p
1 p
2 g
2 g
2 p
2 p
2 g
2 p
2 p
2 p
1 g
2 p
1 g
3 p
2 g
3 g
1 g
2 g
1 g
1 p
2 p
1 g
3 ...

output:

0
0
0
0
0
4
0
1
0
1
0
0
1
1
1
1
1
0
0
0
1
0
1
4
4
0
0
0
0
4
3
0
1
0
0
0
0
4
4
4
2
2
2
4
4
4
2
2
4
4
2
4
4
4
0
1
0
1
0
0
0
0
0
4
4
0
1
0
1
0
1
0
0
4
3
4
4
4
4
2
0
0
1
0
0
0
0
1
0
1
0
1
1
1
0
0
1
1
0
1
4

result:

ok 101 numbers

Test #8:

score: 0
Accepted
time: 9ms
memory: 59492kb

input:

50 50
yyy
iyiyiyyyiiii
yiiiyyyiiiyi
iiiiiiyyyyiiiyiyii
yiyyiyyiiy
yyyiiyiyiiyiiiyyyyiyy
iiyyyyyiiiiiiiiyyiyiyii
iy
iiyiyiiii
yyiiiiiyyyy
yiyiyiiiiiyiyyyiiyiy
iiiiiyyyy
yyiiiiyiiiyyiiy
iiyyiyyiyyiiyyyyiiiiyiiyiiyiyii
iiiiyyyiiyii
i
iiyyyyyyiiyiyii
iiyiiyyiyyyyyiiiiyiy
yyiyiyyyyiiyyiiyyiyyiyi
yyyiiyiy...

output:

45
45
22
22
45
45
45
45
2
45
37
22
22
22
33
22
22
22
22
33
45
2
2
45
45
45
45
45
45
45
45
45
37
45
45
45
37
45
2
2
19
45
37
45
37
45
45
2
2
7
7

result:

ok 51 numbers

Test #9:

score: 0
Accepted
time: 17ms
memory: 60896kb

input:

250 250
sbabbsb
bsbbb
asssaasbssa
sbaabbabaasbabaaabasaasbbsabbaaasasbsbbbaabs
sasasbbbbaassssabssaabasababssaaabaabssbsass
b
basasabbsbasaasbabsabbsabassbabssbasbbsaa
ssbassbaasbsabssssssasbsassabsasbsbsbsaasbsb
baabbsaabsbbassasasssbabsaaabababbsb
sababssaabababaaa
sbba
basaassbbsbaaaasbssbbbsbsbb...

output:

203
203
201
209
2
8
2
4
2
2
48
48
42
138
2
13
13
13
13
13
13
13
13
48
48
2
13
29
24
24
29
29
21
21
90
250
249
250
209
209
209
209
209
209
209
250
242
242
250
250
249
209
213
171
171
209
209
209
209
209
209
171
250
2
2
29
16
21
21
14
14
2
8
8
8
48
48
48
90
90
76
2
2
6
2
16
29
27
29
2
13
29
29
29
29
2...

result:

ok 251 numbers

Test #10:

score: 0
Accepted
time: 79ms
memory: 237092kb

input:

2500 2500
xdwxxxdxwxdwdxdwwwwdwxdxdwwxdxwwdxxdwwwdxxxxxdddwwwxdwxdxxxdwdwxxwwwwxwxdxwxdxdxwdxdxxdwdwxwwxddwwxdddddxxxddxwwxwxwxddwwxdwdxwxdxwwxdddwxwxwwddxdxdddwxwdwwdwwdwwxwdw
wwwwxwdxdxddwxwwdwwxxddxxw
w
wdxwxxxxwdwxdwdxxwwdxxxwwxwwxdwxwddddxwdwdxwdddxxdxddwwxddddxxxxdxwdwdwdxxxwdxwxxdwddwddwxwxww...

output:

1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1254
1254
1254
1254
...

result:

ok 2501 numbers

Test #11:

score: -100
Time Limit Exceeded

input:

10000 100000
bbbbjbbrrbjrjr
brjbrbjbjbrbjrbrjrbjbjrrjjbrjrjbjjrjr
bbjjbbjrbbbbrjjrbbbbrrbrjrbrbjjbbjbbbj
jbbrjbjbjjbbbjbrbbrbjbbrrbrbrrbrrbjbjjjrbjrrrrrbjbbjrrjjbrjjrbrrrbb
b
jjbrjrjrrrjbbbrjjbjjjbrrbbjjjjjjbrrbjjbrrrjrrjrbjrrbbjbrjj
jbjrbbrbjjjjbrbbrbjbrbjjbjrbbjjrjrbrjjbjjbbjjbbjjjbrbrrb
jjrbbrbrr...

output:

91
91
90
90
90
90
91
91
91
91
99
99
5034
5034
5033
5045
5034
5034
5034
5034
5034
5034
59
59
59
59
59
59
59
59
60
10000
9999
8383
8383
8383
10000
5034
5034
3396
3511
4524
4524
4480
4482
4482
3396
3396
3413
3413
3413
3396
10000
9997
9997
9997
9997
9997
8889
8383
8383
8383
8390
7812
8383
8385
8383
8383...

result: