#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
const int P=31;
const int maxn=2e5+100;
int pref[maxn];
struct Node{
int val;
int lz;
Node* left,*right;
Node() : left(nullptr),right(nullptr){}
};
int f(int a){
a%=mod;
if(a<0) a+=mod;
return a%=mod;
}
int sum(int l,int r){
if(l==0) return pref[r];
return f(pref[r]%mod-pref[l-1]%mod)%mod;
}
void push(Node* node,int l,int r){
if(node->lz==0) return;
node->val=f(node->lz*f(sum(l,r))%mod);
if(l!=r){
node->left->lz=node->lz;
node->right->lz=node->lz;
}
node->lz=0;
}
void p(Node* node,int l,int r){
push(node,l,r);
int mid=(l+r)/2;
if(l==r) return;
push(node->left,l,mid);
push(node->right,mid+1,r);
}
void build(Node* node,int l,int r,vector<int> &v){
if(l==r){
node->val=v[l];
return;
}
int mid=(l+r)/2;
node->left=new Node();
node->right=new Node();
build(node->left,l,mid,v);
build(node->right,mid+1,r,v);
node->val=((node->left->val%mod)+(node->right->val%mod))%mod;
}
void update(Node* node,int l,int r,int ql,int qr,int x){
p(node,l,r);
if(ql<=l&&r<=qr){
node->lz=x;p(node,l,r);
return;
}
int mid=(l+r)>>1;
if(ql<=mid){
update(node->left,l,mid,ql,qr,x);
}
if(qr>mid) update(node->right,mid+1,r,ql,qr,x);
node->val=((node->left->val%mod)+(node->right->val%mod))%mod;
}
int query(Node* node,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr) return node->val%mod;
int mid=(l+r)/2;
int ans=0;
if(ql<=mid) ans=f(ans+query(node->left,l,mid,ql,qr)),ans%=mod;
if(qr>mid) ans=f(ans+query(node->right,mid+1,r,ql,qr)),ans%=mod;
return ans%mod;
}
map<char,int> mp;
vector<int> hsh(string s){
int n=s.length();
int c=1;
vector<int> v(n);
for(int i=0;i<n;i++){
int x=mp[s[i]];
v[i]=(x*c%mod)%mod;
c=(c*P%mod)%mod;
}
return v;
}
int binpow(int a,int b){
int res=1;
while(b){
if(b&1) {
res=(res*a%mod)%mod;
}
a=(a*a%mod)%mod;
b>>=1;
}
return res;
}
#define all(v) v.begin(),v.end()
signed main(){
mp['J']=1;mp['O']=2;mp['I']=3;
ios_base::sync_with_stdio(0);cin.tie(0);
for(int i=0;i<maxn;i++){
pref[i]=binpow(P,i)%mod;
if(i) {
pref[i]+=pref[i-1];
pref[i]%=mod;
}
}
int n;
cin>>n;
string s;
cin>>s>>s>>s;
int q;
cin>>q;
string t;
cin>>t;
vector<int> a=hsh(s);
vector<int> b=hsh(t);
int ans=0;
for(auto x:a){
ans+=x;
ans%=mod;
}
Node* r1=new Node();
build(r1,0,n-1,b);
puts((r1->val==ans?"Yes":"No"));
while(q--){
int l,r;
cin>>l>>r,--l,--r;char c;cin>>c;
update(r1,0,n-1,l,r,mp[c]);
puts((r1->val%mod==ans?"Yes":"No"));
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
2384 KB |
Output is correct |
2 |
Correct |
74 ms |
2492 KB |
Output is correct |
3 |
Correct |
88 ms |
2388 KB |
Output is correct |
4 |
Correct |
65 ms |
2388 KB |
Output is correct |
5 |
Correct |
61 ms |
2556 KB |
Output is correct |
6 |
Correct |
63 ms |
2384 KB |
Output is correct |
7 |
Correct |
61 ms |
2392 KB |
Output is correct |
8 |
Correct |
65 ms |
2384 KB |
Output is correct |
9 |
Correct |
71 ms |
2384 KB |
Output is correct |
10 |
Correct |
64 ms |
2384 KB |
Output is correct |
11 |
Correct |
66 ms |
2392 KB |
Output is correct |
12 |
Correct |
65 ms |
2384 KB |
Output is correct |
13 |
Correct |
65 ms |
2384 KB |
Output is correct |
14 |
Correct |
66 ms |
2584 KB |
Output is correct |
15 |
Correct |
65 ms |
2404 KB |
Output is correct |
16 |
Correct |
65 ms |
2388 KB |
Output is correct |
17 |
Correct |
66 ms |
2504 KB |
Output is correct |
18 |
Correct |
82 ms |
2540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
2384 KB |
Output is correct |
2 |
Correct |
74 ms |
2492 KB |
Output is correct |
3 |
Correct |
88 ms |
2388 KB |
Output is correct |
4 |
Correct |
65 ms |
2388 KB |
Output is correct |
5 |
Correct |
61 ms |
2556 KB |
Output is correct |
6 |
Correct |
63 ms |
2384 KB |
Output is correct |
7 |
Correct |
61 ms |
2392 KB |
Output is correct |
8 |
Correct |
65 ms |
2384 KB |
Output is correct |
9 |
Correct |
71 ms |
2384 KB |
Output is correct |
10 |
Correct |
64 ms |
2384 KB |
Output is correct |
11 |
Correct |
66 ms |
2392 KB |
Output is correct |
12 |
Correct |
65 ms |
2384 KB |
Output is correct |
13 |
Correct |
65 ms |
2384 KB |
Output is correct |
14 |
Correct |
66 ms |
2584 KB |
Output is correct |
15 |
Correct |
65 ms |
2404 KB |
Output is correct |
16 |
Correct |
65 ms |
2388 KB |
Output is correct |
17 |
Correct |
66 ms |
2504 KB |
Output is correct |
18 |
Correct |
82 ms |
2540 KB |
Output is correct |
19 |
Correct |
263 ms |
27572 KB |
Output is correct |
20 |
Correct |
303 ms |
28484 KB |
Output is correct |
21 |
Correct |
151 ms |
27044 KB |
Output is correct |
22 |
Correct |
143 ms |
24724 KB |
Output is correct |
23 |
Correct |
104 ms |
5996 KB |
Output is correct |
24 |
Correct |
106 ms |
6224 KB |
Output is correct |
25 |
Correct |
155 ms |
28612 KB |
Output is correct |
26 |
Correct |
163 ms |
28608 KB |
Output is correct |
27 |
Correct |
200 ms |
28608 KB |
Output is correct |
28 |
Correct |
198 ms |
28420 KB |
Output is correct |
29 |
Correct |
191 ms |
27836 KB |
Output is correct |
30 |
Correct |
125 ms |
5968 KB |
Output is correct |
31 |
Correct |
196 ms |
28612 KB |
Output is correct |
32 |
Correct |
181 ms |
26232 KB |
Output is correct |
33 |
Correct |
107 ms |
5968 KB |
Output is correct |
34 |
Correct |
192 ms |
28600 KB |
Output is correct |
35 |
Correct |
137 ms |
22296 KB |
Output is correct |
36 |
Correct |
108 ms |
5928 KB |
Output is correct |
37 |
Correct |
107 ms |
5968 KB |
Output is correct |
38 |
Correct |
247 ms |
28352 KB |
Output is correct |
39 |
Incorrect |
120 ms |
28564 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
2384 KB |
Output is correct |
2 |
Correct |
74 ms |
2492 KB |
Output is correct |
3 |
Correct |
88 ms |
2388 KB |
Output is correct |
4 |
Correct |
65 ms |
2388 KB |
Output is correct |
5 |
Correct |
61 ms |
2556 KB |
Output is correct |
6 |
Correct |
63 ms |
2384 KB |
Output is correct |
7 |
Correct |
61 ms |
2392 KB |
Output is correct |
8 |
Correct |
65 ms |
2384 KB |
Output is correct |
9 |
Correct |
71 ms |
2384 KB |
Output is correct |
10 |
Correct |
64 ms |
2384 KB |
Output is correct |
11 |
Correct |
66 ms |
2392 KB |
Output is correct |
12 |
Correct |
65 ms |
2384 KB |
Output is correct |
13 |
Correct |
65 ms |
2384 KB |
Output is correct |
14 |
Correct |
66 ms |
2584 KB |
Output is correct |
15 |
Correct |
65 ms |
2404 KB |
Output is correct |
16 |
Correct |
65 ms |
2388 KB |
Output is correct |
17 |
Correct |
66 ms |
2504 KB |
Output is correct |
18 |
Correct |
82 ms |
2540 KB |
Output is correct |
19 |
Correct |
74 ms |
2576 KB |
Output is correct |
20 |
Correct |
87 ms |
2484 KB |
Output is correct |
21 |
Incorrect |
64 ms |
2640 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
2384 KB |
Output is correct |
2 |
Correct |
74 ms |
2492 KB |
Output is correct |
3 |
Correct |
88 ms |
2388 KB |
Output is correct |
4 |
Correct |
65 ms |
2388 KB |
Output is correct |
5 |
Correct |
61 ms |
2556 KB |
Output is correct |
6 |
Correct |
63 ms |
2384 KB |
Output is correct |
7 |
Correct |
61 ms |
2392 KB |
Output is correct |
8 |
Correct |
65 ms |
2384 KB |
Output is correct |
9 |
Correct |
71 ms |
2384 KB |
Output is correct |
10 |
Correct |
64 ms |
2384 KB |
Output is correct |
11 |
Correct |
66 ms |
2392 KB |
Output is correct |
12 |
Correct |
65 ms |
2384 KB |
Output is correct |
13 |
Correct |
65 ms |
2384 KB |
Output is correct |
14 |
Correct |
66 ms |
2584 KB |
Output is correct |
15 |
Correct |
65 ms |
2404 KB |
Output is correct |
16 |
Correct |
65 ms |
2388 KB |
Output is correct |
17 |
Correct |
66 ms |
2504 KB |
Output is correct |
18 |
Correct |
82 ms |
2540 KB |
Output is correct |
19 |
Correct |
263 ms |
27572 KB |
Output is correct |
20 |
Correct |
303 ms |
28484 KB |
Output is correct |
21 |
Correct |
151 ms |
27044 KB |
Output is correct |
22 |
Correct |
143 ms |
24724 KB |
Output is correct |
23 |
Correct |
104 ms |
5996 KB |
Output is correct |
24 |
Correct |
106 ms |
6224 KB |
Output is correct |
25 |
Correct |
155 ms |
28612 KB |
Output is correct |
26 |
Correct |
163 ms |
28608 KB |
Output is correct |
27 |
Correct |
200 ms |
28608 KB |
Output is correct |
28 |
Correct |
198 ms |
28420 KB |
Output is correct |
29 |
Correct |
191 ms |
27836 KB |
Output is correct |
30 |
Correct |
125 ms |
5968 KB |
Output is correct |
31 |
Correct |
196 ms |
28612 KB |
Output is correct |
32 |
Correct |
181 ms |
26232 KB |
Output is correct |
33 |
Correct |
107 ms |
5968 KB |
Output is correct |
34 |
Correct |
192 ms |
28600 KB |
Output is correct |
35 |
Correct |
137 ms |
22296 KB |
Output is correct |
36 |
Correct |
108 ms |
5928 KB |
Output is correct |
37 |
Correct |
107 ms |
5968 KB |
Output is correct |
38 |
Correct |
247 ms |
28352 KB |
Output is correct |
39 |
Incorrect |
120 ms |
28564 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |