#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define dl double
using namespace std;
const int N = 2e5 + 7;
const long long mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int A[N];
vector<vector<int>> col;
struct seg{
int t[4 * N][3];
void build(int x, int l, int r)
{
if(l == r){
t[x][A[l]] = 1;
return;
}
int m = (l + r) / 2;
build(x + x, l, m);
build(x + x + 1, m + 1, r);
for(int i = 0; i < 3; i++){
t[x][i] = t[x + x][i] + t[x + x + 1][i];
}
}
} D[10];
int used[4 * N][20];
void go(int x)
{
for(int i = 0; i < (int)col.size(); i++){
used[x][i] = (used[x + x][i] & used[x + x + 1][i]);
}
}
void go(int x, int l, int r, int val)
{
for(int i = 0; i < (int)col.size(); i++){
if(D[i].t[x][val] == r - l + 1)used[x][i] = 1;
else used[x][i] = 0;
}
}
void build(int x, int l, int r)
{
if(l == r){
go(x, l, r, A[l]);
return;
}
int m = (l + r) / 2;
build(x + x, l, m);
build(x + x + 1, m + 1, r);
go(x);
}
int lz[4 * N];
void push(int x, int l, int r)
{
int m = (l + r) / 2;
if(lz[x] != -1){
lz[x + x] = lz[x + x + 1] = lz[x];
go(x + x, l, m, lz[x]);
go(x + x + 1, m + 1, r, lz[x]);
lz[x] = -1;
}
}
void upd(int x, int l, int r, int tl, int tr, int val)
{
if(tl > tr)return;
if(l == tl && r == tr){
go(x, l, r, val);
lz[x] = val;
return;
}
int m = (l + r) / 2;
push(x, l, r);
upd(x + x, l, m, tl, min(tr, m), val);
upd(x + x + 1, m + 1, r, max(tl, m + 1), tr, val);
go(x);
}
vector<int> get(string s)
{
vector<int> res;
for(int i = 0; i < n; i++){
if(s[i] == 'I')res.push_back(0);
else if(s[i] == 'J')res.push_back(1);
else res.push_back(2);
}
return res;
}
bool f()
{
for(int i = 0; i < (int)col.size(); i++){
if(used[1][i])return true;
}
return false;
}
void solve()
{
cin >> n;
vector<int> a(n),b(n),c(n);
set<vector<int>> s;
string st;
cin >> st;
a = get(st);
cin >> st;
b = get(st);
cin >> st;
c = get(st);
s.insert(a);
s.insert(b);
s.insert(c);
while(true){
bool f = false;
vector<int> id;
for(auto x : s){
for(auto y : s){
if(f)break;
vector<int> v;
for(int i = 0; i < n; i++){
if(x[i] == y[i]){
v.push_back(x[i]);
}else v.push_back(3 - x[i] - y[i]);
}
if(s.find(v) == s.end()){
id = v;
f = true;
}
}
}
if(!f)break;
s.insert(id);
}
assert((int)s.size() <= 10);
for(auto x : s){
col.push_back(x);
}
int G = 0;
for(auto x : col){
for(int i = 0; i < n; i++){
A[i + 1] = x[i];
}
D[G].build(1, 1, n);
G++;
}
for(int i = 0; i < 4 * N; i++)lz[i] = -1;
int q;
cin >> q;
cin >> st;
auto x = get(st);
for(int i = 0; i < n; i++){
A[i + 1] = x[i];
}
build(1, 1, n);
if(f())cout << "Yes\n";
else cout << "No\n";
while(q--){
int l,r;
char g;
cin >> l >> r >> g;
int id = -1;
if(g == 'I')id = 0;
else if(g == 'J')id = 1;
else id = 2;
upd(1, 1, n, l, r, id);
if(f())cout << "Yes\n";
else cout << "No\n";
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
4324 KB |
Output is correct |
2 |
Correct |
103 ms |
4440 KB |
Output is correct |
3 |
Correct |
122 ms |
4452 KB |
Output is correct |
4 |
Correct |
97 ms |
4404 KB |
Output is correct |
5 |
Correct |
88 ms |
4456 KB |
Output is correct |
6 |
Correct |
90 ms |
4372 KB |
Output is correct |
7 |
Correct |
103 ms |
4292 KB |
Output is correct |
8 |
Correct |
91 ms |
4308 KB |
Output is correct |
9 |
Correct |
90 ms |
4980 KB |
Output is correct |
10 |
Correct |
94 ms |
4948 KB |
Output is correct |
11 |
Correct |
88 ms |
4900 KB |
Output is correct |
12 |
Correct |
98 ms |
4936 KB |
Output is correct |
13 |
Correct |
99 ms |
4888 KB |
Output is correct |
14 |
Correct |
90 ms |
4972 KB |
Output is correct |
15 |
Correct |
104 ms |
4920 KB |
Output is correct |
16 |
Correct |
104 ms |
4952 KB |
Output is correct |
17 |
Correct |
89 ms |
4900 KB |
Output is correct |
18 |
Correct |
91 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
4324 KB |
Output is correct |
2 |
Correct |
103 ms |
4440 KB |
Output is correct |
3 |
Correct |
122 ms |
4452 KB |
Output is correct |
4 |
Correct |
97 ms |
4404 KB |
Output is correct |
5 |
Correct |
88 ms |
4456 KB |
Output is correct |
6 |
Correct |
90 ms |
4372 KB |
Output is correct |
7 |
Correct |
103 ms |
4292 KB |
Output is correct |
8 |
Correct |
91 ms |
4308 KB |
Output is correct |
9 |
Correct |
90 ms |
4980 KB |
Output is correct |
10 |
Correct |
94 ms |
4948 KB |
Output is correct |
11 |
Correct |
88 ms |
4900 KB |
Output is correct |
12 |
Correct |
98 ms |
4936 KB |
Output is correct |
13 |
Correct |
99 ms |
4888 KB |
Output is correct |
14 |
Correct |
90 ms |
4972 KB |
Output is correct |
15 |
Correct |
104 ms |
4920 KB |
Output is correct |
16 |
Correct |
104 ms |
4952 KB |
Output is correct |
17 |
Correct |
89 ms |
4900 KB |
Output is correct |
18 |
Correct |
91 ms |
4984 KB |
Output is correct |
19 |
Correct |
622 ms |
61288 KB |
Output is correct |
20 |
Correct |
435 ms |
61552 KB |
Output is correct |
21 |
Correct |
360 ms |
61020 KB |
Output is correct |
22 |
Correct |
354 ms |
60296 KB |
Output is correct |
23 |
Correct |
159 ms |
9620 KB |
Output is correct |
24 |
Correct |
161 ms |
9536 KB |
Output is correct |
25 |
Correct |
362 ms |
61556 KB |
Output is correct |
26 |
Correct |
394 ms |
61248 KB |
Output is correct |
27 |
Correct |
436 ms |
61120 KB |
Output is correct |
28 |
Correct |
427 ms |
61552 KB |
Output is correct |
29 |
Correct |
440 ms |
60804 KB |
Output is correct |
30 |
Correct |
159 ms |
9556 KB |
Output is correct |
31 |
Correct |
433 ms |
61656 KB |
Output is correct |
32 |
Correct |
408 ms |
60992 KB |
Output is correct |
33 |
Correct |
183 ms |
9628 KB |
Output is correct |
34 |
Correct |
464 ms |
61624 KB |
Output is correct |
35 |
Correct |
333 ms |
59800 KB |
Output is correct |
36 |
Correct |
166 ms |
9520 KB |
Output is correct |
37 |
Correct |
168 ms |
9688 KB |
Output is correct |
38 |
Correct |
350 ms |
61404 KB |
Output is correct |
39 |
Correct |
206 ms |
61740 KB |
Output is correct |
40 |
Correct |
315 ms |
35612 KB |
Output is correct |
41 |
Correct |
578 ms |
61836 KB |
Output is correct |
42 |
Correct |
96 ms |
61092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
4324 KB |
Output is correct |
2 |
Correct |
103 ms |
4440 KB |
Output is correct |
3 |
Correct |
122 ms |
4452 KB |
Output is correct |
4 |
Correct |
97 ms |
4404 KB |
Output is correct |
5 |
Correct |
88 ms |
4456 KB |
Output is correct |
6 |
Correct |
90 ms |
4372 KB |
Output is correct |
7 |
Correct |
103 ms |
4292 KB |
Output is correct |
8 |
Correct |
91 ms |
4308 KB |
Output is correct |
9 |
Correct |
90 ms |
4980 KB |
Output is correct |
10 |
Correct |
94 ms |
4948 KB |
Output is correct |
11 |
Correct |
88 ms |
4900 KB |
Output is correct |
12 |
Correct |
98 ms |
4936 KB |
Output is correct |
13 |
Correct |
99 ms |
4888 KB |
Output is correct |
14 |
Correct |
90 ms |
4972 KB |
Output is correct |
15 |
Correct |
104 ms |
4920 KB |
Output is correct |
16 |
Correct |
104 ms |
4952 KB |
Output is correct |
17 |
Correct |
89 ms |
4900 KB |
Output is correct |
18 |
Correct |
91 ms |
4984 KB |
Output is correct |
19 |
Correct |
136 ms |
5032 KB |
Output is correct |
20 |
Correct |
166 ms |
4984 KB |
Output is correct |
21 |
Correct |
88 ms |
5024 KB |
Output is correct |
22 |
Correct |
100 ms |
4872 KB |
Output is correct |
23 |
Correct |
93 ms |
5000 KB |
Output is correct |
24 |
Correct |
106 ms |
4944 KB |
Output is correct |
25 |
Correct |
109 ms |
4928 KB |
Output is correct |
26 |
Correct |
86 ms |
4952 KB |
Output is correct |
27 |
Correct |
89 ms |
4932 KB |
Output is correct |
28 |
Correct |
94 ms |
4928 KB |
Output is correct |
29 |
Correct |
110 ms |
4932 KB |
Output is correct |
30 |
Correct |
94 ms |
4964 KB |
Output is correct |
31 |
Correct |
118 ms |
5076 KB |
Output is correct |
32 |
Correct |
113 ms |
5060 KB |
Output is correct |
33 |
Correct |
113 ms |
5024 KB |
Output is correct |
34 |
Correct |
103 ms |
5028 KB |
Output is correct |
35 |
Correct |
123 ms |
4620 KB |
Output is correct |
36 |
Correct |
104 ms |
4972 KB |
Output is correct |
37 |
Correct |
106 ms |
5080 KB |
Output is correct |
38 |
Correct |
119 ms |
5088 KB |
Output is correct |
39 |
Correct |
106 ms |
5048 KB |
Output is correct |
40 |
Correct |
107 ms |
5092 KB |
Output is correct |
41 |
Correct |
118 ms |
5016 KB |
Output is correct |
42 |
Correct |
103 ms |
5104 KB |
Output is correct |
43 |
Correct |
113 ms |
5068 KB |
Output is correct |
44 |
Correct |
121 ms |
5188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
4324 KB |
Output is correct |
2 |
Correct |
103 ms |
4440 KB |
Output is correct |
3 |
Correct |
122 ms |
4452 KB |
Output is correct |
4 |
Correct |
97 ms |
4404 KB |
Output is correct |
5 |
Correct |
88 ms |
4456 KB |
Output is correct |
6 |
Correct |
90 ms |
4372 KB |
Output is correct |
7 |
Correct |
103 ms |
4292 KB |
Output is correct |
8 |
Correct |
91 ms |
4308 KB |
Output is correct |
9 |
Correct |
90 ms |
4980 KB |
Output is correct |
10 |
Correct |
94 ms |
4948 KB |
Output is correct |
11 |
Correct |
88 ms |
4900 KB |
Output is correct |
12 |
Correct |
98 ms |
4936 KB |
Output is correct |
13 |
Correct |
99 ms |
4888 KB |
Output is correct |
14 |
Correct |
90 ms |
4972 KB |
Output is correct |
15 |
Correct |
104 ms |
4920 KB |
Output is correct |
16 |
Correct |
104 ms |
4952 KB |
Output is correct |
17 |
Correct |
89 ms |
4900 KB |
Output is correct |
18 |
Correct |
91 ms |
4984 KB |
Output is correct |
19 |
Correct |
622 ms |
61288 KB |
Output is correct |
20 |
Correct |
435 ms |
61552 KB |
Output is correct |
21 |
Correct |
360 ms |
61020 KB |
Output is correct |
22 |
Correct |
354 ms |
60296 KB |
Output is correct |
23 |
Correct |
159 ms |
9620 KB |
Output is correct |
24 |
Correct |
161 ms |
9536 KB |
Output is correct |
25 |
Correct |
362 ms |
61556 KB |
Output is correct |
26 |
Correct |
394 ms |
61248 KB |
Output is correct |
27 |
Correct |
436 ms |
61120 KB |
Output is correct |
28 |
Correct |
427 ms |
61552 KB |
Output is correct |
29 |
Correct |
440 ms |
60804 KB |
Output is correct |
30 |
Correct |
159 ms |
9556 KB |
Output is correct |
31 |
Correct |
433 ms |
61656 KB |
Output is correct |
32 |
Correct |
408 ms |
60992 KB |
Output is correct |
33 |
Correct |
183 ms |
9628 KB |
Output is correct |
34 |
Correct |
464 ms |
61624 KB |
Output is correct |
35 |
Correct |
333 ms |
59800 KB |
Output is correct |
36 |
Correct |
166 ms |
9520 KB |
Output is correct |
37 |
Correct |
168 ms |
9688 KB |
Output is correct |
38 |
Correct |
350 ms |
61404 KB |
Output is correct |
39 |
Correct |
206 ms |
61740 KB |
Output is correct |
40 |
Correct |
315 ms |
35612 KB |
Output is correct |
41 |
Correct |
578 ms |
61836 KB |
Output is correct |
42 |
Correct |
96 ms |
61092 KB |
Output is correct |
43 |
Correct |
136 ms |
5032 KB |
Output is correct |
44 |
Correct |
166 ms |
4984 KB |
Output is correct |
45 |
Correct |
88 ms |
5024 KB |
Output is correct |
46 |
Correct |
100 ms |
4872 KB |
Output is correct |
47 |
Correct |
93 ms |
5000 KB |
Output is correct |
48 |
Correct |
106 ms |
4944 KB |
Output is correct |
49 |
Correct |
109 ms |
4928 KB |
Output is correct |
50 |
Correct |
86 ms |
4952 KB |
Output is correct |
51 |
Correct |
89 ms |
4932 KB |
Output is correct |
52 |
Correct |
94 ms |
4928 KB |
Output is correct |
53 |
Correct |
110 ms |
4932 KB |
Output is correct |
54 |
Correct |
94 ms |
4964 KB |
Output is correct |
55 |
Correct |
118 ms |
5076 KB |
Output is correct |
56 |
Correct |
113 ms |
5060 KB |
Output is correct |
57 |
Correct |
113 ms |
5024 KB |
Output is correct |
58 |
Correct |
103 ms |
5028 KB |
Output is correct |
59 |
Correct |
123 ms |
4620 KB |
Output is correct |
60 |
Correct |
104 ms |
4972 KB |
Output is correct |
61 |
Correct |
106 ms |
5080 KB |
Output is correct |
62 |
Correct |
119 ms |
5088 KB |
Output is correct |
63 |
Correct |
106 ms |
5048 KB |
Output is correct |
64 |
Correct |
107 ms |
5092 KB |
Output is correct |
65 |
Correct |
118 ms |
5016 KB |
Output is correct |
66 |
Correct |
103 ms |
5104 KB |
Output is correct |
67 |
Correct |
113 ms |
5068 KB |
Output is correct |
68 |
Correct |
121 ms |
5188 KB |
Output is correct |
69 |
Correct |
1448 ms |
118672 KB |
Output is correct |
70 |
Correct |
1284 ms |
122908 KB |
Output is correct |
71 |
Correct |
189 ms |
10524 KB |
Output is correct |
72 |
Correct |
184 ms |
10756 KB |
Output is correct |
73 |
Correct |
182 ms |
10440 KB |
Output is correct |
74 |
Correct |
438 ms |
75500 KB |
Output is correct |
75 |
Correct |
224 ms |
10228 KB |
Output is correct |
76 |
Correct |
504 ms |
77188 KB |
Output is correct |
77 |
Correct |
521 ms |
75336 KB |
Output is correct |
78 |
Correct |
210 ms |
10596 KB |
Output is correct |
79 |
Correct |
188 ms |
10448 KB |
Output is correct |
80 |
Correct |
848 ms |
117180 KB |
Output is correct |
81 |
Correct |
258 ms |
13148 KB |
Output is correct |
82 |
Correct |
994 ms |
122928 KB |
Output is correct |
83 |
Correct |
1052 ms |
121428 KB |
Output is correct |
84 |
Correct |
244 ms |
13400 KB |
Output is correct |
85 |
Correct |
378 ms |
13356 KB |
Output is correct |
86 |
Correct |
1122 ms |
118708 KB |
Output is correct |
87 |
Correct |
1272 ms |
123332 KB |
Output is correct |
88 |
Correct |
252 ms |
13128 KB |
Output is correct |
89 |
Correct |
1061 ms |
120216 KB |
Output is correct |
90 |
Correct |
1102 ms |
121748 KB |
Output is correct |
91 |
Correct |
265 ms |
12392 KB |
Output is correct |
92 |
Correct |
944 ms |
116252 KB |
Output is correct |
93 |
Correct |
255 ms |
12280 KB |
Output is correct |
94 |
Correct |
313 ms |
12776 KB |
Output is correct |
95 |
Correct |
305 ms |
12612 KB |
Output is correct |
96 |
Correct |
376 ms |
61088 KB |
Output is correct |
97 |
Correct |
537 ms |
123440 KB |
Output is correct |
98 |
Correct |
825 ms |
68460 KB |
Output is correct |
99 |
Correct |
1834 ms |
123712 KB |
Output is correct |
100 |
Correct |
472 ms |
122576 KB |
Output is correct |