#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7,P=31;
map<char,int> mp;
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;
}
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;
}
#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);
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 sum=0;
int ans=0;
for(auto x:a){
ans+=x;
ans%=mod;
}
for(auto x:b) {
sum+=x;
sum%=mod;
}
puts(ans==sum?"Yes":"No");
while(q--){
int l,r;
cin>>l>>r;
l--,r--;
char c;
cin>>c;
for(int i=l;i<=r;i++){
sum-=b[i];
sum%=mod;
if(sum<0) sum+=mod;
sum%=mod;
b[i]=(mp[c]*binpow(P,i)%mod)%mod;
sum+=b[i];
sum%=mod;
if(sum<0) sum+=mod;
sum%=mod;
}
if(ans==sum){
puts("Yes");
}else puts("No");
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
2388 KB |
Output is correct |
2 |
Correct |
87 ms |
2388 KB |
Output is correct |
3 |
Correct |
367 ms |
2396 KB |
Output is correct |
4 |
Correct |
68 ms |
2384 KB |
Output is correct |
5 |
Correct |
66 ms |
2412 KB |
Output is correct |
6 |
Correct |
64 ms |
2388 KB |
Output is correct |
7 |
Correct |
65 ms |
2384 KB |
Output is correct |
8 |
Correct |
87 ms |
2472 KB |
Output is correct |
9 |
Correct |
68 ms |
2420 KB |
Output is correct |
10 |
Correct |
82 ms |
2388 KB |
Output is correct |
11 |
Correct |
72 ms |
2388 KB |
Output is correct |
12 |
Correct |
78 ms |
2336 KB |
Output is correct |
13 |
Correct |
71 ms |
2388 KB |
Output is correct |
14 |
Correct |
76 ms |
2388 KB |
Output is correct |
15 |
Correct |
73 ms |
2516 KB |
Output is correct |
16 |
Correct |
78 ms |
2388 KB |
Output is correct |
17 |
Correct |
69 ms |
2388 KB |
Output is correct |
18 |
Correct |
367 ms |
2408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
2388 KB |
Output is correct |
2 |
Correct |
87 ms |
2388 KB |
Output is correct |
3 |
Correct |
367 ms |
2396 KB |
Output is correct |
4 |
Correct |
68 ms |
2384 KB |
Output is correct |
5 |
Correct |
66 ms |
2412 KB |
Output is correct |
6 |
Correct |
64 ms |
2388 KB |
Output is correct |
7 |
Correct |
65 ms |
2384 KB |
Output is correct |
8 |
Correct |
87 ms |
2472 KB |
Output is correct |
9 |
Correct |
68 ms |
2420 KB |
Output is correct |
10 |
Correct |
82 ms |
2388 KB |
Output is correct |
11 |
Correct |
72 ms |
2388 KB |
Output is correct |
12 |
Correct |
78 ms |
2336 KB |
Output is correct |
13 |
Correct |
71 ms |
2388 KB |
Output is correct |
14 |
Correct |
76 ms |
2388 KB |
Output is correct |
15 |
Correct |
73 ms |
2516 KB |
Output is correct |
16 |
Correct |
78 ms |
2388 KB |
Output is correct |
17 |
Correct |
69 ms |
2388 KB |
Output is correct |
18 |
Correct |
367 ms |
2408 KB |
Output is correct |
19 |
Execution timed out |
7059 ms |
5176 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
2388 KB |
Output is correct |
2 |
Correct |
87 ms |
2388 KB |
Output is correct |
3 |
Correct |
367 ms |
2396 KB |
Output is correct |
4 |
Correct |
68 ms |
2384 KB |
Output is correct |
5 |
Correct |
66 ms |
2412 KB |
Output is correct |
6 |
Correct |
64 ms |
2388 KB |
Output is correct |
7 |
Correct |
65 ms |
2384 KB |
Output is correct |
8 |
Correct |
87 ms |
2472 KB |
Output is correct |
9 |
Correct |
68 ms |
2420 KB |
Output is correct |
10 |
Correct |
82 ms |
2388 KB |
Output is correct |
11 |
Correct |
72 ms |
2388 KB |
Output is correct |
12 |
Correct |
78 ms |
2336 KB |
Output is correct |
13 |
Correct |
71 ms |
2388 KB |
Output is correct |
14 |
Correct |
76 ms |
2388 KB |
Output is correct |
15 |
Correct |
73 ms |
2516 KB |
Output is correct |
16 |
Correct |
78 ms |
2388 KB |
Output is correct |
17 |
Correct |
69 ms |
2388 KB |
Output is correct |
18 |
Correct |
367 ms |
2408 KB |
Output is correct |
19 |
Correct |
91 ms |
2388 KB |
Output is correct |
20 |
Correct |
360 ms |
2384 KB |
Output is correct |
21 |
Incorrect |
84 ms |
2388 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
2388 KB |
Output is correct |
2 |
Correct |
87 ms |
2388 KB |
Output is correct |
3 |
Correct |
367 ms |
2396 KB |
Output is correct |
4 |
Correct |
68 ms |
2384 KB |
Output is correct |
5 |
Correct |
66 ms |
2412 KB |
Output is correct |
6 |
Correct |
64 ms |
2388 KB |
Output is correct |
7 |
Correct |
65 ms |
2384 KB |
Output is correct |
8 |
Correct |
87 ms |
2472 KB |
Output is correct |
9 |
Correct |
68 ms |
2420 KB |
Output is correct |
10 |
Correct |
82 ms |
2388 KB |
Output is correct |
11 |
Correct |
72 ms |
2388 KB |
Output is correct |
12 |
Correct |
78 ms |
2336 KB |
Output is correct |
13 |
Correct |
71 ms |
2388 KB |
Output is correct |
14 |
Correct |
76 ms |
2388 KB |
Output is correct |
15 |
Correct |
73 ms |
2516 KB |
Output is correct |
16 |
Correct |
78 ms |
2388 KB |
Output is correct |
17 |
Correct |
69 ms |
2388 KB |
Output is correct |
18 |
Correct |
367 ms |
2408 KB |
Output is correct |
19 |
Execution timed out |
7059 ms |
5176 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |