#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define all(x) x.begin() , x.end()
#define sze(x) (int)(x.size())
typedef long long ll;
typedef pair<ll , ll> pll;
const ll maxn = 2e5 + 16 , inf = 2e16;
set<vector<int>> s;
vector<int> operator+ (vector<int> a , vector<int> b){
vector<int> res(27);
for(int i = 0 ; i < 27 ; i++){
if(a[i] == b[i]){
res[i] = a[i];
} else {
res[i] = 3 - a[i] - b[i];
}
}
return res;
}
struct segtree {
int sz = 1;
vector<int> val , laz;
void init(int n){
while(sz < n) sz <<= 1;
val.assign(sz << 1 , 0);
laz.assign(sz << 1 , -1);
return;
}
void shift(int x , int lx , int rx){
int h = laz[x];
laz[x] = -1;
if(h == -1) return;
val[x] = h * (rx - lx);
if(rx - lx == 1) return;
int ln = (x << 1) + 1 , rn = ln + 1;
laz[ln] = laz[rn] = h;
return;
}
void set(int l , int r , int k , int x , int lx , int rx){
shift(x , lx , rx);
if(rx <= l || lx >= r) return;
if(rx <= r && lx >= l){
laz[x] = k;
shift(x , lx , rx);
return;
}
int m = (rx + lx) >> 1 , ln = (x << 1) + 1 , rn = ln + 1;
set(l , r , k , ln , lx , m); set(l , r , k , rn , m , rx);
val[x] = val[ln] + val[rn];
return;
}
void set(int l , int r , int k){
set(l , r , k , 0 , 0 , sz);
}
};
vector<int> v[27] , a[27];
int f[maxn] , lb[27][maxn];
segtree st[27][3];
bool check(){
auto it = s.begin() , et = s.end();
while(it != et){
vector<int> h = *it; ++it;
bool res = true;
for(int k = 0 ; k < 27 && res ; k++){
if(st[k][0].val[0] > 0 && h[k] != 0){
res = false;
}
if(st[k][1].val[0] > 0 && h[k] != 1){
res = false;
}
if(st[k][2].val[0] > 0 && h[k] != 2){
res = false;
}
}
if(res) return true;
}
return false;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
memset(f , 0 , sizeof(f));
vector<int> g(27);
int o = 27;
for(int t = 0 ; t < 3 ; t++){
for(int i = 0 ; i < 27 ; i++){
int h = i % o;
g[i] = h / (o / 3);
// cout<<a[i]<<' ';
}
// cout<<'\n';
o /= 3;
s.insert(g);
}
bool hm = true;
while(hm){
hm = false;
auto et = s.end();
for(auto it = s.begin() ; it != et && !hm ; ++it){
for(auto jt = it ; jt != et && !hm ; ++jt){
vector<int> res = (*it) + (*jt);
if(!s.count(res)){
s.insert(res);
hm = true;
}
}
}
}
// cout<<"---------------------------\n";
// auto it = s.begin() , et = s.end();
// while(it != et){
// vector<int> res = *it;
// for(int i = 0 ; i < 27 ; i++){
// cout<<res[i]<<' ';
// }
// cout<<'\n';
// ++it;
// }
int n;
cin>>n;
o = 9;
for(int t = 0 ; t < 3 ; t++){
for(int i = 0 ; i < n ; i++){
int h;
char c;
cin>>c;
if(c == 'J'){
h = 0;
} else if(c == 'O'){
h = 1;
} else {
h = 2;
}
f[i] += h * o;
}
o /= 3;
}
int q;
cin>>q;
for(int i = 0 ; i < n ; i++){
char c;
int h;
cin>>c;
if(c == 'J'){
h = 0;
} else if(c == 'O'){
h = 1;
} else {
h = 2;
}
a[f[i]].push_back(h);
v[f[i]].push_back(i);
}
for(int k = 0 ; k < 27 ; k++){
int vs = sze(v[k]);
lb[k][n] = vs;
for(int i = n - 1 ; ~i ; i--){
lb[k][i] = lb[k][i + 1];
lb[k][i] -= (f[i] == k);
}
}
for(int k = 0 ; k < 27 ; k++){
int vs = sze(v[k]);
st[k][0].init(vs); st[k][1].init(vs); st[k][2].init(vs);
for(int i = 0 ; i < vs ; i++){
st[k][a[k][i]].set(i , i + 1 , 1);
}
}
cout<<(check() ? "Yes\n" : "No\n");
for(int i = 0 ; i < q ; i++){
int l , r , h;
char c;
cin>>l>>r>>c; l--;
if(c == 'J'){
h = 0;
} else if(c == 'O'){
h = 1;
} else {
h = 2;
}
for(int k = 0 ; k < 27 ; k++){
if(v[k].empty()) continue;
int lk = lb[k][l] , rk = lb[k][r];
// cout<<k<<' '<<lk<<' '<<rk<<' '<<h<<' '<<Cnt[k][0]<<' '<<Cnt[k][1]<<' '<<Cnt[k][2]<<'\n';
st[k][0].set(lk , rk , h == 0); st[k][1].set(lk , rk , h == 1); st[k][2].set(lk , rk , h == 2);
}
cout<<(check() ? "Yes\n" : "No\n");
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
1764 KB |
Output is correct |
2 |
Correct |
323 ms |
1836 KB |
Output is correct |
3 |
Correct |
295 ms |
1796 KB |
Output is correct |
4 |
Correct |
266 ms |
1760 KB |
Output is correct |
5 |
Correct |
223 ms |
1804 KB |
Output is correct |
6 |
Correct |
248 ms |
1736 KB |
Output is correct |
7 |
Correct |
249 ms |
1740 KB |
Output is correct |
8 |
Correct |
246 ms |
1784 KB |
Output is correct |
9 |
Correct |
277 ms |
1864 KB |
Output is correct |
10 |
Correct |
249 ms |
1800 KB |
Output is correct |
11 |
Correct |
269 ms |
1796 KB |
Output is correct |
12 |
Correct |
268 ms |
1912 KB |
Output is correct |
13 |
Correct |
254 ms |
1824 KB |
Output is correct |
14 |
Correct |
313 ms |
1832 KB |
Output is correct |
15 |
Correct |
250 ms |
1772 KB |
Output is correct |
16 |
Correct |
264 ms |
1868 KB |
Output is correct |
17 |
Correct |
270 ms |
1768 KB |
Output is correct |
18 |
Correct |
283 ms |
1840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
1764 KB |
Output is correct |
2 |
Correct |
323 ms |
1836 KB |
Output is correct |
3 |
Correct |
295 ms |
1796 KB |
Output is correct |
4 |
Correct |
266 ms |
1760 KB |
Output is correct |
5 |
Correct |
223 ms |
1804 KB |
Output is correct |
6 |
Correct |
248 ms |
1736 KB |
Output is correct |
7 |
Correct |
249 ms |
1740 KB |
Output is correct |
8 |
Correct |
246 ms |
1784 KB |
Output is correct |
9 |
Correct |
277 ms |
1864 KB |
Output is correct |
10 |
Correct |
249 ms |
1800 KB |
Output is correct |
11 |
Correct |
269 ms |
1796 KB |
Output is correct |
12 |
Correct |
268 ms |
1912 KB |
Output is correct |
13 |
Correct |
254 ms |
1824 KB |
Output is correct |
14 |
Correct |
313 ms |
1832 KB |
Output is correct |
15 |
Correct |
250 ms |
1772 KB |
Output is correct |
16 |
Correct |
264 ms |
1868 KB |
Output is correct |
17 |
Correct |
270 ms |
1768 KB |
Output is correct |
18 |
Correct |
283 ms |
1840 KB |
Output is correct |
19 |
Correct |
1573 ms |
43200 KB |
Output is correct |
20 |
Correct |
1448 ms |
43316 KB |
Output is correct |
21 |
Correct |
866 ms |
32556 KB |
Output is correct |
22 |
Correct |
895 ms |
30320 KB |
Output is correct |
23 |
Correct |
517 ms |
3616 KB |
Output is correct |
24 |
Correct |
482 ms |
3612 KB |
Output is correct |
25 |
Correct |
982 ms |
43412 KB |
Output is correct |
26 |
Correct |
986 ms |
43116 KB |
Output is correct |
27 |
Correct |
1059 ms |
40256 KB |
Output is correct |
28 |
Correct |
1039 ms |
43292 KB |
Output is correct |
29 |
Correct |
1014 ms |
39576 KB |
Output is correct |
30 |
Correct |
542 ms |
3704 KB |
Output is correct |
31 |
Correct |
957 ms |
39924 KB |
Output is correct |
32 |
Correct |
960 ms |
32208 KB |
Output is correct |
33 |
Correct |
501 ms |
3588 KB |
Output is correct |
34 |
Correct |
1004 ms |
39984 KB |
Output is correct |
35 |
Correct |
823 ms |
28204 KB |
Output is correct |
36 |
Correct |
523 ms |
3524 KB |
Output is correct |
37 |
Correct |
512 ms |
3532 KB |
Output is correct |
38 |
Correct |
670 ms |
36988 KB |
Output is correct |
39 |
Correct |
569 ms |
43432 KB |
Output is correct |
40 |
Correct |
699 ms |
23056 KB |
Output is correct |
41 |
Correct |
736 ms |
37300 KB |
Output is correct |
42 |
Correct |
222 ms |
37172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
1764 KB |
Output is correct |
2 |
Correct |
323 ms |
1836 KB |
Output is correct |
3 |
Correct |
295 ms |
1796 KB |
Output is correct |
4 |
Correct |
266 ms |
1760 KB |
Output is correct |
5 |
Correct |
223 ms |
1804 KB |
Output is correct |
6 |
Correct |
248 ms |
1736 KB |
Output is correct |
7 |
Correct |
249 ms |
1740 KB |
Output is correct |
8 |
Correct |
246 ms |
1784 KB |
Output is correct |
9 |
Correct |
277 ms |
1864 KB |
Output is correct |
10 |
Correct |
249 ms |
1800 KB |
Output is correct |
11 |
Correct |
269 ms |
1796 KB |
Output is correct |
12 |
Correct |
268 ms |
1912 KB |
Output is correct |
13 |
Correct |
254 ms |
1824 KB |
Output is correct |
14 |
Correct |
313 ms |
1832 KB |
Output is correct |
15 |
Correct |
250 ms |
1772 KB |
Output is correct |
16 |
Correct |
264 ms |
1868 KB |
Output is correct |
17 |
Correct |
270 ms |
1768 KB |
Output is correct |
18 |
Correct |
283 ms |
1840 KB |
Output is correct |
19 |
Correct |
428 ms |
1816 KB |
Output is correct |
20 |
Correct |
410 ms |
1948 KB |
Output is correct |
21 |
Correct |
367 ms |
1860 KB |
Output is correct |
22 |
Correct |
242 ms |
1916 KB |
Output is correct |
23 |
Correct |
348 ms |
1848 KB |
Output is correct |
24 |
Correct |
303 ms |
1832 KB |
Output is correct |
25 |
Correct |
354 ms |
1840 KB |
Output is correct |
26 |
Correct |
270 ms |
1844 KB |
Output is correct |
27 |
Correct |
349 ms |
1860 KB |
Output is correct |
28 |
Correct |
324 ms |
1704 KB |
Output is correct |
29 |
Correct |
394 ms |
1824 KB |
Output is correct |
30 |
Correct |
258 ms |
1740 KB |
Output is correct |
31 |
Correct |
405 ms |
1824 KB |
Output is correct |
32 |
Correct |
387 ms |
1852 KB |
Output is correct |
33 |
Correct |
399 ms |
1988 KB |
Output is correct |
34 |
Correct |
305 ms |
1824 KB |
Output is correct |
35 |
Correct |
422 ms |
1848 KB |
Output is correct |
36 |
Correct |
365 ms |
1848 KB |
Output is correct |
37 |
Correct |
414 ms |
1832 KB |
Output is correct |
38 |
Correct |
404 ms |
1844 KB |
Output is correct |
39 |
Correct |
375 ms |
1800 KB |
Output is correct |
40 |
Correct |
413 ms |
1820 KB |
Output is correct |
41 |
Correct |
354 ms |
1796 KB |
Output is correct |
42 |
Correct |
378 ms |
1856 KB |
Output is correct |
43 |
Correct |
303 ms |
1852 KB |
Output is correct |
44 |
Correct |
408 ms |
1916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
1764 KB |
Output is correct |
2 |
Correct |
323 ms |
1836 KB |
Output is correct |
3 |
Correct |
295 ms |
1796 KB |
Output is correct |
4 |
Correct |
266 ms |
1760 KB |
Output is correct |
5 |
Correct |
223 ms |
1804 KB |
Output is correct |
6 |
Correct |
248 ms |
1736 KB |
Output is correct |
7 |
Correct |
249 ms |
1740 KB |
Output is correct |
8 |
Correct |
246 ms |
1784 KB |
Output is correct |
9 |
Correct |
277 ms |
1864 KB |
Output is correct |
10 |
Correct |
249 ms |
1800 KB |
Output is correct |
11 |
Correct |
269 ms |
1796 KB |
Output is correct |
12 |
Correct |
268 ms |
1912 KB |
Output is correct |
13 |
Correct |
254 ms |
1824 KB |
Output is correct |
14 |
Correct |
313 ms |
1832 KB |
Output is correct |
15 |
Correct |
250 ms |
1772 KB |
Output is correct |
16 |
Correct |
264 ms |
1868 KB |
Output is correct |
17 |
Correct |
270 ms |
1768 KB |
Output is correct |
18 |
Correct |
283 ms |
1840 KB |
Output is correct |
19 |
Correct |
1573 ms |
43200 KB |
Output is correct |
20 |
Correct |
1448 ms |
43316 KB |
Output is correct |
21 |
Correct |
866 ms |
32556 KB |
Output is correct |
22 |
Correct |
895 ms |
30320 KB |
Output is correct |
23 |
Correct |
517 ms |
3616 KB |
Output is correct |
24 |
Correct |
482 ms |
3612 KB |
Output is correct |
25 |
Correct |
982 ms |
43412 KB |
Output is correct |
26 |
Correct |
986 ms |
43116 KB |
Output is correct |
27 |
Correct |
1059 ms |
40256 KB |
Output is correct |
28 |
Correct |
1039 ms |
43292 KB |
Output is correct |
29 |
Correct |
1014 ms |
39576 KB |
Output is correct |
30 |
Correct |
542 ms |
3704 KB |
Output is correct |
31 |
Correct |
957 ms |
39924 KB |
Output is correct |
32 |
Correct |
960 ms |
32208 KB |
Output is correct |
33 |
Correct |
501 ms |
3588 KB |
Output is correct |
34 |
Correct |
1004 ms |
39984 KB |
Output is correct |
35 |
Correct |
823 ms |
28204 KB |
Output is correct |
36 |
Correct |
523 ms |
3524 KB |
Output is correct |
37 |
Correct |
512 ms |
3532 KB |
Output is correct |
38 |
Correct |
670 ms |
36988 KB |
Output is correct |
39 |
Correct |
569 ms |
43432 KB |
Output is correct |
40 |
Correct |
699 ms |
23056 KB |
Output is correct |
41 |
Correct |
736 ms |
37300 KB |
Output is correct |
42 |
Correct |
222 ms |
37172 KB |
Output is correct |
43 |
Correct |
428 ms |
1816 KB |
Output is correct |
44 |
Correct |
410 ms |
1948 KB |
Output is correct |
45 |
Correct |
367 ms |
1860 KB |
Output is correct |
46 |
Correct |
242 ms |
1916 KB |
Output is correct |
47 |
Correct |
348 ms |
1848 KB |
Output is correct |
48 |
Correct |
303 ms |
1832 KB |
Output is correct |
49 |
Correct |
354 ms |
1840 KB |
Output is correct |
50 |
Correct |
270 ms |
1844 KB |
Output is correct |
51 |
Correct |
349 ms |
1860 KB |
Output is correct |
52 |
Correct |
324 ms |
1704 KB |
Output is correct |
53 |
Correct |
394 ms |
1824 KB |
Output is correct |
54 |
Correct |
258 ms |
1740 KB |
Output is correct |
55 |
Correct |
405 ms |
1824 KB |
Output is correct |
56 |
Correct |
387 ms |
1852 KB |
Output is correct |
57 |
Correct |
399 ms |
1988 KB |
Output is correct |
58 |
Correct |
305 ms |
1824 KB |
Output is correct |
59 |
Correct |
422 ms |
1848 KB |
Output is correct |
60 |
Correct |
365 ms |
1848 KB |
Output is correct |
61 |
Correct |
414 ms |
1832 KB |
Output is correct |
62 |
Correct |
404 ms |
1844 KB |
Output is correct |
63 |
Correct |
375 ms |
1800 KB |
Output is correct |
64 |
Correct |
413 ms |
1820 KB |
Output is correct |
65 |
Correct |
354 ms |
1796 KB |
Output is correct |
66 |
Correct |
378 ms |
1856 KB |
Output is correct |
67 |
Correct |
303 ms |
1852 KB |
Output is correct |
68 |
Correct |
408 ms |
1916 KB |
Output is correct |
69 |
Execution timed out |
7034 ms |
31672 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |