#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define ui unsigned int
#define us unsigned short
#define inf_int 1e9
#define inf_ll 1e18
#define mod 1000000007
#define smod 998244353
map<pair<char, char>, char> mp;
const int maxN = 2e5 + 5;
const ll base = 5;
int n;
ll prefix[maxN];
ll convert(char c){
if(c == 'J') return 0;
else if(c == 'O') return 1;
else if(c == 'I') return 2;
}
struct SegTree { // index start from 0 (v)
ll tree[4*maxN], lazy[4*maxN];
int n;
void resize(int m){
n = m;
}
void build(int v, int l, int r, string s){
if(l > r) return;
if(l == r){
tree[v] = (prefix[l] - (l > 0 ? prefix[l-1] : 0) + mod) % mod * convert(s[l]) % mod;
lazy[v] = -1;
return;
}
int m = (l+r) >> 1;
build(v*2+1, l, m, s);
build(v*2+2, m+1, r, s);
tree[v] = (tree[v*2+1] + tree[v*2+2]) % mod;
lazy[v] = -1;
}
void push(int v, int l, int m, int r){
if(lazy[v] == -1) return;
tree[v*2+1] = (prefix[m] - (l > 0 ? prefix[l-1] : 0) + mod) % mod * lazy[v] % mod;
lazy[v*2+1] = lazy[v];
tree[v*2+2] = (prefix[r] - prefix[m] + mod) % mod * lazy[v] % mod;
lazy[v*2+2] = lazy[v];
lazy[v] = -1;
}
void update(int v, int curL, int curR, int l, int r, ll val){
if(l > r) return;
if(curL == l && r == curR){
tree[v] = (prefix[curR] - (curL > 0 ? prefix[curL-1] : 0) + mod) % mod * val % mod;
lazy[v] = val;
} else {
int curM = (curL+curR) >> 1;
push(v, curL, curM, curR);
update(v*2+1, curL, curM, l, min(r, curM), val);
update(v*2+2, curM+1, curR, max(l, curM+1), r, val);
tree[v] = (tree[v*2+1] + tree[v*2+2]) % mod;
}
}
ll query(int v, int curL, int curR, int l, int r){
if(l > r || curL > curR) return 0;
if(l <= curL && curR <= r){
return tree[v];
}
int curM = (curL+curR) >> 1;
push(v, curL, curM, curR);
return (query(v*2+1, curL, curM, l, min(r, curM)) + query(v*2+2, curM+1, curR, max(l, curM+1), r)) % mod;
}
};
SegTree tree;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
mp[{'J', 'O'}] = mp[{'O', 'J'}] = 'I';
mp[{'J', 'I'}] = mp[{'I', 'J'}] = 'O';
mp[{'I', 'O'}] = mp[{'O', 'I'}] = 'J';
cin >> n;
ll cur = 1;
prefix[0] = 1;
for(int x=1;x<n;x++){
cur *= base;
cur %= mod;
prefix[x] = (prefix[x-1] + cur) % mod;
}
set<string> st;
vector<string> v;
for(int x=0;x<3;x++){
string s;
cin >> s;
if(!st.count(s)){
st.insert(s);
v.push_back(s);
}
}
for(int x=0;x<v.size();x++){
for(int y=0;y<x;y++){
string tmp;
for(int z=0;z<v[x].length();z++){
if(v[x][z] == v[y][z]){
tmp.push_back(v[x][z]);
} else {
tmp.push_back(mp[{v[x][z], v[y][z]}]);
}
}
if(!st.count(tmp)){
st.insert(tmp);
v.push_back(tmp);
}
}
}
set<ll> st2;
for(auto s : st){
ll val = 0, cur = 1;
for(int x=0;x<n;x++){
val += convert(s[x]) * cur % mod;
val %= mod;
cur *= base;
cur %= mod;
}
st2.insert(val);
}
int q;
cin >> q;
string t;
cin >> t;
tree.resize(n);
tree.build(0, 0, n-1, t);
if(st2.count(tree.query(0, 0, n-1, 0, n-1))){
cout << "Yes\n";
} else {
cout << "No\n";
}
for(int i=1;i<=q;i++){
int l, r;
char c;
cin >> l >> r >> c;
l--; r--;
tree.update(0, 0, n-1, l, r, convert(c));
if(st2.count(tree.query(0, 0, n-1, 0, n-1))){
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:129:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
129 | for(int x=0;x<v.size();x++){
| ~^~~~~~~~~
Main.cpp:132:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
132 | for(int z=0;z<v[x].length();z++){
| ~^~~~~~~~~~~~~~
Main.cpp: In function 'long long int convert(char)':
Main.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
26 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
860 KB |
Output is correct |
2 |
Correct |
79 ms |
916 KB |
Output is correct |
3 |
Correct |
80 ms |
832 KB |
Output is correct |
4 |
Correct |
68 ms |
836 KB |
Output is correct |
5 |
Correct |
70 ms |
888 KB |
Output is correct |
6 |
Correct |
66 ms |
868 KB |
Output is correct |
7 |
Correct |
70 ms |
836 KB |
Output is correct |
8 |
Correct |
70 ms |
820 KB |
Output is correct |
9 |
Correct |
71 ms |
808 KB |
Output is correct |
10 |
Correct |
72 ms |
836 KB |
Output is correct |
11 |
Correct |
73 ms |
836 KB |
Output is correct |
12 |
Correct |
79 ms |
896 KB |
Output is correct |
13 |
Correct |
78 ms |
836 KB |
Output is correct |
14 |
Correct |
72 ms |
912 KB |
Output is correct |
15 |
Correct |
72 ms |
872 KB |
Output is correct |
16 |
Correct |
77 ms |
852 KB |
Output is correct |
17 |
Correct |
78 ms |
816 KB |
Output is correct |
18 |
Correct |
83 ms |
880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
860 KB |
Output is correct |
2 |
Correct |
79 ms |
916 KB |
Output is correct |
3 |
Correct |
80 ms |
832 KB |
Output is correct |
4 |
Correct |
68 ms |
836 KB |
Output is correct |
5 |
Correct |
70 ms |
888 KB |
Output is correct |
6 |
Correct |
66 ms |
868 KB |
Output is correct |
7 |
Correct |
70 ms |
836 KB |
Output is correct |
8 |
Correct |
70 ms |
820 KB |
Output is correct |
9 |
Correct |
71 ms |
808 KB |
Output is correct |
10 |
Correct |
72 ms |
836 KB |
Output is correct |
11 |
Correct |
73 ms |
836 KB |
Output is correct |
12 |
Correct |
79 ms |
896 KB |
Output is correct |
13 |
Correct |
78 ms |
836 KB |
Output is correct |
14 |
Correct |
72 ms |
912 KB |
Output is correct |
15 |
Correct |
72 ms |
872 KB |
Output is correct |
16 |
Correct |
77 ms |
852 KB |
Output is correct |
17 |
Correct |
78 ms |
816 KB |
Output is correct |
18 |
Correct |
83 ms |
880 KB |
Output is correct |
19 |
Execution timed out |
7065 ms |
10588 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
860 KB |
Output is correct |
2 |
Correct |
79 ms |
916 KB |
Output is correct |
3 |
Correct |
80 ms |
832 KB |
Output is correct |
4 |
Correct |
68 ms |
836 KB |
Output is correct |
5 |
Correct |
70 ms |
888 KB |
Output is correct |
6 |
Correct |
66 ms |
868 KB |
Output is correct |
7 |
Correct |
70 ms |
836 KB |
Output is correct |
8 |
Correct |
70 ms |
820 KB |
Output is correct |
9 |
Correct |
71 ms |
808 KB |
Output is correct |
10 |
Correct |
72 ms |
836 KB |
Output is correct |
11 |
Correct |
73 ms |
836 KB |
Output is correct |
12 |
Correct |
79 ms |
896 KB |
Output is correct |
13 |
Correct |
78 ms |
836 KB |
Output is correct |
14 |
Correct |
72 ms |
912 KB |
Output is correct |
15 |
Correct |
72 ms |
872 KB |
Output is correct |
16 |
Correct |
77 ms |
852 KB |
Output is correct |
17 |
Correct |
78 ms |
816 KB |
Output is correct |
18 |
Correct |
83 ms |
880 KB |
Output is correct |
19 |
Correct |
84 ms |
828 KB |
Output is correct |
20 |
Correct |
100 ms |
884 KB |
Output is correct |
21 |
Correct |
73 ms |
836 KB |
Output is correct |
22 |
Correct |
67 ms |
824 KB |
Output is correct |
23 |
Correct |
72 ms |
924 KB |
Output is correct |
24 |
Correct |
69 ms |
880 KB |
Output is correct |
25 |
Correct |
78 ms |
796 KB |
Output is correct |
26 |
Correct |
67 ms |
836 KB |
Output is correct |
27 |
Correct |
77 ms |
908 KB |
Output is correct |
28 |
Correct |
65 ms |
848 KB |
Output is correct |
29 |
Correct |
71 ms |
836 KB |
Output is correct |
30 |
Correct |
69 ms |
808 KB |
Output is correct |
31 |
Correct |
77 ms |
908 KB |
Output is correct |
32 |
Correct |
78 ms |
836 KB |
Output is correct |
33 |
Correct |
78 ms |
824 KB |
Output is correct |
34 |
Correct |
72 ms |
836 KB |
Output is correct |
35 |
Correct |
75 ms |
836 KB |
Output is correct |
36 |
Correct |
78 ms |
888 KB |
Output is correct |
37 |
Correct |
77 ms |
836 KB |
Output is correct |
38 |
Correct |
79 ms |
964 KB |
Output is correct |
39 |
Correct |
80 ms |
836 KB |
Output is correct |
40 |
Correct |
75 ms |
896 KB |
Output is correct |
41 |
Correct |
73 ms |
828 KB |
Output is correct |
42 |
Correct |
78 ms |
884 KB |
Output is correct |
43 |
Correct |
74 ms |
804 KB |
Output is correct |
44 |
Correct |
79 ms |
836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
860 KB |
Output is correct |
2 |
Correct |
79 ms |
916 KB |
Output is correct |
3 |
Correct |
80 ms |
832 KB |
Output is correct |
4 |
Correct |
68 ms |
836 KB |
Output is correct |
5 |
Correct |
70 ms |
888 KB |
Output is correct |
6 |
Correct |
66 ms |
868 KB |
Output is correct |
7 |
Correct |
70 ms |
836 KB |
Output is correct |
8 |
Correct |
70 ms |
820 KB |
Output is correct |
9 |
Correct |
71 ms |
808 KB |
Output is correct |
10 |
Correct |
72 ms |
836 KB |
Output is correct |
11 |
Correct |
73 ms |
836 KB |
Output is correct |
12 |
Correct |
79 ms |
896 KB |
Output is correct |
13 |
Correct |
78 ms |
836 KB |
Output is correct |
14 |
Correct |
72 ms |
912 KB |
Output is correct |
15 |
Correct |
72 ms |
872 KB |
Output is correct |
16 |
Correct |
77 ms |
852 KB |
Output is correct |
17 |
Correct |
78 ms |
816 KB |
Output is correct |
18 |
Correct |
83 ms |
880 KB |
Output is correct |
19 |
Execution timed out |
7065 ms |
10588 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |