//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 2e5+10;
int n,m;
int tree[10][maxn*4];
int add[maxn*4];
int cnt[10][maxn*4][3];
int num[maxn];
string s[3];
int comb[9][3] = {{0,0,1},{0,1,0},{1,0,0},{0,2,2},{2,0,2},{2,2,0},{1,1,2},{1,2,1},{2,1,1}};
int val[9][maxn];
string ss;
void init(int c,int cl,int cr) {
if (cl==cr) {
rep(i,0,9) tree[i][c] = (num[int(ss[cl])]==val[i][cl]),cnt[i][c][val[i][cl]]=1;
return;
}
int mid=cl+cr>>1;
init(c<<1,cl,mid);
init(c<<1|1,mid+1,cr);
rep(i,0,9) {
tree[i][c] = tree[i][c<<1] + tree[i][c<<1|1];
rep(j,0,3) cnt[i][c][j] = cnt[i][c<<1][j] + cnt[i][c<<1|1][j];
}
return;
}
void update(int c,int cl,int cr,int l,int r,int x) {
if (l<=cl and cr<=r) {
rep(i,0,9) tree[i][c] = cnt[i][c][x];
add[c] = x;
return;
}
if (add[c]!=-1) {
int tmp = add[c];
rep(i,0,9) tree[i][c<<1] = cnt[i][c<<1][tmp], tree[i][c<<1|1] = cnt[i][c<<1|1][tmp];
add[c<<1] = tmp, add[c<<1|1] = tmp;
add[c] = -1;
}
int mid=cl+cr>>1;
if (l<=mid) update(c<<1,cl,mid,l,r,x);
if (r>mid) update(c<<1|1,mid+1,cr,l,r,x);
rep(i,0,9) tree[i][c] = tree[i][c<<1] + tree[i][c<<1|1];
}
int main() {
// freopen("input.txt","r",stdin);
memset(add,-1,sizeof(add));
std::ios::sync_with_stdio(false);cin.tie(0);
num[int('J')]=0,num[int('O')]=1,num[int('I')]=2;
cin>>n>>s[0]>>s[1]>>s[2];
rep(i,0,9) {
rep(k,0,n) {
int res = 0;
rep(j,0,3) res += comb[i][j] * num[int(s[j][k])];
res%=3;
val[i][k] = res;
// cout<<val[i][k]<<" ";
}
// cout<<endl;
}
cin>>m>>ss;
init(1,0,n-1);
bool flag= false;
rep(i,0,9) if (tree[i][1]==n) flag=true;
if (flag) cout<<"Yes\n";
else cout<<"No\n";
// debug(tree[8][1]);
while (m--) {
int l,r;char c;
cin>>l>>r>>c;
l--,r--;
update(1,0,n-1,l,r,num[int(c)]);
// debug(num[int(c)]);
flag=false;
rep(i,0,9) if (tree[i][1]==n) {flag=true;break;}
if (flag) cout<<"Yes\n";
else cout<<"No\n";
// debug(tree[8][1]);
}
return 0;
}
Compilation message
Main.cpp: In function 'void init(int, int, int)':
Main.cpp:42:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int mid=cl+cr>>1;
| ~~^~~
Main.cpp: In function 'void update(int, int, int, int, int, int)':
Main.cpp:64:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
64 | int mid=cl+cr>>1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
5656 KB |
Output is correct |
2 |
Correct |
81 ms |
5824 KB |
Output is correct |
3 |
Correct |
100 ms |
5672 KB |
Output is correct |
4 |
Correct |
71 ms |
5628 KB |
Output is correct |
5 |
Correct |
63 ms |
5608 KB |
Output is correct |
6 |
Correct |
65 ms |
5588 KB |
Output is correct |
7 |
Correct |
67 ms |
5712 KB |
Output is correct |
8 |
Correct |
68 ms |
5728 KB |
Output is correct |
9 |
Correct |
74 ms |
5768 KB |
Output is correct |
10 |
Correct |
68 ms |
5732 KB |
Output is correct |
11 |
Correct |
69 ms |
5716 KB |
Output is correct |
12 |
Correct |
68 ms |
5760 KB |
Output is correct |
13 |
Correct |
73 ms |
5708 KB |
Output is correct |
14 |
Correct |
70 ms |
5760 KB |
Output is correct |
15 |
Correct |
69 ms |
5760 KB |
Output is correct |
16 |
Correct |
69 ms |
5708 KB |
Output is correct |
17 |
Correct |
80 ms |
5760 KB |
Output is correct |
18 |
Correct |
75 ms |
5704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
5656 KB |
Output is correct |
2 |
Correct |
81 ms |
5824 KB |
Output is correct |
3 |
Correct |
100 ms |
5672 KB |
Output is correct |
4 |
Correct |
71 ms |
5628 KB |
Output is correct |
5 |
Correct |
63 ms |
5608 KB |
Output is correct |
6 |
Correct |
65 ms |
5588 KB |
Output is correct |
7 |
Correct |
67 ms |
5712 KB |
Output is correct |
8 |
Correct |
68 ms |
5728 KB |
Output is correct |
9 |
Correct |
74 ms |
5768 KB |
Output is correct |
10 |
Correct |
68 ms |
5732 KB |
Output is correct |
11 |
Correct |
69 ms |
5716 KB |
Output is correct |
12 |
Correct |
68 ms |
5760 KB |
Output is correct |
13 |
Correct |
73 ms |
5708 KB |
Output is correct |
14 |
Correct |
70 ms |
5760 KB |
Output is correct |
15 |
Correct |
69 ms |
5760 KB |
Output is correct |
16 |
Correct |
69 ms |
5708 KB |
Output is correct |
17 |
Correct |
80 ms |
5760 KB |
Output is correct |
18 |
Correct |
75 ms |
5704 KB |
Output is correct |
19 |
Correct |
631 ms |
89696 KB |
Output is correct |
20 |
Correct |
418 ms |
89560 KB |
Output is correct |
21 |
Correct |
314 ms |
88968 KB |
Output is correct |
22 |
Correct |
324 ms |
88148 KB |
Output is correct |
23 |
Correct |
117 ms |
11596 KB |
Output is correct |
24 |
Correct |
123 ms |
11556 KB |
Output is correct |
25 |
Correct |
353 ms |
89588 KB |
Output is correct |
26 |
Correct |
422 ms |
89628 KB |
Output is correct |
27 |
Correct |
472 ms |
89628 KB |
Output is correct |
28 |
Correct |
451 ms |
89624 KB |
Output is correct |
29 |
Correct |
498 ms |
89448 KB |
Output is correct |
30 |
Correct |
134 ms |
11596 KB |
Output is correct |
31 |
Correct |
447 ms |
89724 KB |
Output is correct |
32 |
Correct |
506 ms |
88840 KB |
Output is correct |
33 |
Correct |
180 ms |
11544 KB |
Output is correct |
34 |
Correct |
461 ms |
89612 KB |
Output is correct |
35 |
Correct |
333 ms |
87156 KB |
Output is correct |
36 |
Correct |
131 ms |
11648 KB |
Output is correct |
37 |
Correct |
127 ms |
11600 KB |
Output is correct |
38 |
Correct |
404 ms |
89500 KB |
Output is correct |
39 |
Correct |
160 ms |
89756 KB |
Output is correct |
40 |
Correct |
288 ms |
49668 KB |
Output is correct |
41 |
Correct |
745 ms |
89980 KB |
Output is correct |
42 |
Correct |
94 ms |
89180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
5656 KB |
Output is correct |
2 |
Correct |
81 ms |
5824 KB |
Output is correct |
3 |
Correct |
100 ms |
5672 KB |
Output is correct |
4 |
Correct |
71 ms |
5628 KB |
Output is correct |
5 |
Correct |
63 ms |
5608 KB |
Output is correct |
6 |
Correct |
65 ms |
5588 KB |
Output is correct |
7 |
Correct |
67 ms |
5712 KB |
Output is correct |
8 |
Correct |
68 ms |
5728 KB |
Output is correct |
9 |
Correct |
74 ms |
5768 KB |
Output is correct |
10 |
Correct |
68 ms |
5732 KB |
Output is correct |
11 |
Correct |
69 ms |
5716 KB |
Output is correct |
12 |
Correct |
68 ms |
5760 KB |
Output is correct |
13 |
Correct |
73 ms |
5708 KB |
Output is correct |
14 |
Correct |
70 ms |
5760 KB |
Output is correct |
15 |
Correct |
69 ms |
5760 KB |
Output is correct |
16 |
Correct |
69 ms |
5708 KB |
Output is correct |
17 |
Correct |
80 ms |
5760 KB |
Output is correct |
18 |
Correct |
75 ms |
5704 KB |
Output is correct |
19 |
Correct |
76 ms |
5608 KB |
Output is correct |
20 |
Correct |
86 ms |
5572 KB |
Output is correct |
21 |
Correct |
67 ms |
5732 KB |
Output is correct |
22 |
Correct |
60 ms |
5588 KB |
Output is correct |
23 |
Correct |
67 ms |
5732 KB |
Output is correct |
24 |
Correct |
66 ms |
5716 KB |
Output is correct |
25 |
Correct |
68 ms |
5708 KB |
Output is correct |
26 |
Correct |
64 ms |
5644 KB |
Output is correct |
27 |
Correct |
67 ms |
5704 KB |
Output is correct |
28 |
Correct |
61 ms |
5508 KB |
Output is correct |
29 |
Correct |
68 ms |
5736 KB |
Output is correct |
30 |
Correct |
60 ms |
5580 KB |
Output is correct |
31 |
Correct |
67 ms |
5716 KB |
Output is correct |
32 |
Correct |
67 ms |
5796 KB |
Output is correct |
33 |
Correct |
67 ms |
5744 KB |
Output is correct |
34 |
Correct |
62 ms |
5580 KB |
Output is correct |
35 |
Correct |
69 ms |
5820 KB |
Output is correct |
36 |
Correct |
70 ms |
5712 KB |
Output is correct |
37 |
Correct |
68 ms |
5828 KB |
Output is correct |
38 |
Correct |
71 ms |
5708 KB |
Output is correct |
39 |
Correct |
67 ms |
5720 KB |
Output is correct |
40 |
Correct |
67 ms |
5776 KB |
Output is correct |
41 |
Correct |
68 ms |
5700 KB |
Output is correct |
42 |
Correct |
69 ms |
5780 KB |
Output is correct |
43 |
Correct |
67 ms |
5740 KB |
Output is correct |
44 |
Correct |
67 ms |
5708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
5656 KB |
Output is correct |
2 |
Correct |
81 ms |
5824 KB |
Output is correct |
3 |
Correct |
100 ms |
5672 KB |
Output is correct |
4 |
Correct |
71 ms |
5628 KB |
Output is correct |
5 |
Correct |
63 ms |
5608 KB |
Output is correct |
6 |
Correct |
65 ms |
5588 KB |
Output is correct |
7 |
Correct |
67 ms |
5712 KB |
Output is correct |
8 |
Correct |
68 ms |
5728 KB |
Output is correct |
9 |
Correct |
74 ms |
5768 KB |
Output is correct |
10 |
Correct |
68 ms |
5732 KB |
Output is correct |
11 |
Correct |
69 ms |
5716 KB |
Output is correct |
12 |
Correct |
68 ms |
5760 KB |
Output is correct |
13 |
Correct |
73 ms |
5708 KB |
Output is correct |
14 |
Correct |
70 ms |
5760 KB |
Output is correct |
15 |
Correct |
69 ms |
5760 KB |
Output is correct |
16 |
Correct |
69 ms |
5708 KB |
Output is correct |
17 |
Correct |
80 ms |
5760 KB |
Output is correct |
18 |
Correct |
75 ms |
5704 KB |
Output is correct |
19 |
Correct |
631 ms |
89696 KB |
Output is correct |
20 |
Correct |
418 ms |
89560 KB |
Output is correct |
21 |
Correct |
314 ms |
88968 KB |
Output is correct |
22 |
Correct |
324 ms |
88148 KB |
Output is correct |
23 |
Correct |
117 ms |
11596 KB |
Output is correct |
24 |
Correct |
123 ms |
11556 KB |
Output is correct |
25 |
Correct |
353 ms |
89588 KB |
Output is correct |
26 |
Correct |
422 ms |
89628 KB |
Output is correct |
27 |
Correct |
472 ms |
89628 KB |
Output is correct |
28 |
Correct |
451 ms |
89624 KB |
Output is correct |
29 |
Correct |
498 ms |
89448 KB |
Output is correct |
30 |
Correct |
134 ms |
11596 KB |
Output is correct |
31 |
Correct |
447 ms |
89724 KB |
Output is correct |
32 |
Correct |
506 ms |
88840 KB |
Output is correct |
33 |
Correct |
180 ms |
11544 KB |
Output is correct |
34 |
Correct |
461 ms |
89612 KB |
Output is correct |
35 |
Correct |
333 ms |
87156 KB |
Output is correct |
36 |
Correct |
131 ms |
11648 KB |
Output is correct |
37 |
Correct |
127 ms |
11600 KB |
Output is correct |
38 |
Correct |
404 ms |
89500 KB |
Output is correct |
39 |
Correct |
160 ms |
89756 KB |
Output is correct |
40 |
Correct |
288 ms |
49668 KB |
Output is correct |
41 |
Correct |
745 ms |
89980 KB |
Output is correct |
42 |
Correct |
94 ms |
89180 KB |
Output is correct |
43 |
Correct |
76 ms |
5608 KB |
Output is correct |
44 |
Correct |
86 ms |
5572 KB |
Output is correct |
45 |
Correct |
67 ms |
5732 KB |
Output is correct |
46 |
Correct |
60 ms |
5588 KB |
Output is correct |
47 |
Correct |
67 ms |
5732 KB |
Output is correct |
48 |
Correct |
66 ms |
5716 KB |
Output is correct |
49 |
Correct |
68 ms |
5708 KB |
Output is correct |
50 |
Correct |
64 ms |
5644 KB |
Output is correct |
51 |
Correct |
67 ms |
5704 KB |
Output is correct |
52 |
Correct |
61 ms |
5508 KB |
Output is correct |
53 |
Correct |
68 ms |
5736 KB |
Output is correct |
54 |
Correct |
60 ms |
5580 KB |
Output is correct |
55 |
Correct |
67 ms |
5716 KB |
Output is correct |
56 |
Correct |
67 ms |
5796 KB |
Output is correct |
57 |
Correct |
67 ms |
5744 KB |
Output is correct |
58 |
Correct |
62 ms |
5580 KB |
Output is correct |
59 |
Correct |
69 ms |
5820 KB |
Output is correct |
60 |
Correct |
70 ms |
5712 KB |
Output is correct |
61 |
Correct |
68 ms |
5828 KB |
Output is correct |
62 |
Correct |
71 ms |
5708 KB |
Output is correct |
63 |
Correct |
67 ms |
5720 KB |
Output is correct |
64 |
Correct |
67 ms |
5776 KB |
Output is correct |
65 |
Correct |
68 ms |
5700 KB |
Output is correct |
66 |
Correct |
69 ms |
5780 KB |
Output is correct |
67 |
Correct |
67 ms |
5740 KB |
Output is correct |
68 |
Correct |
67 ms |
5708 KB |
Output is correct |
69 |
Correct |
521 ms |
88036 KB |
Output is correct |
70 |
Correct |
445 ms |
89604 KB |
Output is correct |
71 |
Correct |
141 ms |
11824 KB |
Output is correct |
72 |
Correct |
126 ms |
11560 KB |
Output is correct |
73 |
Correct |
123 ms |
11564 KB |
Output is correct |
74 |
Correct |
349 ms |
87892 KB |
Output is correct |
75 |
Correct |
121 ms |
11564 KB |
Output is correct |
76 |
Correct |
378 ms |
89648 KB |
Output is correct |
77 |
Correct |
347 ms |
88100 KB |
Output is correct |
78 |
Correct |
125 ms |
11600 KB |
Output is correct |
79 |
Correct |
143 ms |
11512 KB |
Output is correct |
80 |
Correct |
304 ms |
86800 KB |
Output is correct |
81 |
Correct |
123 ms |
11592 KB |
Output is correct |
82 |
Correct |
333 ms |
89668 KB |
Output is correct |
83 |
Correct |
340 ms |
89088 KB |
Output is correct |
84 |
Correct |
118 ms |
11596 KB |
Output is correct |
85 |
Correct |
126 ms |
11596 KB |
Output is correct |
86 |
Correct |
432 ms |
87412 KB |
Output is correct |
87 |
Correct |
453 ms |
89716 KB |
Output is correct |
88 |
Correct |
129 ms |
11620 KB |
Output is correct |
89 |
Correct |
452 ms |
88496 KB |
Output is correct |
90 |
Correct |
439 ms |
89628 KB |
Output is correct |
91 |
Correct |
134 ms |
11596 KB |
Output is correct |
92 |
Correct |
280 ms |
87356 KB |
Output is correct |
93 |
Correct |
118 ms |
11488 KB |
Output is correct |
94 |
Correct |
141 ms |
11568 KB |
Output is correct |
95 |
Correct |
142 ms |
11528 KB |
Output is correct |
96 |
Correct |
345 ms |
89504 KB |
Output is correct |
97 |
Correct |
166 ms |
89632 KB |
Output is correct |
98 |
Correct |
347 ms |
49668 KB |
Output is correct |
99 |
Correct |
611 ms |
90000 KB |
Output is correct |
100 |
Correct |
88 ms |
89096 KB |
Output is correct |