QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22799 | #2135. How Many Strings Are Less | Mr_Eight# | WA | 3ms | 20180kb | C++20 | 3.5kb | 2022-03-10 16:55:40 | 2022-04-30 01:42:22 |
Judging History
answer
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <climits>
#include <functional>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
//#include <random>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/priority_queue.hpp>
#define itn int
#define nit int
#define ll long long
#define ms multiset
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define re register
#define ri re int
#define il inline
#define pii pair<int,int>
#define cp complex<double>
#define vi vector<int>
#define ull unsigned long long
#define mem0(x) memset(x,0,sizeof(x))
#define mem0x3f(x) memset(x,0x3f,sizeof(x))
using namespace std;
//using namespace __gnu_pbds;
const double Pi=acos(-1);
namespace fastIO {
template<class T>
inline void read(T &x) {
x=0;
bool fu=0;
char ch=0;
while(ch>'9'||ch<'0') {
ch=getchar();
if(ch=='-')fu=1;
}
while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
if(fu)x=-x;
}
inline int read() {
int x=0;
bool fu=0;
char ch=0;
while(ch>'9'||ch<'0') {
ch=getchar();
if(ch=='-')fu=1;
}
while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
return fu?-x:x;
}
template<class T,class... Args>
inline void read(T& t,Args&... args) {
read(t);
read(args...);
}
char _n_u_m_[40];
template<class T>
inline void write(T x) {
if(x==0) {
putchar('0');
return;
}
T tmp = x > 0 ? x : -x ;
if( x < 0 ) putchar('-') ;
register int cnt = 0 ;
while( tmp > 0 ) {
_n_u_m_[ cnt ++ ] = tmp % 10 + '0' ;
tmp /= 10 ;
}
while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ;
}
template<class T>
inline void write(T x ,char ch) {
write(x);
putchar(ch);
}
}
using namespace fastIO;
int n,q,len,cnt;
int ch[1000002][26],f[1000002],fa[1000002][20],res[1000002][26],d[1000002],c[1000002],ans[1000002][27],sum[1000002];
char s[1000002],temp[1000002];
int now,fly=26,v[1000002];
inline int to(int pos,int len) {
int x=d[pos]-len;//cerr<<x<<endl;
if(x>0)F(i,0,19)if(x>>i&1)pos=fa[pos][i];
return pos;
}
inline void modify(int llen,char c) {//cerr<<d[now]<<" "<<llen<<"k"<<to(now,llen)<<endl;
now=to(now,llen);
if(d[now]>=llen)now=res[now][c-'a'];
if(d[now]>=llen&&d[now]!=len)fly=c-'a';
if(d[now]==len)fly=26;
}
inline void dfs(int pos) {
fa[pos][0]=f[pos];
F(i,1,19)fa[pos][i]=fa[fa[pos][i-1]][i-1];
F(i,0,25)res[pos][i]=pos;
F(i,0,25)if(ch[pos][i]) {
d[ch[pos][i]]=d[pos]+1;f[ch[pos][i]]=pos;
dfs(ch[pos][i]);
if(d[i]<len)res[pos][i]=res[ch[pos][i]][i];
}
}
inline void getans(int pos) {
ans[pos][26]=cnt;
cnt+=v[pos];
ans[pos][0]=cnt;
F(i,0,25) {
if(ch[pos][i]) {
getans(ch[pos][i]);
}
if(i!=25)ans[pos][i+1]=cnt;
}
}
int main() {
cin>>n>>q;
scanf("%s",s+1);
len=strlen(s+1);
F(i,1,n) {
scanf("%s",temp);
int now=0;
for(int j=0; temp[j]; ++j) {
if(ch[now][temp[j]-'a'])now=ch[now][temp[j]-'a'];
else ch[now][temp[j]-'a']=++cnt,now=cnt;
c[now]=temp[j];
}
++v[now];
}
dfs(0);
cnt=0;
getans(0);
F(i,1,len)modify(i-1,s[i]);//cerr<<now<<" "<<fly<<endl;
write(ans[now][fly],'\n');
//
F(i,1,q) {
int pos=read();
scanf("%s",s);
modify(pos-1,s[0]);
write(ans[now][fly],'\n');//cerr<<now<<" "<<fly<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 20124kb
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: 3ms
memory: 20180kb
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: 2ms
memory: 20052kb
input:
1 1 abababababababababababab ababababababababababababab 23 b
output:
0 1
result:
ok 2 number(s): "0 1"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 20024kb
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 4 4 0 4 4 4 4 4 0 4 4 0 0 4 0 0 0 4 0 4 0 4 4 0 0 0 0 4 4 0 4 4 0 0 4 4 4 4 4 4 4 0 0 4 0 4 4 4 4 0 4 4 4 4 4 4 4 0 0 4 0 4 4 0 0 0 0 4 0 4 4 0 0 4 4 4 0 4 0 0 4 4 4 4 0 0 0 0 4 4 0 4 4 4 4 0 4 4 4
result:
wrong answer 3rd numbers differ - expected: '2', found: '4'