//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////
int N;
V<vi>vec;
vi merge(vi a, vi b){
vi ans(N);
FOR(i,0,N){
if(a[i]==b[i]) ans[i]=a[i];
else ans[i]=3-a[i]-b[i];
}
return ans;
}
void f(){
map<vi,int>mp;
FOR(rep,0,3){
vi cur(N);
FOR(i,0,N){
char c; cin>>c;
cur[i]=2;
if(c=='J') cur[i]=0;
else if(c=='O') cur[i]=1;
}
vec.pb(cur);
mp[cur]=1;
}
while(1){
int n=sz(vec),added=0;
FOR(i,0,n) FOR(j,i+1,n){
vi cur=merge(vec[i],vec[j]);
if(!mp.count(cur)){
vec.pb(cur);
mp[cur]=1;
added=1;
}
}
if(!added) break;
}
}
#define prev whatever
vi T(MX), L(MX), R(MX), W(MX);
vi cur(MX), prev(MX);
//-----------
int check_range(int l, int r, int x){
if(cur[r]==x && l>=prev[r]) return 1;
return 0;
}
struct node{
int lazy, f;
};
node merge(node a, node b){
node c;
c.lazy=-1;
c.f=(a.f&b.f);
return c;
}
V<node> t(MX*4);
void build(int tl=0, int tr=N-1, int u=1){
if(tl==tr){
t[u]={-1,(T[tl]==cur[tl])};
return;
}
int mid=(tl+tr)/2;
build(tl,mid,u*2);
build(mid+1,tr,u*2+1);
t[u]=merge(t[u*2],t[u*2+1]);
}
void push_down(int u, int tl, int tr){
if(t[u].lazy==-1) return;
t[u*2].lazy=t[u].lazy;
t[u*2+1].lazy=t[u].lazy;
int tm=(tl+tr)/2;
t[u*2].f=check_range(tl,tm,t[u].lazy);
t[u*2+1].f=check_range(tm+1,tr,t[u].lazy);
}
void upd(int l, int r, int v, int tl=0, int tr=N-1, int u=1){
if(l>tr || r<tl) return;
if(l==tl && r==tr){
t[u]={v, check_range(l,r,v)};
return;
}
push_down(u, tl, tr);
int tm=(tl+tr)/2;
upd(l,min(r,tm),v,tl,tm,u*2);
upd(max(tm+1,l), r, v, tm+1,tr,u*2+1);
t[u]=merge(t[u*2],t[u*2+1]);
}
int check(){
return t[1].f;
}
//-------------
int main() {
boost; IO();
cin>>N;
f();
/*FOR(i,0,sz(vec)){
vi cur=vec[i];
for(int x: cur) cout << x;
cout << endl;
}*/
int Q; cin>>Q;
FOR(i,0,N){
char c; cin>>c;
T[i]=2;
if(c=='J') T[i]=0;
else if(c=='O') T[i]=1;
}
FOR(i,0,Q){
cin>>L[i]>>R[i];
L[i]--; R[i]--;
char c; cin>>c;
W[i]=2;
if(c=='J') W[i]=0;
else if(c=='O') W[i]=1;
}
vi ans(Q+1,0);
for(vi v: vec){
//upd cur
FOR(i,0,N) cur[i]=v[i];
prev[0]=0;
FOR(i,1,N){
if(cur[i]==cur[i-1]) prev[i]=prev[i-1];
else prev[i]=i;
}
//FOR(i,0,N) cout << prev[i] << ' '; cout << endl;
build();
if(check()) ans[0]=1;
FOR(i,0,Q){
upd(L[i],R[i], W[i]);
if(check()) ans[i+1]=1;
}
}
FOR(i,0,Q+1){
if(ans[i]) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
//Change your approach
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
13960 KB |
Output is correct |
2 |
Correct |
165 ms |
14240 KB |
Output is correct |
3 |
Correct |
150 ms |
14004 KB |
Output is correct |
4 |
Correct |
124 ms |
14040 KB |
Output is correct |
5 |
Correct |
122 ms |
13980 KB |
Output is correct |
6 |
Correct |
121 ms |
13972 KB |
Output is correct |
7 |
Correct |
129 ms |
14096 KB |
Output is correct |
8 |
Correct |
128 ms |
14116 KB |
Output is correct |
9 |
Correct |
133 ms |
14156 KB |
Output is correct |
10 |
Correct |
129 ms |
14196 KB |
Output is correct |
11 |
Correct |
133 ms |
14156 KB |
Output is correct |
12 |
Correct |
130 ms |
14124 KB |
Output is correct |
13 |
Correct |
136 ms |
14112 KB |
Output is correct |
14 |
Correct |
133 ms |
14136 KB |
Output is correct |
15 |
Correct |
140 ms |
14124 KB |
Output is correct |
16 |
Correct |
129 ms |
14132 KB |
Output is correct |
17 |
Correct |
136 ms |
14108 KB |
Output is correct |
18 |
Correct |
130 ms |
14036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
13960 KB |
Output is correct |
2 |
Correct |
165 ms |
14240 KB |
Output is correct |
3 |
Correct |
150 ms |
14004 KB |
Output is correct |
4 |
Correct |
124 ms |
14040 KB |
Output is correct |
5 |
Correct |
122 ms |
13980 KB |
Output is correct |
6 |
Correct |
121 ms |
13972 KB |
Output is correct |
7 |
Correct |
129 ms |
14096 KB |
Output is correct |
8 |
Correct |
128 ms |
14116 KB |
Output is correct |
9 |
Correct |
133 ms |
14156 KB |
Output is correct |
10 |
Correct |
129 ms |
14196 KB |
Output is correct |
11 |
Correct |
133 ms |
14156 KB |
Output is correct |
12 |
Correct |
130 ms |
14124 KB |
Output is correct |
13 |
Correct |
136 ms |
14112 KB |
Output is correct |
14 |
Correct |
133 ms |
14136 KB |
Output is correct |
15 |
Correct |
140 ms |
14124 KB |
Output is correct |
16 |
Correct |
129 ms |
14132 KB |
Output is correct |
17 |
Correct |
136 ms |
14108 KB |
Output is correct |
18 |
Correct |
130 ms |
14036 KB |
Output is correct |
19 |
Correct |
521 ms |
17456 KB |
Output is correct |
20 |
Correct |
507 ms |
17476 KB |
Output is correct |
21 |
Correct |
288 ms |
17244 KB |
Output is correct |
22 |
Correct |
295 ms |
16992 KB |
Output is correct |
23 |
Correct |
212 ms |
14512 KB |
Output is correct |
24 |
Correct |
214 ms |
14644 KB |
Output is correct |
25 |
Correct |
314 ms |
17468 KB |
Output is correct |
26 |
Correct |
326 ms |
17484 KB |
Output is correct |
27 |
Correct |
367 ms |
17504 KB |
Output is correct |
28 |
Correct |
380 ms |
17380 KB |
Output is correct |
29 |
Correct |
356 ms |
17508 KB |
Output is correct |
30 |
Correct |
239 ms |
14540 KB |
Output is correct |
31 |
Correct |
382 ms |
17420 KB |
Output is correct |
32 |
Correct |
400 ms |
17220 KB |
Output is correct |
33 |
Correct |
230 ms |
14532 KB |
Output is correct |
34 |
Correct |
406 ms |
17428 KB |
Output is correct |
35 |
Correct |
329 ms |
16724 KB |
Output is correct |
36 |
Correct |
238 ms |
14900 KB |
Output is correct |
37 |
Correct |
226 ms |
14856 KB |
Output is correct |
38 |
Correct |
390 ms |
17792 KB |
Output is correct |
39 |
Correct |
266 ms |
17816 KB |
Output is correct |
40 |
Correct |
326 ms |
16820 KB |
Output is correct |
41 |
Correct |
573 ms |
18020 KB |
Output is correct |
42 |
Correct |
78 ms |
18016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
13960 KB |
Output is correct |
2 |
Correct |
165 ms |
14240 KB |
Output is correct |
3 |
Correct |
150 ms |
14004 KB |
Output is correct |
4 |
Correct |
124 ms |
14040 KB |
Output is correct |
5 |
Correct |
122 ms |
13980 KB |
Output is correct |
6 |
Correct |
121 ms |
13972 KB |
Output is correct |
7 |
Correct |
129 ms |
14096 KB |
Output is correct |
8 |
Correct |
128 ms |
14116 KB |
Output is correct |
9 |
Correct |
133 ms |
14156 KB |
Output is correct |
10 |
Correct |
129 ms |
14196 KB |
Output is correct |
11 |
Correct |
133 ms |
14156 KB |
Output is correct |
12 |
Correct |
130 ms |
14124 KB |
Output is correct |
13 |
Correct |
136 ms |
14112 KB |
Output is correct |
14 |
Correct |
133 ms |
14136 KB |
Output is correct |
15 |
Correct |
140 ms |
14124 KB |
Output is correct |
16 |
Correct |
129 ms |
14132 KB |
Output is correct |
17 |
Correct |
136 ms |
14108 KB |
Output is correct |
18 |
Correct |
130 ms |
14036 KB |
Output is correct |
19 |
Correct |
438 ms |
14032 KB |
Output is correct |
20 |
Correct |
372 ms |
14044 KB |
Output is correct |
21 |
Correct |
157 ms |
14156 KB |
Output is correct |
22 |
Correct |
136 ms |
13908 KB |
Output is correct |
23 |
Correct |
160 ms |
14132 KB |
Output is correct |
24 |
Correct |
156 ms |
14288 KB |
Output is correct |
25 |
Correct |
161 ms |
14156 KB |
Output is correct |
26 |
Correct |
148 ms |
14024 KB |
Output is correct |
27 |
Correct |
129 ms |
14108 KB |
Output is correct |
28 |
Correct |
118 ms |
13904 KB |
Output is correct |
29 |
Correct |
132 ms |
14192 KB |
Output is correct |
30 |
Correct |
116 ms |
14028 KB |
Output is correct |
31 |
Correct |
304 ms |
14156 KB |
Output is correct |
32 |
Correct |
304 ms |
14220 KB |
Output is correct |
33 |
Correct |
309 ms |
14136 KB |
Output is correct |
34 |
Correct |
285 ms |
13972 KB |
Output is correct |
35 |
Correct |
305 ms |
14140 KB |
Output is correct |
36 |
Correct |
317 ms |
14156 KB |
Output is correct |
37 |
Correct |
305 ms |
14244 KB |
Output is correct |
38 |
Correct |
317 ms |
14108 KB |
Output is correct |
39 |
Correct |
303 ms |
14136 KB |
Output is correct |
40 |
Correct |
315 ms |
14132 KB |
Output is correct |
41 |
Correct |
303 ms |
14116 KB |
Output is correct |
42 |
Correct |
314 ms |
14156 KB |
Output is correct |
43 |
Correct |
290 ms |
14096 KB |
Output is correct |
44 |
Correct |
315 ms |
14184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
13960 KB |
Output is correct |
2 |
Correct |
165 ms |
14240 KB |
Output is correct |
3 |
Correct |
150 ms |
14004 KB |
Output is correct |
4 |
Correct |
124 ms |
14040 KB |
Output is correct |
5 |
Correct |
122 ms |
13980 KB |
Output is correct |
6 |
Correct |
121 ms |
13972 KB |
Output is correct |
7 |
Correct |
129 ms |
14096 KB |
Output is correct |
8 |
Correct |
128 ms |
14116 KB |
Output is correct |
9 |
Correct |
133 ms |
14156 KB |
Output is correct |
10 |
Correct |
129 ms |
14196 KB |
Output is correct |
11 |
Correct |
133 ms |
14156 KB |
Output is correct |
12 |
Correct |
130 ms |
14124 KB |
Output is correct |
13 |
Correct |
136 ms |
14112 KB |
Output is correct |
14 |
Correct |
133 ms |
14136 KB |
Output is correct |
15 |
Correct |
140 ms |
14124 KB |
Output is correct |
16 |
Correct |
129 ms |
14132 KB |
Output is correct |
17 |
Correct |
136 ms |
14108 KB |
Output is correct |
18 |
Correct |
130 ms |
14036 KB |
Output is correct |
19 |
Correct |
521 ms |
17456 KB |
Output is correct |
20 |
Correct |
507 ms |
17476 KB |
Output is correct |
21 |
Correct |
288 ms |
17244 KB |
Output is correct |
22 |
Correct |
295 ms |
16992 KB |
Output is correct |
23 |
Correct |
212 ms |
14512 KB |
Output is correct |
24 |
Correct |
214 ms |
14644 KB |
Output is correct |
25 |
Correct |
314 ms |
17468 KB |
Output is correct |
26 |
Correct |
326 ms |
17484 KB |
Output is correct |
27 |
Correct |
367 ms |
17504 KB |
Output is correct |
28 |
Correct |
380 ms |
17380 KB |
Output is correct |
29 |
Correct |
356 ms |
17508 KB |
Output is correct |
30 |
Correct |
239 ms |
14540 KB |
Output is correct |
31 |
Correct |
382 ms |
17420 KB |
Output is correct |
32 |
Correct |
400 ms |
17220 KB |
Output is correct |
33 |
Correct |
230 ms |
14532 KB |
Output is correct |
34 |
Correct |
406 ms |
17428 KB |
Output is correct |
35 |
Correct |
329 ms |
16724 KB |
Output is correct |
36 |
Correct |
238 ms |
14900 KB |
Output is correct |
37 |
Correct |
226 ms |
14856 KB |
Output is correct |
38 |
Correct |
390 ms |
17792 KB |
Output is correct |
39 |
Correct |
266 ms |
17816 KB |
Output is correct |
40 |
Correct |
326 ms |
16820 KB |
Output is correct |
41 |
Correct |
573 ms |
18020 KB |
Output is correct |
42 |
Correct |
78 ms |
18016 KB |
Output is correct |
43 |
Correct |
438 ms |
14032 KB |
Output is correct |
44 |
Correct |
372 ms |
14044 KB |
Output is correct |
45 |
Correct |
157 ms |
14156 KB |
Output is correct |
46 |
Correct |
136 ms |
13908 KB |
Output is correct |
47 |
Correct |
160 ms |
14132 KB |
Output is correct |
48 |
Correct |
156 ms |
14288 KB |
Output is correct |
49 |
Correct |
161 ms |
14156 KB |
Output is correct |
50 |
Correct |
148 ms |
14024 KB |
Output is correct |
51 |
Correct |
129 ms |
14108 KB |
Output is correct |
52 |
Correct |
118 ms |
13904 KB |
Output is correct |
53 |
Correct |
132 ms |
14192 KB |
Output is correct |
54 |
Correct |
116 ms |
14028 KB |
Output is correct |
55 |
Correct |
304 ms |
14156 KB |
Output is correct |
56 |
Correct |
304 ms |
14220 KB |
Output is correct |
57 |
Correct |
309 ms |
14136 KB |
Output is correct |
58 |
Correct |
285 ms |
13972 KB |
Output is correct |
59 |
Correct |
305 ms |
14140 KB |
Output is correct |
60 |
Correct |
317 ms |
14156 KB |
Output is correct |
61 |
Correct |
305 ms |
14244 KB |
Output is correct |
62 |
Correct |
317 ms |
14108 KB |
Output is correct |
63 |
Correct |
303 ms |
14136 KB |
Output is correct |
64 |
Correct |
315 ms |
14132 KB |
Output is correct |
65 |
Correct |
303 ms |
14116 KB |
Output is correct |
66 |
Correct |
314 ms |
14156 KB |
Output is correct |
67 |
Correct |
290 ms |
14096 KB |
Output is correct |
68 |
Correct |
315 ms |
14184 KB |
Output is correct |
69 |
Correct |
1274 ms |
26060 KB |
Output is correct |
70 |
Correct |
1457 ms |
29276 KB |
Output is correct |
71 |
Correct |
273 ms |
15124 KB |
Output is correct |
72 |
Correct |
270 ms |
15156 KB |
Output is correct |
73 |
Correct |
273 ms |
15064 KB |
Output is correct |
74 |
Correct |
292 ms |
17908 KB |
Output is correct |
75 |
Correct |
210 ms |
15096 KB |
Output is correct |
76 |
Correct |
316 ms |
18796 KB |
Output is correct |
77 |
Correct |
309 ms |
17940 KB |
Output is correct |
78 |
Correct |
214 ms |
15004 KB |
Output is correct |
79 |
Correct |
221 ms |
14976 KB |
Output is correct |
80 |
Correct |
758 ms |
24124 KB |
Output is correct |
81 |
Correct |
546 ms |
15476 KB |
Output is correct |
82 |
Correct |
888 ms |
29052 KB |
Output is correct |
83 |
Correct |
855 ms |
28004 KB |
Output is correct |
84 |
Correct |
548 ms |
15344 KB |
Output is correct |
85 |
Correct |
547 ms |
15348 KB |
Output is correct |
86 |
Correct |
965 ms |
24896 KB |
Output is correct |
87 |
Correct |
1035 ms |
28716 KB |
Output is correct |
88 |
Correct |
631 ms |
15244 KB |
Output is correct |
89 |
Correct |
894 ms |
27236 KB |
Output is correct |
90 |
Correct |
1010 ms |
28668 KB |
Output is correct |
91 |
Correct |
636 ms |
15228 KB |
Output is correct |
92 |
Correct |
743 ms |
24296 KB |
Output is correct |
93 |
Correct |
551 ms |
15212 KB |
Output is correct |
94 |
Correct |
560 ms |
15212 KB |
Output is correct |
95 |
Correct |
558 ms |
15228 KB |
Output is correct |
96 |
Correct |
423 ms |
17512 KB |
Output is correct |
97 |
Correct |
682 ms |
28612 KB |
Output is correct |
98 |
Correct |
892 ms |
23012 KB |
Output is correct |
99 |
Correct |
1760 ms |
29292 KB |
Output is correct |
100 |
Correct |
191 ms |
29192 KB |
Output is correct |