#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5 + 23;
const ll inf = 1e18;
#define F first
#define S second
#define pb push_back
#define kill(x) cout<<x<<endl, exit(0);
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lc (v << 1)
#define rc ((v<<1) |1)
ll mod =1865790559;
ll base =937;
ll pw[N];
ll J[N],O[N],I[N];
void meow() {
pw[0] = 1;
for(int i=1;i<N ; i++) {
pw[i] = (pw[i-1] * base) %mod;
J[i] = ('J' + J[i-1]*base) %mod;
O[i] = ('O' + O[i-1]*base) %mod;
I[i] = ('I' + I[i-1]*base) %mod;
}
}
int n,q;
string beg;
string a,b,c;
vector<string> strs;
vector<ll> hshs;
ll t[N<<2];
char lz[N<<2];
void build(int v=1,int tl=1,int tr = n+1) {
lz[v] = '-';
if(tr-tl == 1) {
t[v] = beg[tl];
return;
}
int mid=(tl+tr)/2;
build(lc,tl,mid);
build(rc,mid,tr);
t[v] = (t[lc] + t[rc] * pw[mid-tl]) %mod;
}
void shift(int v,int tl,int mid,int tr) {
if(lz[v] == '-') return;
if(lz[v] == 'J') {
t[lc] = J[mid-tl];
t[rc] = J[tr-mid];
}
if(lz[v] == 'O') {
t[lc] = O[mid-tl];
t[rc] = O[tr-mid];
}
if(lz[v] == 'I') {
t[lc] = I[mid-tl];
t[rc] = I[tr-mid];
}
lz[lc] = lz[rc] = lz[v];
lz[v] = '-';
}
void upd(int l,int r,char c,int v=1,int tl = 1,int tr= n+1) {
if(l > r) return;
if(l == tl && r == tr-1) {
if(c == 'J') t[v] = J[tr-tl];
if(c == 'O') t[v] = O[tr-tl];
if(c == 'I') t[v] = I[tr-tl];
lz[v]= c;
return;
}
int mid=(tl+tr)/2;
shift(v,tl,mid,tr);
upd(l,min(mid-1,r),c,lc,tl,mid);
upd(max(l,mid),r,c,rc,mid,tr);
t[v] = (t[lc] + t[rc] * pw[mid-tl]) %mod;
}
ll getHash(string s) {
ll hash = 0;
reverse(all(s));
for(char c : s) {
if(c == '#') continue;
hash = (c + hash*base) %mod;
}
return hash;
}
string cross(string one,string two) {
string ans; ans.resize(n+1);
for(int i = 0; i <= n ; i++) {
if(one[i] == two[i]) ans[i] = one[i];
else{
if('J' != one[i] && 'J' != two[i]) ans[i] = 'J';
else if('O' != one[i] && 'O' != two[i]) ans[i] = 'O';
else ans[i] = 'I';
}
}
return ans;
}
void out() {
bool ans = 0;
for(ll hsh : hshs) {
debug(t[1] ,hsh);
ans |= (t[1] == hsh);
}
cout<<(ans ? "Yes" : "No") << '\n';
}
int32_t main() {
cin.tie(nullptr)->sync_with_stdio(false);
meow();
cin>>n>>a>>b>>c; a= "#" + a; b = "#" + b; c = "#" + c;
strs.pb(a);
strs.pb(b);
strs.pb(c);
strs.pb(cross(a,b));
strs.pb(cross(a,c));
strs.pb(cross(b,c));
strs.pb(cross(cross(a,b),c));
strs.pb(cross(cross(a,c),b));
strs.pb(cross(cross(b,a),c));
strs.pb(cross(cross(b,c),a));
strs.pb(cross(cross(c,a),b));
strs.pb(cross(cross(c,b),a));
for(string s : strs) hshs.pb(getHash(s));
cin>>q;
cin>>beg; beg = "#" + beg;
build();
debug(t[1]);
out();
while(q--) {
int l,r; char c; cin>>l>>r>>c;
upd(l,r,c);
out();
}
return 0;
}
Compilation message
Main.cpp: In function 'void out()':
Main.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 69
| ^~
Main.cpp:122:3: note: in expansion of macro 'debug'
122 | debug(t[1] ,hsh);
| ^~~~~
Main.cpp: In function 'int32_t main()':
Main.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 69
| ^~
Main.cpp:148:2: note: in expansion of macro 'debug'
148 | debug(t[1]);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
9812 KB |
Output is correct |
2 |
Correct |
72 ms |
10068 KB |
Output is correct |
3 |
Correct |
81 ms |
10044 KB |
Output is correct |
4 |
Correct |
65 ms |
10068 KB |
Output is correct |
5 |
Correct |
61 ms |
10064 KB |
Output is correct |
6 |
Correct |
61 ms |
10036 KB |
Output is correct |
7 |
Correct |
66 ms |
10068 KB |
Output is correct |
8 |
Correct |
70 ms |
10056 KB |
Output is correct |
9 |
Correct |
65 ms |
10064 KB |
Output is correct |
10 |
Correct |
65 ms |
10068 KB |
Output is correct |
11 |
Correct |
67 ms |
9996 KB |
Output is correct |
12 |
Correct |
65 ms |
10028 KB |
Output is correct |
13 |
Correct |
69 ms |
10068 KB |
Output is correct |
14 |
Correct |
65 ms |
10068 KB |
Output is correct |
15 |
Correct |
66 ms |
9840 KB |
Output is correct |
16 |
Correct |
65 ms |
10068 KB |
Output is correct |
17 |
Correct |
66 ms |
10068 KB |
Output is correct |
18 |
Correct |
68 ms |
9884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
9812 KB |
Output is correct |
2 |
Correct |
72 ms |
10068 KB |
Output is correct |
3 |
Correct |
81 ms |
10044 KB |
Output is correct |
4 |
Correct |
65 ms |
10068 KB |
Output is correct |
5 |
Correct |
61 ms |
10064 KB |
Output is correct |
6 |
Correct |
61 ms |
10036 KB |
Output is correct |
7 |
Correct |
66 ms |
10068 KB |
Output is correct |
8 |
Correct |
70 ms |
10056 KB |
Output is correct |
9 |
Correct |
65 ms |
10064 KB |
Output is correct |
10 |
Correct |
65 ms |
10068 KB |
Output is correct |
11 |
Correct |
67 ms |
9996 KB |
Output is correct |
12 |
Correct |
65 ms |
10028 KB |
Output is correct |
13 |
Correct |
69 ms |
10068 KB |
Output is correct |
14 |
Correct |
65 ms |
10068 KB |
Output is correct |
15 |
Correct |
66 ms |
9840 KB |
Output is correct |
16 |
Correct |
65 ms |
10068 KB |
Output is correct |
17 |
Correct |
66 ms |
10068 KB |
Output is correct |
18 |
Correct |
68 ms |
9884 KB |
Output is correct |
19 |
Correct |
189 ms |
19372 KB |
Output is correct |
20 |
Correct |
213 ms |
21420 KB |
Output is correct |
21 |
Correct |
139 ms |
20908 KB |
Output is correct |
22 |
Correct |
136 ms |
20320 KB |
Output is correct |
23 |
Correct |
101 ms |
12628 KB |
Output is correct |
24 |
Correct |
103 ms |
12876 KB |
Output is correct |
25 |
Correct |
149 ms |
21168 KB |
Output is correct |
26 |
Correct |
149 ms |
21348 KB |
Output is correct |
27 |
Correct |
172 ms |
21380 KB |
Output is correct |
28 |
Correct |
166 ms |
21344 KB |
Output is correct |
29 |
Correct |
167 ms |
21076 KB |
Output is correct |
30 |
Correct |
115 ms |
12464 KB |
Output is correct |
31 |
Correct |
166 ms |
21208 KB |
Output is correct |
32 |
Correct |
157 ms |
20916 KB |
Output is correct |
33 |
Correct |
103 ms |
12628 KB |
Output is correct |
34 |
Correct |
164 ms |
21164 KB |
Output is correct |
35 |
Correct |
131 ms |
20032 KB |
Output is correct |
36 |
Correct |
102 ms |
12504 KB |
Output is correct |
37 |
Correct |
102 ms |
12564 KB |
Output is correct |
38 |
Correct |
180 ms |
21112 KB |
Output is correct |
39 |
Correct |
133 ms |
21168 KB |
Output is correct |
40 |
Correct |
134 ms |
17760 KB |
Output is correct |
41 |
Correct |
200 ms |
21488 KB |
Output is correct |
42 |
Correct |
63 ms |
20868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
9812 KB |
Output is correct |
2 |
Correct |
72 ms |
10068 KB |
Output is correct |
3 |
Correct |
81 ms |
10044 KB |
Output is correct |
4 |
Correct |
65 ms |
10068 KB |
Output is correct |
5 |
Correct |
61 ms |
10064 KB |
Output is correct |
6 |
Correct |
61 ms |
10036 KB |
Output is correct |
7 |
Correct |
66 ms |
10068 KB |
Output is correct |
8 |
Correct |
70 ms |
10056 KB |
Output is correct |
9 |
Correct |
65 ms |
10064 KB |
Output is correct |
10 |
Correct |
65 ms |
10068 KB |
Output is correct |
11 |
Correct |
67 ms |
9996 KB |
Output is correct |
12 |
Correct |
65 ms |
10028 KB |
Output is correct |
13 |
Correct |
69 ms |
10068 KB |
Output is correct |
14 |
Correct |
65 ms |
10068 KB |
Output is correct |
15 |
Correct |
66 ms |
9840 KB |
Output is correct |
16 |
Correct |
65 ms |
10068 KB |
Output is correct |
17 |
Correct |
66 ms |
10068 KB |
Output is correct |
18 |
Correct |
68 ms |
9884 KB |
Output is correct |
19 |
Correct |
68 ms |
9960 KB |
Output is correct |
20 |
Correct |
77 ms |
10056 KB |
Output is correct |
21 |
Correct |
66 ms |
10064 KB |
Output is correct |
22 |
Correct |
58 ms |
9812 KB |
Output is correct |
23 |
Correct |
65 ms |
10068 KB |
Output is correct |
24 |
Correct |
70 ms |
10152 KB |
Output is correct |
25 |
Correct |
66 ms |
9892 KB |
Output is correct |
26 |
Correct |
60 ms |
9812 KB |
Output is correct |
27 |
Correct |
65 ms |
10076 KB |
Output is correct |
28 |
Correct |
59 ms |
10068 KB |
Output is correct |
29 |
Correct |
65 ms |
10068 KB |
Output is correct |
30 |
Correct |
58 ms |
9992 KB |
Output is correct |
31 |
Correct |
65 ms |
10068 KB |
Output is correct |
32 |
Correct |
64 ms |
9980 KB |
Output is correct |
33 |
Correct |
69 ms |
10292 KB |
Output is correct |
34 |
Correct |
60 ms |
9904 KB |
Output is correct |
35 |
Correct |
65 ms |
10056 KB |
Output is correct |
36 |
Correct |
67 ms |
9832 KB |
Output is correct |
37 |
Correct |
71 ms |
10136 KB |
Output is correct |
38 |
Correct |
68 ms |
10064 KB |
Output is correct |
39 |
Correct |
65 ms |
10064 KB |
Output is correct |
40 |
Correct |
65 ms |
10052 KB |
Output is correct |
41 |
Correct |
69 ms |
10068 KB |
Output is correct |
42 |
Correct |
66 ms |
9848 KB |
Output is correct |
43 |
Correct |
63 ms |
10320 KB |
Output is correct |
44 |
Correct |
65 ms |
10060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
9812 KB |
Output is correct |
2 |
Correct |
72 ms |
10068 KB |
Output is correct |
3 |
Correct |
81 ms |
10044 KB |
Output is correct |
4 |
Correct |
65 ms |
10068 KB |
Output is correct |
5 |
Correct |
61 ms |
10064 KB |
Output is correct |
6 |
Correct |
61 ms |
10036 KB |
Output is correct |
7 |
Correct |
66 ms |
10068 KB |
Output is correct |
8 |
Correct |
70 ms |
10056 KB |
Output is correct |
9 |
Correct |
65 ms |
10064 KB |
Output is correct |
10 |
Correct |
65 ms |
10068 KB |
Output is correct |
11 |
Correct |
67 ms |
9996 KB |
Output is correct |
12 |
Correct |
65 ms |
10028 KB |
Output is correct |
13 |
Correct |
69 ms |
10068 KB |
Output is correct |
14 |
Correct |
65 ms |
10068 KB |
Output is correct |
15 |
Correct |
66 ms |
9840 KB |
Output is correct |
16 |
Correct |
65 ms |
10068 KB |
Output is correct |
17 |
Correct |
66 ms |
10068 KB |
Output is correct |
18 |
Correct |
68 ms |
9884 KB |
Output is correct |
19 |
Correct |
189 ms |
19372 KB |
Output is correct |
20 |
Correct |
213 ms |
21420 KB |
Output is correct |
21 |
Correct |
139 ms |
20908 KB |
Output is correct |
22 |
Correct |
136 ms |
20320 KB |
Output is correct |
23 |
Correct |
101 ms |
12628 KB |
Output is correct |
24 |
Correct |
103 ms |
12876 KB |
Output is correct |
25 |
Correct |
149 ms |
21168 KB |
Output is correct |
26 |
Correct |
149 ms |
21348 KB |
Output is correct |
27 |
Correct |
172 ms |
21380 KB |
Output is correct |
28 |
Correct |
166 ms |
21344 KB |
Output is correct |
29 |
Correct |
167 ms |
21076 KB |
Output is correct |
30 |
Correct |
115 ms |
12464 KB |
Output is correct |
31 |
Correct |
166 ms |
21208 KB |
Output is correct |
32 |
Correct |
157 ms |
20916 KB |
Output is correct |
33 |
Correct |
103 ms |
12628 KB |
Output is correct |
34 |
Correct |
164 ms |
21164 KB |
Output is correct |
35 |
Correct |
131 ms |
20032 KB |
Output is correct |
36 |
Correct |
102 ms |
12504 KB |
Output is correct |
37 |
Correct |
102 ms |
12564 KB |
Output is correct |
38 |
Correct |
180 ms |
21112 KB |
Output is correct |
39 |
Correct |
133 ms |
21168 KB |
Output is correct |
40 |
Correct |
134 ms |
17760 KB |
Output is correct |
41 |
Correct |
200 ms |
21488 KB |
Output is correct |
42 |
Correct |
63 ms |
20868 KB |
Output is correct |
43 |
Correct |
68 ms |
9960 KB |
Output is correct |
44 |
Correct |
77 ms |
10056 KB |
Output is correct |
45 |
Correct |
66 ms |
10064 KB |
Output is correct |
46 |
Correct |
58 ms |
9812 KB |
Output is correct |
47 |
Correct |
65 ms |
10068 KB |
Output is correct |
48 |
Correct |
70 ms |
10152 KB |
Output is correct |
49 |
Correct |
66 ms |
9892 KB |
Output is correct |
50 |
Correct |
60 ms |
9812 KB |
Output is correct |
51 |
Correct |
65 ms |
10076 KB |
Output is correct |
52 |
Correct |
59 ms |
10068 KB |
Output is correct |
53 |
Correct |
65 ms |
10068 KB |
Output is correct |
54 |
Correct |
58 ms |
9992 KB |
Output is correct |
55 |
Correct |
65 ms |
10068 KB |
Output is correct |
56 |
Correct |
64 ms |
9980 KB |
Output is correct |
57 |
Correct |
69 ms |
10292 KB |
Output is correct |
58 |
Correct |
60 ms |
9904 KB |
Output is correct |
59 |
Correct |
65 ms |
10056 KB |
Output is correct |
60 |
Correct |
67 ms |
9832 KB |
Output is correct |
61 |
Correct |
71 ms |
10136 KB |
Output is correct |
62 |
Correct |
68 ms |
10064 KB |
Output is correct |
63 |
Correct |
65 ms |
10064 KB |
Output is correct |
64 |
Correct |
65 ms |
10052 KB |
Output is correct |
65 |
Correct |
69 ms |
10068 KB |
Output is correct |
66 |
Correct |
66 ms |
9848 KB |
Output is correct |
67 |
Correct |
63 ms |
10320 KB |
Output is correct |
68 |
Correct |
65 ms |
10060 KB |
Output is correct |
69 |
Correct |
187 ms |
20196 KB |
Output is correct |
70 |
Correct |
228 ms |
21116 KB |
Output is correct |
71 |
Correct |
103 ms |
12544 KB |
Output is correct |
72 |
Correct |
105 ms |
12372 KB |
Output is correct |
73 |
Correct |
105 ms |
12784 KB |
Output is correct |
74 |
Correct |
145 ms |
20140 KB |
Output is correct |
75 |
Correct |
106 ms |
12468 KB |
Output is correct |
76 |
Correct |
161 ms |
20908 KB |
Output is correct |
77 |
Correct |
151 ms |
20472 KB |
Output is correct |
78 |
Correct |
103 ms |
12376 KB |
Output is correct |
79 |
Correct |
103 ms |
12368 KB |
Output is correct |
80 |
Correct |
151 ms |
19680 KB |
Output is correct |
81 |
Correct |
103 ms |
12368 KB |
Output is correct |
82 |
Correct |
170 ms |
21148 KB |
Output is correct |
83 |
Correct |
169 ms |
20836 KB |
Output is correct |
84 |
Correct |
102 ms |
12432 KB |
Output is correct |
85 |
Correct |
102 ms |
12372 KB |
Output is correct |
86 |
Correct |
157 ms |
19932 KB |
Output is correct |
87 |
Correct |
172 ms |
21164 KB |
Output is correct |
88 |
Correct |
109 ms |
12368 KB |
Output is correct |
89 |
Correct |
152 ms |
20508 KB |
Output is correct |
90 |
Correct |
166 ms |
21080 KB |
Output is correct |
91 |
Correct |
111 ms |
12496 KB |
Output is correct |
92 |
Correct |
147 ms |
19916 KB |
Output is correct |
93 |
Correct |
108 ms |
12628 KB |
Output is correct |
94 |
Correct |
103 ms |
12624 KB |
Output is correct |
95 |
Correct |
102 ms |
12564 KB |
Output is correct |
96 |
Correct |
180 ms |
20924 KB |
Output is correct |
97 |
Correct |
135 ms |
20912 KB |
Output is correct |
98 |
Correct |
149 ms |
17504 KB |
Output is correct |
99 |
Correct |
223 ms |
21164 KB |
Output is correct |
100 |
Correct |
84 ms |
20652 KB |
Output is correct |