#include <bits/stdc++.h>
using namespace std;
struct segtree{
vector<char> curequals;
vector<char> targequals;
vector<bool> equals;
string cur;
string targ;
int size;
segtree(int _size, string _cur, string _targ): cur(_cur), targ(_targ), size(_size){
curequals.resize(4*size+5);
targequals.resize(4*size+5);
equals.resize(4*size+5);
build(0, size-1, 0);
}
void build(int left, int right, int pos){
if(left!=right){
int mid = (left+right)/2;
build(left, mid, 2*pos+1);
build(mid+1, right, 2*pos+2);
if(targequals[2*pos+1]==targequals[2*pos+2]){
targequals[pos]=targequals[2*pos+1];
}
else{
targequals[pos]='0';
}
if(curequals[2*pos+1]==curequals[2*pos+2]){
curequals[pos]=curequals[2*pos+1];
}
else{
curequals[pos]='0';
}
equals[pos]=(equals[2*pos+1] && equals[2*pos+2]);
}
else{
targequals[pos] = targ[left];
curequals[pos] = cur[left];
equals[pos] = (targequals[pos]==curequals[pos]);
}
}
void update(char c, int left, int right, int start, int end, int pos){
if(start==left && end==right){
curequals[pos] = c;
equals[pos] = (targequals[pos]!='0' && curequals[pos]==targequals[pos]);
}
else{
if(curequals[pos]!='0'){
curequals[2*pos+1] = curequals[pos];
equals[2*pos+1] = (targequals[2*pos+1]==curequals[2*pos+1]);
curequals[2*pos+2] = curequals[pos];
equals[2*pos+2] = (targequals[2*pos+2]==curequals[2*pos+2]);
curequals[pos] = '0';
}
int mid = (left+right)/2;
if(start>mid){
update(c, mid+1, right, start, end, 2*pos+2);
}
else if(end<=mid){
update(c, left, mid, start, end, 2*pos+1);
}
else{
update(c, left, mid, start, mid, 2*pos+1);
update(c, mid+1, right, mid+1, end, 2*pos+2);
}
equals[pos] = (equals[2*pos+2] && equals[2*pos+1]);
}
}
};
char func2(char a, char b){
if(a==b){
return a;
}
else{
if(a>b){
swap(a, b);
}
if(a=='I' && b=='J'){
return 'O';
}
else if(a=='I' && b=='O'){
return 'J';
}
else{
return 'I';
}
}
}
string func(string a, string b){
string c = "";
for(int i=0; i< (int) a.size(); i++){
c+=" ";
c[i]=func2(a[i], b[i]);
}
return c;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string a, b, c;
cin >> a >> b >> c;
set<string> vect;
vect.insert(a);
vect.insert(b);
vect.insert(c);
bool res = false;
do{
res = false;
for(auto i : vect){
for(auto u : vect){
if(!vect.count(func(i, u))){
vect.insert(func(i, u));
res = true;
}
}
}
}
while(res==true);
vector<string> refarr;
for(auto i : vect){
refarr.push_back(i);
}
int q;
cin >> q;
string init;
cin >> init;
int num = refarr.size();
vector<segtree> segs;
for(int i=0; i<num; i++){
segtree temp(n, init, refarr[i]);
segs.push_back(temp);
}
bool curres = false;
for(int i=0; i<num; i++){
curres = curres || segs[i].equals[0];
}
curres ? cout << "Yes\n" : cout << "No\n";
for(int i=0; i<q; i++){
int d, e;
char f;
cin >> d >> e >> f;
d--;
e--;
curres = false;
for(int j=0; j<num; j++){
segs[j].update(f, 0, n-1, d, e, 0);
curres = curres || segs[j].equals[0];
}
curres ? cout << "Yes\n" : cout << "No\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
1184 KB |
Output is correct |
2 |
Correct |
68 ms |
1288 KB |
Output is correct |
3 |
Correct |
75 ms |
1216 KB |
Output is correct |
4 |
Correct |
62 ms |
1312 KB |
Output is correct |
5 |
Correct |
60 ms |
1160 KB |
Output is correct |
6 |
Correct |
58 ms |
1124 KB |
Output is correct |
7 |
Correct |
58 ms |
1104 KB |
Output is correct |
8 |
Correct |
66 ms |
1200 KB |
Output is correct |
9 |
Correct |
62 ms |
1140 KB |
Output is correct |
10 |
Correct |
63 ms |
1100 KB |
Output is correct |
11 |
Correct |
64 ms |
1164 KB |
Output is correct |
12 |
Correct |
65 ms |
1188 KB |
Output is correct |
13 |
Correct |
60 ms |
1100 KB |
Output is correct |
14 |
Correct |
60 ms |
1040 KB |
Output is correct |
15 |
Correct |
78 ms |
1116 KB |
Output is correct |
16 |
Correct |
64 ms |
1100 KB |
Output is correct |
17 |
Correct |
71 ms |
1072 KB |
Output is correct |
18 |
Correct |
67 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
1184 KB |
Output is correct |
2 |
Correct |
68 ms |
1288 KB |
Output is correct |
3 |
Correct |
75 ms |
1216 KB |
Output is correct |
4 |
Correct |
62 ms |
1312 KB |
Output is correct |
5 |
Correct |
60 ms |
1160 KB |
Output is correct |
6 |
Correct |
58 ms |
1124 KB |
Output is correct |
7 |
Correct |
58 ms |
1104 KB |
Output is correct |
8 |
Correct |
66 ms |
1200 KB |
Output is correct |
9 |
Correct |
62 ms |
1140 KB |
Output is correct |
10 |
Correct |
63 ms |
1100 KB |
Output is correct |
11 |
Correct |
64 ms |
1164 KB |
Output is correct |
12 |
Correct |
65 ms |
1188 KB |
Output is correct |
13 |
Correct |
60 ms |
1100 KB |
Output is correct |
14 |
Correct |
60 ms |
1040 KB |
Output is correct |
15 |
Correct |
78 ms |
1116 KB |
Output is correct |
16 |
Correct |
64 ms |
1100 KB |
Output is correct |
17 |
Correct |
71 ms |
1072 KB |
Output is correct |
18 |
Correct |
67 ms |
1108 KB |
Output is correct |
19 |
Correct |
179 ms |
6244 KB |
Output is correct |
20 |
Correct |
202 ms |
5852 KB |
Output is correct |
21 |
Correct |
116 ms |
5664 KB |
Output is correct |
22 |
Correct |
121 ms |
5276 KB |
Output is correct |
23 |
Correct |
97 ms |
2220 KB |
Output is correct |
24 |
Correct |
90 ms |
2168 KB |
Output is correct |
25 |
Correct |
130 ms |
5952 KB |
Output is correct |
26 |
Correct |
133 ms |
5920 KB |
Output is correct |
27 |
Correct |
156 ms |
5808 KB |
Output is correct |
28 |
Correct |
159 ms |
5940 KB |
Output is correct |
29 |
Correct |
152 ms |
5740 KB |
Output is correct |
30 |
Correct |
109 ms |
2184 KB |
Output is correct |
31 |
Correct |
161 ms |
5896 KB |
Output is correct |
32 |
Correct |
136 ms |
5464 KB |
Output is correct |
33 |
Correct |
103 ms |
2100 KB |
Output is correct |
34 |
Correct |
153 ms |
5892 KB |
Output is correct |
35 |
Correct |
118 ms |
4756 KB |
Output is correct |
36 |
Correct |
90 ms |
2360 KB |
Output is correct |
37 |
Correct |
93 ms |
2244 KB |
Output is correct |
38 |
Correct |
170 ms |
5912 KB |
Output is correct |
39 |
Correct |
105 ms |
5812 KB |
Output is correct |
40 |
Correct |
127 ms |
4412 KB |
Output is correct |
41 |
Correct |
195 ms |
5964 KB |
Output is correct |
42 |
Correct |
45 ms |
6104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
1184 KB |
Output is correct |
2 |
Correct |
68 ms |
1288 KB |
Output is correct |
3 |
Correct |
75 ms |
1216 KB |
Output is correct |
4 |
Correct |
62 ms |
1312 KB |
Output is correct |
5 |
Correct |
60 ms |
1160 KB |
Output is correct |
6 |
Correct |
58 ms |
1124 KB |
Output is correct |
7 |
Correct |
58 ms |
1104 KB |
Output is correct |
8 |
Correct |
66 ms |
1200 KB |
Output is correct |
9 |
Correct |
62 ms |
1140 KB |
Output is correct |
10 |
Correct |
63 ms |
1100 KB |
Output is correct |
11 |
Correct |
64 ms |
1164 KB |
Output is correct |
12 |
Correct |
65 ms |
1188 KB |
Output is correct |
13 |
Correct |
60 ms |
1100 KB |
Output is correct |
14 |
Correct |
60 ms |
1040 KB |
Output is correct |
15 |
Correct |
78 ms |
1116 KB |
Output is correct |
16 |
Correct |
64 ms |
1100 KB |
Output is correct |
17 |
Correct |
71 ms |
1072 KB |
Output is correct |
18 |
Correct |
67 ms |
1108 KB |
Output is correct |
19 |
Correct |
321 ms |
1128 KB |
Output is correct |
20 |
Correct |
383 ms |
1152 KB |
Output is correct |
21 |
Correct |
117 ms |
1228 KB |
Output is correct |
22 |
Correct |
100 ms |
2180 KB |
Output is correct |
23 |
Correct |
137 ms |
2388 KB |
Output is correct |
24 |
Correct |
112 ms |
2296 KB |
Output is correct |
25 |
Correct |
120 ms |
2388 KB |
Output is correct |
26 |
Correct |
107 ms |
2276 KB |
Output is correct |
27 |
Correct |
119 ms |
2408 KB |
Output is correct |
28 |
Correct |
108 ms |
2212 KB |
Output is correct |
29 |
Correct |
118 ms |
2424 KB |
Output is correct |
30 |
Correct |
101 ms |
2220 KB |
Output is correct |
31 |
Correct |
257 ms |
2356 KB |
Output is correct |
32 |
Correct |
260 ms |
2348 KB |
Output is correct |
33 |
Correct |
276 ms |
2372 KB |
Output is correct |
34 |
Correct |
230 ms |
2304 KB |
Output is correct |
35 |
Correct |
260 ms |
2340 KB |
Output is correct |
36 |
Correct |
268 ms |
2464 KB |
Output is correct |
37 |
Correct |
252 ms |
2356 KB |
Output is correct |
38 |
Correct |
263 ms |
2408 KB |
Output is correct |
39 |
Correct |
271 ms |
2476 KB |
Output is correct |
40 |
Correct |
298 ms |
2432 KB |
Output is correct |
41 |
Correct |
254 ms |
2544 KB |
Output is correct |
42 |
Correct |
265 ms |
2380 KB |
Output is correct |
43 |
Correct |
242 ms |
2328 KB |
Output is correct |
44 |
Correct |
268 ms |
2360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
1184 KB |
Output is correct |
2 |
Correct |
68 ms |
1288 KB |
Output is correct |
3 |
Correct |
75 ms |
1216 KB |
Output is correct |
4 |
Correct |
62 ms |
1312 KB |
Output is correct |
5 |
Correct |
60 ms |
1160 KB |
Output is correct |
6 |
Correct |
58 ms |
1124 KB |
Output is correct |
7 |
Correct |
58 ms |
1104 KB |
Output is correct |
8 |
Correct |
66 ms |
1200 KB |
Output is correct |
9 |
Correct |
62 ms |
1140 KB |
Output is correct |
10 |
Correct |
63 ms |
1100 KB |
Output is correct |
11 |
Correct |
64 ms |
1164 KB |
Output is correct |
12 |
Correct |
65 ms |
1188 KB |
Output is correct |
13 |
Correct |
60 ms |
1100 KB |
Output is correct |
14 |
Correct |
60 ms |
1040 KB |
Output is correct |
15 |
Correct |
78 ms |
1116 KB |
Output is correct |
16 |
Correct |
64 ms |
1100 KB |
Output is correct |
17 |
Correct |
71 ms |
1072 KB |
Output is correct |
18 |
Correct |
67 ms |
1108 KB |
Output is correct |
19 |
Correct |
179 ms |
6244 KB |
Output is correct |
20 |
Correct |
202 ms |
5852 KB |
Output is correct |
21 |
Correct |
116 ms |
5664 KB |
Output is correct |
22 |
Correct |
121 ms |
5276 KB |
Output is correct |
23 |
Correct |
97 ms |
2220 KB |
Output is correct |
24 |
Correct |
90 ms |
2168 KB |
Output is correct |
25 |
Correct |
130 ms |
5952 KB |
Output is correct |
26 |
Correct |
133 ms |
5920 KB |
Output is correct |
27 |
Correct |
156 ms |
5808 KB |
Output is correct |
28 |
Correct |
159 ms |
5940 KB |
Output is correct |
29 |
Correct |
152 ms |
5740 KB |
Output is correct |
30 |
Correct |
109 ms |
2184 KB |
Output is correct |
31 |
Correct |
161 ms |
5896 KB |
Output is correct |
32 |
Correct |
136 ms |
5464 KB |
Output is correct |
33 |
Correct |
103 ms |
2100 KB |
Output is correct |
34 |
Correct |
153 ms |
5892 KB |
Output is correct |
35 |
Correct |
118 ms |
4756 KB |
Output is correct |
36 |
Correct |
90 ms |
2360 KB |
Output is correct |
37 |
Correct |
93 ms |
2244 KB |
Output is correct |
38 |
Correct |
170 ms |
5912 KB |
Output is correct |
39 |
Correct |
105 ms |
5812 KB |
Output is correct |
40 |
Correct |
127 ms |
4412 KB |
Output is correct |
41 |
Correct |
195 ms |
5964 KB |
Output is correct |
42 |
Correct |
45 ms |
6104 KB |
Output is correct |
43 |
Correct |
321 ms |
1128 KB |
Output is correct |
44 |
Correct |
383 ms |
1152 KB |
Output is correct |
45 |
Correct |
117 ms |
1228 KB |
Output is correct |
46 |
Correct |
100 ms |
2180 KB |
Output is correct |
47 |
Correct |
137 ms |
2388 KB |
Output is correct |
48 |
Correct |
112 ms |
2296 KB |
Output is correct |
49 |
Correct |
120 ms |
2388 KB |
Output is correct |
50 |
Correct |
107 ms |
2276 KB |
Output is correct |
51 |
Correct |
119 ms |
2408 KB |
Output is correct |
52 |
Correct |
108 ms |
2212 KB |
Output is correct |
53 |
Correct |
118 ms |
2424 KB |
Output is correct |
54 |
Correct |
101 ms |
2220 KB |
Output is correct |
55 |
Correct |
257 ms |
2356 KB |
Output is correct |
56 |
Correct |
260 ms |
2348 KB |
Output is correct |
57 |
Correct |
276 ms |
2372 KB |
Output is correct |
58 |
Correct |
230 ms |
2304 KB |
Output is correct |
59 |
Correct |
260 ms |
2340 KB |
Output is correct |
60 |
Correct |
268 ms |
2464 KB |
Output is correct |
61 |
Correct |
252 ms |
2356 KB |
Output is correct |
62 |
Correct |
263 ms |
2408 KB |
Output is correct |
63 |
Correct |
271 ms |
2476 KB |
Output is correct |
64 |
Correct |
298 ms |
2432 KB |
Output is correct |
65 |
Correct |
254 ms |
2544 KB |
Output is correct |
66 |
Correct |
265 ms |
2380 KB |
Output is correct |
67 |
Correct |
242 ms |
2328 KB |
Output is correct |
68 |
Correct |
268 ms |
2360 KB |
Output is correct |
69 |
Correct |
1679 ms |
26212 KB |
Output is correct |
70 |
Correct |
1720 ms |
30816 KB |
Output is correct |
71 |
Correct |
194 ms |
3844 KB |
Output is correct |
72 |
Correct |
208 ms |
3728 KB |
Output is correct |
73 |
Correct |
193 ms |
3772 KB |
Output is correct |
74 |
Correct |
279 ms |
13052 KB |
Output is correct |
75 |
Correct |
189 ms |
3740 KB |
Output is correct |
76 |
Correct |
326 ms |
15376 KB |
Output is correct |
77 |
Correct |
285 ms |
13020 KB |
Output is correct |
78 |
Correct |
188 ms |
3760 KB |
Output is correct |
79 |
Correct |
195 ms |
3784 KB |
Output is correct |
80 |
Correct |
1035 ms |
22800 KB |
Output is correct |
81 |
Correct |
493 ms |
4700 KB |
Output is correct |
82 |
Correct |
1306 ms |
31128 KB |
Output is correct |
83 |
Correct |
1253 ms |
29316 KB |
Output is correct |
84 |
Correct |
487 ms |
4532 KB |
Output is correct |
85 |
Correct |
486 ms |
4672 KB |
Output is correct |
86 |
Correct |
1197 ms |
24152 KB |
Output is correct |
87 |
Correct |
1319 ms |
31016 KB |
Output is correct |
88 |
Correct |
561 ms |
4556 KB |
Output is correct |
89 |
Correct |
1136 ms |
27508 KB |
Output is correct |
90 |
Correct |
1233 ms |
31120 KB |
Output is correct |
91 |
Correct |
561 ms |
4544 KB |
Output is correct |
92 |
Correct |
1054 ms |
23720 KB |
Output is correct |
93 |
Correct |
478 ms |
4668 KB |
Output is correct |
94 |
Correct |
471 ms |
4592 KB |
Output is correct |
95 |
Correct |
482 ms |
4648 KB |
Output is correct |
96 |
Correct |
185 ms |
8224 KB |
Output is correct |
97 |
Correct |
760 ms |
31028 KB |
Output is correct |
98 |
Correct |
930 ms |
21564 KB |
Output is correct |
99 |
Correct |
1930 ms |
31384 KB |
Output is correct |
100 |
Correct |
528 ms |
30316 KB |
Output is correct |