#include "bits/stdc++.h"
using namespace std;
typedef vector<int> vi;
const int N=1000001;
const short no_op=-1;
int n, q;
string a, b, c, t;
struct segtree{
int n;
string s;
int cnt[N][3];
bool good[N];
short lazy[N];
void build(int x, int lx, int rx){
if(rx-lx==1){
cnt[x][s[lx]-'0']=1;
return;
}
int m=(lx+rx)/2;
build(2*x+1, lx, m);
build(2*x+2, m, rx);
for(int i=0; i<3; i++){
cnt[x][i]=cnt[2*x+1][i]+cnt[2*x+2][i];
}
}
segtree(int n, string s){
this->n=n, this->s=s;
for(int i=0; i<4*n; i++){
cnt[i][0]=cnt[i][1]=cnt[i][2]=0;
good[i]=0;
lazy[i]=no_op;
}
build(0, 0, n);
}
void push(int x, int lx, int rx){
if(rx-lx==1 || lazy[x]==no_op) return;
short v=lazy[x];
int m=(lx+rx)/2;
good[2*x+1]=(m-lx)==cnt[2*x+1][v];
good[2*x+2]=(rx-m)==cnt[2*x+2][v];
lazy[2*x+1]=lazy[2*x+2]=v;
lazy[x]=no_op;
}
void upd(int l, int r, int v, int x, int lx, int rx){
push(x, lx, rx);
if(lx>=r || rx<=l) return;
if(lx>=l && rx<=r){
lazy[x]=v;
good[x]=(rx-lx)==cnt[x][v];
return;
}
int m=(lx+rx)/2;
upd(l, r, v, 2*x+1, lx, m);
upd(l, r, v, 2*x+2, m, rx);
good[x]=good[2*x+1] and good[2*x+2];
}
void upd(int l, int r, int v){ upd(l, r, v, 0, 0, n); }
bool query(){ return good[0]; }
};
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> a >> b >> c;
map<char, char> mp={{'J', '0'}, {'O', '1'}, {'I', '2'}};
for(int i=0; i<n; i++){
a[i]=mp[a[i]];
b[i]=mp[b[i]];
c[i]=mp[c[i]];
}
vector<segtree> seg;
vector<int> h(3);
h[0]=h[1]=h[2]=1;
for(int z=0; z<3; z++){
h[z]=-1;
string s="";
for(int p=0; p<n; p++){
int A=a[p]-'0';
int B=b[p]-'0';
int C=c[p]-'0';
int d=(h[0]*A+h[1]*B+h[2]*C+9)%3;
s+=static_cast<char>('0'+d);
}
segtree st(n, s);
seg.push_back(st);
h[z]=1;
}
h[0]=h[1]=h[2]=-1;
for(int z=0; z<3; z++){
h[z]=0;
string s="";
for(int p=0; p<n; p++){
int A=a[p]-'0';
int B=b[p]-'0';
int C=c[p]-'0';
int d=(h[0]*A+h[1]*B+h[2]*C+9)%3;
s+=static_cast<char>('0'+d);
}
segtree st(n, s);
seg.push_back(st);
h[z]=-1;
}
h[0]=h[1]=h[2]=0;
for(int z=0; z<3; z++){
h[z]=1;
string s="";
for(int p=0; p<n; p++){
int A=a[p]-'0';
int B=b[p]-'0';
int C=c[p]-'0';
int d=(h[0]*A+h[1]*B+h[2]*C+9)%3;
s+=static_cast<char>('0'+d);
}
segtree st(n, s);
seg.push_back(st);
h[z]=0;
}
auto upd=[&](int l, int r, int v){
for(int i=0; i<9; i++){
seg[i].upd(l, r, v);
}
};
auto any=[&]()->bool{
for(int i=0; i<9; i++){
if(seg[i].query()) return 1;
}
return 0;
};
cin >> q >> t;
for(int i=0; i<n; i++){
upd(i, i+1, mp[t[i]]-'0');
}
cout << (any()?"Yes":"No") << "\n";
while(q--){
int l, r; char c; cin >> l >> r >> c;
l--, r--;
int v=mp[c]-'0';
upd(l, r+1, v);
cout << (any()?"Yes":"No") << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
338 ms |
264500 KB |
Output is correct |
2 |
Correct |
379 ms |
264452 KB |
Output is correct |
3 |
Correct |
364 ms |
264404 KB |
Output is correct |
4 |
Correct |
316 ms |
264480 KB |
Output is correct |
5 |
Correct |
314 ms |
264416 KB |
Output is correct |
6 |
Correct |
304 ms |
264384 KB |
Output is correct |
7 |
Correct |
319 ms |
264404 KB |
Output is correct |
8 |
Correct |
337 ms |
264480 KB |
Output is correct |
9 |
Correct |
340 ms |
264424 KB |
Output is correct |
10 |
Correct |
316 ms |
264432 KB |
Output is correct |
11 |
Correct |
328 ms |
264496 KB |
Output is correct |
12 |
Correct |
318 ms |
264476 KB |
Output is correct |
13 |
Correct |
331 ms |
264468 KB |
Output is correct |
14 |
Correct |
335 ms |
264424 KB |
Output is correct |
15 |
Correct |
333 ms |
264372 KB |
Output is correct |
16 |
Correct |
317 ms |
264460 KB |
Output is correct |
17 |
Correct |
332 ms |
264424 KB |
Output is correct |
18 |
Correct |
333 ms |
264508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
338 ms |
264500 KB |
Output is correct |
2 |
Correct |
379 ms |
264452 KB |
Output is correct |
3 |
Correct |
364 ms |
264404 KB |
Output is correct |
4 |
Correct |
316 ms |
264480 KB |
Output is correct |
5 |
Correct |
314 ms |
264416 KB |
Output is correct |
6 |
Correct |
304 ms |
264384 KB |
Output is correct |
7 |
Correct |
319 ms |
264404 KB |
Output is correct |
8 |
Correct |
337 ms |
264480 KB |
Output is correct |
9 |
Correct |
340 ms |
264424 KB |
Output is correct |
10 |
Correct |
316 ms |
264432 KB |
Output is correct |
11 |
Correct |
328 ms |
264496 KB |
Output is correct |
12 |
Correct |
318 ms |
264476 KB |
Output is correct |
13 |
Correct |
331 ms |
264468 KB |
Output is correct |
14 |
Correct |
335 ms |
264424 KB |
Output is correct |
15 |
Correct |
333 ms |
264372 KB |
Output is correct |
16 |
Correct |
317 ms |
264460 KB |
Output is correct |
17 |
Correct |
332 ms |
264424 KB |
Output is correct |
18 |
Correct |
333 ms |
264508 KB |
Output is correct |
19 |
Correct |
2309 ms |
267316 KB |
Output is correct |
20 |
Correct |
1946 ms |
267360 KB |
Output is correct |
21 |
Correct |
1299 ms |
267176 KB |
Output is correct |
22 |
Correct |
1327 ms |
266904 KB |
Output is correct |
23 |
Correct |
574 ms |
264716 KB |
Output is correct |
24 |
Correct |
554 ms |
264556 KB |
Output is correct |
25 |
Correct |
1455 ms |
267276 KB |
Output is correct |
26 |
Correct |
1564 ms |
267276 KB |
Output is correct |
27 |
Correct |
1931 ms |
267256 KB |
Output is correct |
28 |
Correct |
1946 ms |
267236 KB |
Output is correct |
29 |
Correct |
1759 ms |
267176 KB |
Output is correct |
30 |
Correct |
673 ms |
264660 KB |
Output is correct |
31 |
Correct |
1835 ms |
267340 KB |
Output is correct |
32 |
Correct |
1788 ms |
267112 KB |
Output is correct |
33 |
Correct |
579 ms |
264644 KB |
Output is correct |
34 |
Correct |
1972 ms |
267312 KB |
Output is correct |
35 |
Correct |
1272 ms |
266716 KB |
Output is correct |
36 |
Correct |
615 ms |
264552 KB |
Output is correct |
37 |
Correct |
541 ms |
264576 KB |
Output is correct |
38 |
Correct |
1627 ms |
267364 KB |
Output is correct |
39 |
Correct |
850 ms |
267264 KB |
Output is correct |
40 |
Correct |
1216 ms |
266476 KB |
Output is correct |
41 |
Correct |
2606 ms |
267360 KB |
Output is correct |
42 |
Correct |
470 ms |
267292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
338 ms |
264500 KB |
Output is correct |
2 |
Correct |
379 ms |
264452 KB |
Output is correct |
3 |
Correct |
364 ms |
264404 KB |
Output is correct |
4 |
Correct |
316 ms |
264480 KB |
Output is correct |
5 |
Correct |
314 ms |
264416 KB |
Output is correct |
6 |
Correct |
304 ms |
264384 KB |
Output is correct |
7 |
Correct |
319 ms |
264404 KB |
Output is correct |
8 |
Correct |
337 ms |
264480 KB |
Output is correct |
9 |
Correct |
340 ms |
264424 KB |
Output is correct |
10 |
Correct |
316 ms |
264432 KB |
Output is correct |
11 |
Correct |
328 ms |
264496 KB |
Output is correct |
12 |
Correct |
318 ms |
264476 KB |
Output is correct |
13 |
Correct |
331 ms |
264468 KB |
Output is correct |
14 |
Correct |
335 ms |
264424 KB |
Output is correct |
15 |
Correct |
333 ms |
264372 KB |
Output is correct |
16 |
Correct |
317 ms |
264460 KB |
Output is correct |
17 |
Correct |
332 ms |
264424 KB |
Output is correct |
18 |
Correct |
333 ms |
264508 KB |
Output is correct |
19 |
Correct |
385 ms |
264440 KB |
Output is correct |
20 |
Correct |
439 ms |
264420 KB |
Output is correct |
21 |
Correct |
371 ms |
264488 KB |
Output is correct |
22 |
Correct |
304 ms |
264376 KB |
Output is correct |
23 |
Correct |
350 ms |
264476 KB |
Output is correct |
24 |
Correct |
339 ms |
264664 KB |
Output is correct |
25 |
Correct |
371 ms |
264424 KB |
Output is correct |
26 |
Correct |
324 ms |
264572 KB |
Output is correct |
27 |
Correct |
335 ms |
264408 KB |
Output is correct |
28 |
Correct |
321 ms |
264388 KB |
Output is correct |
29 |
Correct |
334 ms |
264448 KB |
Output is correct |
30 |
Correct |
333 ms |
264432 KB |
Output is correct |
31 |
Correct |
353 ms |
264500 KB |
Output is correct |
32 |
Correct |
362 ms |
264428 KB |
Output is correct |
33 |
Correct |
373 ms |
264424 KB |
Output is correct |
34 |
Correct |
318 ms |
264484 KB |
Output is correct |
35 |
Correct |
359 ms |
264500 KB |
Output is correct |
36 |
Correct |
343 ms |
264420 KB |
Output is correct |
37 |
Correct |
398 ms |
264488 KB |
Output is correct |
38 |
Correct |
348 ms |
264444 KB |
Output is correct |
39 |
Correct |
353 ms |
264388 KB |
Output is correct |
40 |
Correct |
356 ms |
264420 KB |
Output is correct |
41 |
Correct |
349 ms |
264424 KB |
Output is correct |
42 |
Correct |
343 ms |
264580 KB |
Output is correct |
43 |
Correct |
334 ms |
264436 KB |
Output is correct |
44 |
Correct |
350 ms |
264452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
338 ms |
264500 KB |
Output is correct |
2 |
Correct |
379 ms |
264452 KB |
Output is correct |
3 |
Correct |
364 ms |
264404 KB |
Output is correct |
4 |
Correct |
316 ms |
264480 KB |
Output is correct |
5 |
Correct |
314 ms |
264416 KB |
Output is correct |
6 |
Correct |
304 ms |
264384 KB |
Output is correct |
7 |
Correct |
319 ms |
264404 KB |
Output is correct |
8 |
Correct |
337 ms |
264480 KB |
Output is correct |
9 |
Correct |
340 ms |
264424 KB |
Output is correct |
10 |
Correct |
316 ms |
264432 KB |
Output is correct |
11 |
Correct |
328 ms |
264496 KB |
Output is correct |
12 |
Correct |
318 ms |
264476 KB |
Output is correct |
13 |
Correct |
331 ms |
264468 KB |
Output is correct |
14 |
Correct |
335 ms |
264424 KB |
Output is correct |
15 |
Correct |
333 ms |
264372 KB |
Output is correct |
16 |
Correct |
317 ms |
264460 KB |
Output is correct |
17 |
Correct |
332 ms |
264424 KB |
Output is correct |
18 |
Correct |
333 ms |
264508 KB |
Output is correct |
19 |
Correct |
2309 ms |
267316 KB |
Output is correct |
20 |
Correct |
1946 ms |
267360 KB |
Output is correct |
21 |
Correct |
1299 ms |
267176 KB |
Output is correct |
22 |
Correct |
1327 ms |
266904 KB |
Output is correct |
23 |
Correct |
574 ms |
264716 KB |
Output is correct |
24 |
Correct |
554 ms |
264556 KB |
Output is correct |
25 |
Correct |
1455 ms |
267276 KB |
Output is correct |
26 |
Correct |
1564 ms |
267276 KB |
Output is correct |
27 |
Correct |
1931 ms |
267256 KB |
Output is correct |
28 |
Correct |
1946 ms |
267236 KB |
Output is correct |
29 |
Correct |
1759 ms |
267176 KB |
Output is correct |
30 |
Correct |
673 ms |
264660 KB |
Output is correct |
31 |
Correct |
1835 ms |
267340 KB |
Output is correct |
32 |
Correct |
1788 ms |
267112 KB |
Output is correct |
33 |
Correct |
579 ms |
264644 KB |
Output is correct |
34 |
Correct |
1972 ms |
267312 KB |
Output is correct |
35 |
Correct |
1272 ms |
266716 KB |
Output is correct |
36 |
Correct |
615 ms |
264552 KB |
Output is correct |
37 |
Correct |
541 ms |
264576 KB |
Output is correct |
38 |
Correct |
1627 ms |
267364 KB |
Output is correct |
39 |
Correct |
850 ms |
267264 KB |
Output is correct |
40 |
Correct |
1216 ms |
266476 KB |
Output is correct |
41 |
Correct |
2606 ms |
267360 KB |
Output is correct |
42 |
Correct |
470 ms |
267292 KB |
Output is correct |
43 |
Correct |
385 ms |
264440 KB |
Output is correct |
44 |
Correct |
439 ms |
264420 KB |
Output is correct |
45 |
Correct |
371 ms |
264488 KB |
Output is correct |
46 |
Correct |
304 ms |
264376 KB |
Output is correct |
47 |
Correct |
350 ms |
264476 KB |
Output is correct |
48 |
Correct |
339 ms |
264664 KB |
Output is correct |
49 |
Correct |
371 ms |
264424 KB |
Output is correct |
50 |
Correct |
324 ms |
264572 KB |
Output is correct |
51 |
Correct |
335 ms |
264408 KB |
Output is correct |
52 |
Correct |
321 ms |
264388 KB |
Output is correct |
53 |
Correct |
334 ms |
264448 KB |
Output is correct |
54 |
Correct |
333 ms |
264432 KB |
Output is correct |
55 |
Correct |
353 ms |
264500 KB |
Output is correct |
56 |
Correct |
362 ms |
264428 KB |
Output is correct |
57 |
Correct |
373 ms |
264424 KB |
Output is correct |
58 |
Correct |
318 ms |
264484 KB |
Output is correct |
59 |
Correct |
359 ms |
264500 KB |
Output is correct |
60 |
Correct |
343 ms |
264420 KB |
Output is correct |
61 |
Correct |
398 ms |
264488 KB |
Output is correct |
62 |
Correct |
348 ms |
264444 KB |
Output is correct |
63 |
Correct |
353 ms |
264388 KB |
Output is correct |
64 |
Correct |
356 ms |
264420 KB |
Output is correct |
65 |
Correct |
349 ms |
264424 KB |
Output is correct |
66 |
Correct |
343 ms |
264580 KB |
Output is correct |
67 |
Correct |
334 ms |
264436 KB |
Output is correct |
68 |
Correct |
350 ms |
264452 KB |
Output is correct |
69 |
Correct |
2165 ms |
266836 KB |
Output is correct |
70 |
Correct |
1937 ms |
267224 KB |
Output is correct |
71 |
Correct |
602 ms |
264640 KB |
Output is correct |
72 |
Correct |
629 ms |
264560 KB |
Output is correct |
73 |
Correct |
594 ms |
264664 KB |
Output is correct |
74 |
Correct |
1299 ms |
266924 KB |
Output is correct |
75 |
Correct |
555 ms |
264552 KB |
Output is correct |
76 |
Correct |
1438 ms |
267352 KB |
Output is correct |
77 |
Correct |
1467 ms |
266948 KB |
Output is correct |
78 |
Correct |
662 ms |
264552 KB |
Output is correct |
79 |
Correct |
682 ms |
264628 KB |
Output is correct |
80 |
Correct |
1479 ms |
266576 KB |
Output is correct |
81 |
Correct |
682 ms |
264532 KB |
Output is correct |
82 |
Correct |
1765 ms |
267328 KB |
Output is correct |
83 |
Correct |
1690 ms |
267084 KB |
Output is correct |
84 |
Correct |
611 ms |
264628 KB |
Output is correct |
85 |
Correct |
602 ms |
264660 KB |
Output is correct |
86 |
Correct |
1860 ms |
266680 KB |
Output is correct |
87 |
Correct |
1988 ms |
267324 KB |
Output is correct |
88 |
Correct |
669 ms |
264560 KB |
Output is correct |
89 |
Correct |
1689 ms |
267056 KB |
Output is correct |
90 |
Correct |
1754 ms |
267256 KB |
Output is correct |
91 |
Correct |
630 ms |
264584 KB |
Output is correct |
92 |
Correct |
1351 ms |
266628 KB |
Output is correct |
93 |
Correct |
553 ms |
264556 KB |
Output is correct |
94 |
Correct |
553 ms |
264552 KB |
Output is correct |
95 |
Correct |
583 ms |
264632 KB |
Output is correct |
96 |
Correct |
1552 ms |
267312 KB |
Output is correct |
97 |
Correct |
788 ms |
267228 KB |
Output is correct |
98 |
Correct |
1156 ms |
266460 KB |
Output is correct |
99 |
Correct |
2618 ms |
267328 KB |
Output is correct |
100 |
Correct |
483 ms |
267340 KB |
Output is correct |