#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;
const int P = 101;
const int MAXN = 200000;
int add(int a, int b){ return (a+b)%MOD; }
int mul(int a, int b){ return (1LL*a*b)%MOD; }
int sub(int a, int b){ return add(a, MOD - b); }
map <int, bool> ima;
int ppow[MAXN+5];
int pref[MAXN+5];
int hsh(string s){
int tp = P;
int res = 0;
for(int i=0; i<s.size(); i++){
res = add(res, mul(tp, s[i] - '0' + 1));
tp = mul(tp, P);
}
return res;
}
string komb(const string &a, const string &b){
string res = "";
for(int i=0; i<a.size(); i++){
if(a[i] == b[i]) res += a[i];
else res += ('0' + (3 - (a[i] - '0') - (b[i] - '0')));
}
return res;
}
string poc;
struct Segment{
int val;
char lazy;
} seg[4*MAXN+5];
void init(int node, int l, int r){
seg[node].lazy = '5';
if(l == r){
seg[node].val = mul(ppow[l], poc[l-1] - '0' + 1);
return;
}
int mid = (l+r)/2;
init(node*2, l, mid);
init(node*2+1, mid+1, r);
seg[node].val = add(seg[node*2].val, seg[node*2+1].val);
}
void propagate(int node, int l, int r){
if(seg[node].lazy == '5') return;
seg[node].val = mul(sub(pref[r], pref[l-1]), seg[node].lazy - '0' + 1);
if(l == r){
seg[node].lazy = '5';
return;
}
seg[node*2].lazy = seg[node].lazy;
seg[node*2+1].lazy = seg[node].lazy;
seg[node].lazy = '5';
}
void upd(int node, int l, int r, int tl, int tr, char c){
propagate(node, l, r);
if(tl > r || l > tr) return;
if(tl <= l && r <= tr){
seg[node].lazy = c;
propagate(node, l, r);
return;
}
int mid = (l+r)/2;
upd(node*2, l, mid, tl, tr, c);
upd(node*2+1, mid+1, r, tl, tr, c);
seg[node].val = add(seg[node*2].val, seg[node*2+1].val);
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
ppow[0] = 1;
pref[0] = 1;
for(int i=1; i<=n; i++) ppow[i] = mul(ppow[i-1], P);
for(int i=1; i<=n; i++) pref[i] = add(ppow[i], pref[i-1]);
vector <string> strings;
for(int i=0; i<=2; i++){
string x;
cin >> x;
for(int i=0; i<n; i++){
if(x[i] == 'J') x[i] = '0';
else if(x[i] == 'O') x[i] = '1';
else x[i] = '2';
}
strings.push_back(x);
ima[hsh(x)] = 1;
}
for(int i=0; i<strings.size(); i++){
for(int j=0; j<i; j++){
string rs = komb(strings[i], strings[j]);
int g = hsh(rs);
if(!ima[g]){
strings.push_back(rs);
ima[g] = 1;
}
}
}
int qrs;
cin >> qrs;
cin >> poc;
for(int i=0; i<n; i++){
if(poc[i] == 'J') poc[i] = '0';
else if(poc[i] == 'O') poc[i] = '1';
else poc[i] = '2';
}
init(1, 1, n);
if(ima[seg[1].val]) cout << "Yes\n";
else cout << "No\n";
while(qrs--){
int l, r;
char c;
cin >> l >> r >> c;
if(c == 'J') c = '0';
else if(c == 'O') c = '1';
else c = '2';
upd(1, 1, n, l, r, c);
if(ima[seg[1].val]) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'int hsh(std::string)':
Main.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0; i<s.size(); i++){
| ~^~~~~~~~~
Main.cpp: In function 'std::string komb(const string&, const string&)':
Main.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i=0; i<a.size(); i++){
| ~^~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:108:19: 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]
108 | for(int i=0; i<strings.size(); i++){
| ~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
9440 KB |
Output is correct |
2 |
Correct |
183 ms |
10032 KB |
Output is correct |
3 |
Correct |
152 ms |
5060 KB |
Output is correct |
4 |
Correct |
163 ms |
9860 KB |
Output is correct |
5 |
Correct |
168 ms |
10052 KB |
Output is correct |
6 |
Correct |
163 ms |
9532 KB |
Output is correct |
7 |
Correct |
161 ms |
9640 KB |
Output is correct |
8 |
Correct |
173 ms |
10304 KB |
Output is correct |
9 |
Correct |
176 ms |
10012 KB |
Output is correct |
10 |
Correct |
182 ms |
11036 KB |
Output is correct |
11 |
Correct |
180 ms |
10520 KB |
Output is correct |
12 |
Correct |
199 ms |
11252 KB |
Output is correct |
13 |
Correct |
175 ms |
10436 KB |
Output is correct |
14 |
Correct |
180 ms |
11080 KB |
Output is correct |
15 |
Correct |
192 ms |
10616 KB |
Output is correct |
16 |
Correct |
186 ms |
11080 KB |
Output is correct |
17 |
Correct |
177 ms |
10564 KB |
Output is correct |
18 |
Correct |
125 ms |
3784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
9440 KB |
Output is correct |
2 |
Correct |
183 ms |
10032 KB |
Output is correct |
3 |
Correct |
152 ms |
5060 KB |
Output is correct |
4 |
Correct |
163 ms |
9860 KB |
Output is correct |
5 |
Correct |
168 ms |
10052 KB |
Output is correct |
6 |
Correct |
163 ms |
9532 KB |
Output is correct |
7 |
Correct |
161 ms |
9640 KB |
Output is correct |
8 |
Correct |
173 ms |
10304 KB |
Output is correct |
9 |
Correct |
176 ms |
10012 KB |
Output is correct |
10 |
Correct |
182 ms |
11036 KB |
Output is correct |
11 |
Correct |
180 ms |
10520 KB |
Output is correct |
12 |
Correct |
199 ms |
11252 KB |
Output is correct |
13 |
Correct |
175 ms |
10436 KB |
Output is correct |
14 |
Correct |
180 ms |
11080 KB |
Output is correct |
15 |
Correct |
192 ms |
10616 KB |
Output is correct |
16 |
Correct |
186 ms |
11080 KB |
Output is correct |
17 |
Correct |
177 ms |
10564 KB |
Output is correct |
18 |
Correct |
125 ms |
3784 KB |
Output is correct |
19 |
Correct |
455 ms |
18372 KB |
Output is correct |
20 |
Correct |
445 ms |
18884 KB |
Output is correct |
21 |
Correct |
330 ms |
19156 KB |
Output is correct |
22 |
Correct |
328 ms |
17432 KB |
Output is correct |
23 |
Correct |
246 ms |
12996 KB |
Output is correct |
24 |
Correct |
246 ms |
12064 KB |
Output is correct |
25 |
Correct |
360 ms |
20072 KB |
Output is correct |
26 |
Correct |
375 ms |
18632 KB |
Output is correct |
27 |
Correct |
413 ms |
20528 KB |
Output is correct |
28 |
Correct |
384 ms |
18632 KB |
Output is correct |
29 |
Correct |
399 ms |
19992 KB |
Output is correct |
30 |
Correct |
270 ms |
13012 KB |
Output is correct |
31 |
Correct |
406 ms |
20532 KB |
Output is correct |
32 |
Correct |
354 ms |
18088 KB |
Output is correct |
33 |
Correct |
252 ms |
12104 KB |
Output is correct |
34 |
Correct |
387 ms |
18844 KB |
Output is correct |
35 |
Correct |
332 ms |
17728 KB |
Output is correct |
36 |
Correct |
238 ms |
12024 KB |
Output is correct |
37 |
Correct |
234 ms |
11968 KB |
Output is correct |
38 |
Correct |
359 ms |
16680 KB |
Output is correct |
39 |
Correct |
236 ms |
16096 KB |
Output is correct |
40 |
Correct |
300 ms |
15692 KB |
Output is correct |
41 |
Correct |
354 ms |
11588 KB |
Output is correct |
42 |
Correct |
74 ms |
10884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
9440 KB |
Output is correct |
2 |
Correct |
183 ms |
10032 KB |
Output is correct |
3 |
Correct |
152 ms |
5060 KB |
Output is correct |
4 |
Correct |
163 ms |
9860 KB |
Output is correct |
5 |
Correct |
168 ms |
10052 KB |
Output is correct |
6 |
Correct |
163 ms |
9532 KB |
Output is correct |
7 |
Correct |
161 ms |
9640 KB |
Output is correct |
8 |
Correct |
173 ms |
10304 KB |
Output is correct |
9 |
Correct |
176 ms |
10012 KB |
Output is correct |
10 |
Correct |
182 ms |
11036 KB |
Output is correct |
11 |
Correct |
180 ms |
10520 KB |
Output is correct |
12 |
Correct |
199 ms |
11252 KB |
Output is correct |
13 |
Correct |
175 ms |
10436 KB |
Output is correct |
14 |
Correct |
180 ms |
11080 KB |
Output is correct |
15 |
Correct |
192 ms |
10616 KB |
Output is correct |
16 |
Correct |
186 ms |
11080 KB |
Output is correct |
17 |
Correct |
177 ms |
10564 KB |
Output is correct |
18 |
Correct |
125 ms |
3784 KB |
Output is correct |
19 |
Correct |
175 ms |
9636 KB |
Output is correct |
20 |
Correct |
157 ms |
5080 KB |
Output is correct |
21 |
Correct |
177 ms |
10556 KB |
Output is correct |
22 |
Correct |
145 ms |
9000 KB |
Output is correct |
23 |
Correct |
187 ms |
10844 KB |
Output is correct |
24 |
Correct |
167 ms |
9724 KB |
Output is correct |
25 |
Correct |
183 ms |
10564 KB |
Output is correct |
26 |
Correct |
168 ms |
9572 KB |
Output is correct |
27 |
Correct |
178 ms |
10596 KB |
Output is correct |
28 |
Correct |
158 ms |
9668 KB |
Output is correct |
29 |
Correct |
172 ms |
10116 KB |
Output is correct |
30 |
Correct |
173 ms |
9296 KB |
Output is correct |
31 |
Correct |
199 ms |
10824 KB |
Output is correct |
32 |
Correct |
181 ms |
10628 KB |
Output is correct |
33 |
Correct |
187 ms |
10328 KB |
Output is correct |
34 |
Correct |
159 ms |
9436 KB |
Output is correct |
35 |
Correct |
193 ms |
11068 KB |
Output is correct |
36 |
Correct |
201 ms |
10560 KB |
Output is correct |
37 |
Correct |
180 ms |
11156 KB |
Output is correct |
38 |
Correct |
175 ms |
10564 KB |
Output is correct |
39 |
Correct |
189 ms |
11076 KB |
Output is correct |
40 |
Correct |
175 ms |
10564 KB |
Output is correct |
41 |
Correct |
180 ms |
11040 KB |
Output is correct |
42 |
Correct |
191 ms |
10616 KB |
Output is correct |
43 |
Correct |
169 ms |
10008 KB |
Output is correct |
44 |
Correct |
172 ms |
10308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
9440 KB |
Output is correct |
2 |
Correct |
183 ms |
10032 KB |
Output is correct |
3 |
Correct |
152 ms |
5060 KB |
Output is correct |
4 |
Correct |
163 ms |
9860 KB |
Output is correct |
5 |
Correct |
168 ms |
10052 KB |
Output is correct |
6 |
Correct |
163 ms |
9532 KB |
Output is correct |
7 |
Correct |
161 ms |
9640 KB |
Output is correct |
8 |
Correct |
173 ms |
10304 KB |
Output is correct |
9 |
Correct |
176 ms |
10012 KB |
Output is correct |
10 |
Correct |
182 ms |
11036 KB |
Output is correct |
11 |
Correct |
180 ms |
10520 KB |
Output is correct |
12 |
Correct |
199 ms |
11252 KB |
Output is correct |
13 |
Correct |
175 ms |
10436 KB |
Output is correct |
14 |
Correct |
180 ms |
11080 KB |
Output is correct |
15 |
Correct |
192 ms |
10616 KB |
Output is correct |
16 |
Correct |
186 ms |
11080 KB |
Output is correct |
17 |
Correct |
177 ms |
10564 KB |
Output is correct |
18 |
Correct |
125 ms |
3784 KB |
Output is correct |
19 |
Correct |
455 ms |
18372 KB |
Output is correct |
20 |
Correct |
445 ms |
18884 KB |
Output is correct |
21 |
Correct |
330 ms |
19156 KB |
Output is correct |
22 |
Correct |
328 ms |
17432 KB |
Output is correct |
23 |
Correct |
246 ms |
12996 KB |
Output is correct |
24 |
Correct |
246 ms |
12064 KB |
Output is correct |
25 |
Correct |
360 ms |
20072 KB |
Output is correct |
26 |
Correct |
375 ms |
18632 KB |
Output is correct |
27 |
Correct |
413 ms |
20528 KB |
Output is correct |
28 |
Correct |
384 ms |
18632 KB |
Output is correct |
29 |
Correct |
399 ms |
19992 KB |
Output is correct |
30 |
Correct |
270 ms |
13012 KB |
Output is correct |
31 |
Correct |
406 ms |
20532 KB |
Output is correct |
32 |
Correct |
354 ms |
18088 KB |
Output is correct |
33 |
Correct |
252 ms |
12104 KB |
Output is correct |
34 |
Correct |
387 ms |
18844 KB |
Output is correct |
35 |
Correct |
332 ms |
17728 KB |
Output is correct |
36 |
Correct |
238 ms |
12024 KB |
Output is correct |
37 |
Correct |
234 ms |
11968 KB |
Output is correct |
38 |
Correct |
359 ms |
16680 KB |
Output is correct |
39 |
Correct |
236 ms |
16096 KB |
Output is correct |
40 |
Correct |
300 ms |
15692 KB |
Output is correct |
41 |
Correct |
354 ms |
11588 KB |
Output is correct |
42 |
Correct |
74 ms |
10884 KB |
Output is correct |
43 |
Correct |
175 ms |
9636 KB |
Output is correct |
44 |
Correct |
157 ms |
5080 KB |
Output is correct |
45 |
Correct |
177 ms |
10556 KB |
Output is correct |
46 |
Correct |
145 ms |
9000 KB |
Output is correct |
47 |
Correct |
187 ms |
10844 KB |
Output is correct |
48 |
Correct |
167 ms |
9724 KB |
Output is correct |
49 |
Correct |
183 ms |
10564 KB |
Output is correct |
50 |
Correct |
168 ms |
9572 KB |
Output is correct |
51 |
Correct |
178 ms |
10596 KB |
Output is correct |
52 |
Correct |
158 ms |
9668 KB |
Output is correct |
53 |
Correct |
172 ms |
10116 KB |
Output is correct |
54 |
Correct |
173 ms |
9296 KB |
Output is correct |
55 |
Correct |
199 ms |
10824 KB |
Output is correct |
56 |
Correct |
181 ms |
10628 KB |
Output is correct |
57 |
Correct |
187 ms |
10328 KB |
Output is correct |
58 |
Correct |
159 ms |
9436 KB |
Output is correct |
59 |
Correct |
193 ms |
11068 KB |
Output is correct |
60 |
Correct |
201 ms |
10560 KB |
Output is correct |
61 |
Correct |
180 ms |
11156 KB |
Output is correct |
62 |
Correct |
175 ms |
10564 KB |
Output is correct |
63 |
Correct |
189 ms |
11076 KB |
Output is correct |
64 |
Correct |
175 ms |
10564 KB |
Output is correct |
65 |
Correct |
180 ms |
11040 KB |
Output is correct |
66 |
Correct |
191 ms |
10616 KB |
Output is correct |
67 |
Correct |
169 ms |
10008 KB |
Output is correct |
68 |
Correct |
172 ms |
10308 KB |
Output is correct |
69 |
Correct |
544 ms |
17800 KB |
Output is correct |
70 |
Correct |
559 ms |
20060 KB |
Output is correct |
71 |
Correct |
233 ms |
12056 KB |
Output is correct |
72 |
Correct |
243 ms |
12100 KB |
Output is correct |
73 |
Correct |
240 ms |
12108 KB |
Output is correct |
74 |
Correct |
315 ms |
18388 KB |
Output is correct |
75 |
Correct |
257 ms |
13084 KB |
Output is correct |
76 |
Correct |
356 ms |
20148 KB |
Output is correct |
77 |
Correct |
335 ms |
17696 KB |
Output is correct |
78 |
Correct |
236 ms |
12100 KB |
Output is correct |
79 |
Correct |
248 ms |
12100 KB |
Output is correct |
80 |
Correct |
385 ms |
18648 KB |
Output is correct |
81 |
Correct |
254 ms |
12996 KB |
Output is correct |
82 |
Correct |
474 ms |
21392 KB |
Output is correct |
83 |
Correct |
444 ms |
19052 KB |
Output is correct |
84 |
Correct |
241 ms |
12004 KB |
Output is correct |
85 |
Correct |
244 ms |
12092 KB |
Output is correct |
86 |
Correct |
414 ms |
17924 KB |
Output is correct |
87 |
Correct |
488 ms |
19908 KB |
Output is correct |
88 |
Correct |
249 ms |
11588 KB |
Output is correct |
89 |
Correct |
406 ms |
18628 KB |
Output is correct |
90 |
Correct |
497 ms |
19972 KB |
Output is correct |
91 |
Correct |
252 ms |
11716 KB |
Output is correct |
92 |
Correct |
443 ms |
18720 KB |
Output is correct |
93 |
Correct |
249 ms |
12100 KB |
Output is correct |
94 |
Correct |
245 ms |
12076 KB |
Output is correct |
95 |
Correct |
268 ms |
12096 KB |
Output is correct |
96 |
Correct |
377 ms |
16752 KB |
Output is correct |
97 |
Correct |
334 ms |
18048 KB |
Output is correct |
98 |
Correct |
413 ms |
16420 KB |
Output is correct |
99 |
Correct |
490 ms |
12548 KB |
Output is correct |
100 |
Correct |
190 ms |
12020 KB |
Output is correct |