#include<bits/stdc++.h>
using namespace std;
#define int long long
map<char,int> mp;
#define all(v) v.begin(),v.end()
struct Hash {
vector<int> v;
int P,mod;
const int maxn=2e5+100;
int pref[(int)2e5+100];
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;
}
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;
}
Node* root;
void b(string s,int p,int MOD){
P=p;
mod=MOD;
v=hsh(s);
for(int i=0;i<maxn;i++){
pref[i]=binpow(P,i);
if(i){
pref[i]=f(pref[i]+pref[i-1]%mod)%mod;
}
}
root=new Node();
int n=s.size();
build(root,0,n-1,v);
}
int get(){
return root->val;
}
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;
}
};
signed main(){
mp['J']=1;mp['O']=2;mp['I']=3;
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
string s;
cin>>s>>s>>s;
int q;
cin>>q;
string t;
cin>>t;
Hash a1;a1.b(s,31,1e9+7);
Hash b1;b1.b(t,31,1e9+7);
Hash a2;a2.b(s,37,1e9+3);
Hash b2;b2.b(t,37,1e9+3);
puts((a1.get()==b1.get()&&a2.get()==b2.get())?"Yes":"No");
while(q--){
int l,r;
cin>>l>>r,--l,--r;char c;cin>>c;
b1.update(b1.root,0,n-1,l,r,mp[c]);
b2.update(b2.root,0,n-1,l,r,mp[c]);
puts((a1.get()==b1.get()&&a2.get()==b2.get())?"Yes":"No");
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
7216 KB |
Output is correct |
2 |
Correct |
180 ms |
7236 KB |
Output is correct |
3 |
Correct |
262 ms |
7248 KB |
Output is correct |
4 |
Correct |
148 ms |
7264 KB |
Output is correct |
5 |
Correct |
161 ms |
7144 KB |
Output is correct |
6 |
Correct |
166 ms |
7240 KB |
Output is correct |
7 |
Correct |
145 ms |
7248 KB |
Output is correct |
8 |
Correct |
153 ms |
7252 KB |
Output is correct |
9 |
Correct |
147 ms |
7248 KB |
Output is correct |
10 |
Correct |
147 ms |
7248 KB |
Output is correct |
11 |
Correct |
151 ms |
7252 KB |
Output is correct |
12 |
Correct |
147 ms |
7248 KB |
Output is correct |
13 |
Correct |
147 ms |
7252 KB |
Output is correct |
14 |
Correct |
149 ms |
7232 KB |
Output is correct |
15 |
Correct |
146 ms |
7244 KB |
Output is correct |
16 |
Correct |
151 ms |
7252 KB |
Output is correct |
17 |
Correct |
148 ms |
7252 KB |
Output is correct |
18 |
Correct |
235 ms |
7228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
7216 KB |
Output is correct |
2 |
Correct |
180 ms |
7236 KB |
Output is correct |
3 |
Correct |
262 ms |
7248 KB |
Output is correct |
4 |
Correct |
148 ms |
7264 KB |
Output is correct |
5 |
Correct |
161 ms |
7144 KB |
Output is correct |
6 |
Correct |
166 ms |
7240 KB |
Output is correct |
7 |
Correct |
145 ms |
7248 KB |
Output is correct |
8 |
Correct |
153 ms |
7252 KB |
Output is correct |
9 |
Correct |
147 ms |
7248 KB |
Output is correct |
10 |
Correct |
147 ms |
7248 KB |
Output is correct |
11 |
Correct |
151 ms |
7252 KB |
Output is correct |
12 |
Correct |
147 ms |
7248 KB |
Output is correct |
13 |
Correct |
147 ms |
7252 KB |
Output is correct |
14 |
Correct |
149 ms |
7232 KB |
Output is correct |
15 |
Correct |
146 ms |
7244 KB |
Output is correct |
16 |
Correct |
151 ms |
7252 KB |
Output is correct |
17 |
Correct |
148 ms |
7252 KB |
Output is correct |
18 |
Correct |
235 ms |
7228 KB |
Output is correct |
19 |
Correct |
748 ms |
89132 KB |
Output is correct |
20 |
Correct |
876 ms |
89088 KB |
Output is correct |
21 |
Correct |
357 ms |
84412 KB |
Output is correct |
22 |
Correct |
360 ms |
76256 KB |
Output is correct |
23 |
Correct |
225 ms |
11516 KB |
Output is correct |
24 |
Correct |
228 ms |
11348 KB |
Output is correct |
25 |
Correct |
362 ms |
89088 KB |
Output is correct |
26 |
Correct |
393 ms |
89168 KB |
Output is correct |
27 |
Correct |
502 ms |
89056 KB |
Output is correct |
28 |
Correct |
523 ms |
89088 KB |
Output is correct |
29 |
Correct |
475 ms |
86948 KB |
Output is correct |
30 |
Correct |
279 ms |
11348 KB |
Output is correct |
31 |
Correct |
484 ms |
89088 KB |
Output is correct |
32 |
Correct |
455 ms |
81804 KB |
Output is correct |
33 |
Correct |
236 ms |
11160 KB |
Output is correct |
34 |
Correct |
483 ms |
89084 KB |
Output is correct |
35 |
Correct |
318 ms |
68224 KB |
Output is correct |
36 |
Correct |
229 ms |
11344 KB |
Output is correct |
37 |
Correct |
226 ms |
11344 KB |
Output is correct |
38 |
Correct |
774 ms |
89088 KB |
Output is correct |
39 |
Incorrect |
243 ms |
89084 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
7216 KB |
Output is correct |
2 |
Correct |
180 ms |
7236 KB |
Output is correct |
3 |
Correct |
262 ms |
7248 KB |
Output is correct |
4 |
Correct |
148 ms |
7264 KB |
Output is correct |
5 |
Correct |
161 ms |
7144 KB |
Output is correct |
6 |
Correct |
166 ms |
7240 KB |
Output is correct |
7 |
Correct |
145 ms |
7248 KB |
Output is correct |
8 |
Correct |
153 ms |
7252 KB |
Output is correct |
9 |
Correct |
147 ms |
7248 KB |
Output is correct |
10 |
Correct |
147 ms |
7248 KB |
Output is correct |
11 |
Correct |
151 ms |
7252 KB |
Output is correct |
12 |
Correct |
147 ms |
7248 KB |
Output is correct |
13 |
Correct |
147 ms |
7252 KB |
Output is correct |
14 |
Correct |
149 ms |
7232 KB |
Output is correct |
15 |
Correct |
146 ms |
7244 KB |
Output is correct |
16 |
Correct |
151 ms |
7252 KB |
Output is correct |
17 |
Correct |
148 ms |
7252 KB |
Output is correct |
18 |
Correct |
235 ms |
7228 KB |
Output is correct |
19 |
Correct |
178 ms |
7220 KB |
Output is correct |
20 |
Correct |
251 ms |
7252 KB |
Output is correct |
21 |
Incorrect |
150 ms |
7244 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
7216 KB |
Output is correct |
2 |
Correct |
180 ms |
7236 KB |
Output is correct |
3 |
Correct |
262 ms |
7248 KB |
Output is correct |
4 |
Correct |
148 ms |
7264 KB |
Output is correct |
5 |
Correct |
161 ms |
7144 KB |
Output is correct |
6 |
Correct |
166 ms |
7240 KB |
Output is correct |
7 |
Correct |
145 ms |
7248 KB |
Output is correct |
8 |
Correct |
153 ms |
7252 KB |
Output is correct |
9 |
Correct |
147 ms |
7248 KB |
Output is correct |
10 |
Correct |
147 ms |
7248 KB |
Output is correct |
11 |
Correct |
151 ms |
7252 KB |
Output is correct |
12 |
Correct |
147 ms |
7248 KB |
Output is correct |
13 |
Correct |
147 ms |
7252 KB |
Output is correct |
14 |
Correct |
149 ms |
7232 KB |
Output is correct |
15 |
Correct |
146 ms |
7244 KB |
Output is correct |
16 |
Correct |
151 ms |
7252 KB |
Output is correct |
17 |
Correct |
148 ms |
7252 KB |
Output is correct |
18 |
Correct |
235 ms |
7228 KB |
Output is correct |
19 |
Correct |
748 ms |
89132 KB |
Output is correct |
20 |
Correct |
876 ms |
89088 KB |
Output is correct |
21 |
Correct |
357 ms |
84412 KB |
Output is correct |
22 |
Correct |
360 ms |
76256 KB |
Output is correct |
23 |
Correct |
225 ms |
11516 KB |
Output is correct |
24 |
Correct |
228 ms |
11348 KB |
Output is correct |
25 |
Correct |
362 ms |
89088 KB |
Output is correct |
26 |
Correct |
393 ms |
89168 KB |
Output is correct |
27 |
Correct |
502 ms |
89056 KB |
Output is correct |
28 |
Correct |
523 ms |
89088 KB |
Output is correct |
29 |
Correct |
475 ms |
86948 KB |
Output is correct |
30 |
Correct |
279 ms |
11348 KB |
Output is correct |
31 |
Correct |
484 ms |
89088 KB |
Output is correct |
32 |
Correct |
455 ms |
81804 KB |
Output is correct |
33 |
Correct |
236 ms |
11160 KB |
Output is correct |
34 |
Correct |
483 ms |
89084 KB |
Output is correct |
35 |
Correct |
318 ms |
68224 KB |
Output is correct |
36 |
Correct |
229 ms |
11344 KB |
Output is correct |
37 |
Correct |
226 ms |
11344 KB |
Output is correct |
38 |
Correct |
774 ms |
89088 KB |
Output is correct |
39 |
Incorrect |
243 ms |
89084 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |