#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 3e5 + 9;
const ll mod = 1e9 + 7;
const ll base = 31;
typedef pair<ll,ll> LL;
string s[5],p;
ll n,Q;
unordered_map<ll,ll> mp;
ll Getnum(char c){
if (c == 'J') return 0;
if (c == 'O') return 1;
return 2;
}
char Getchar(ll num){
if (num == 0) return 'J';
if (num == 1) return 'O';
return 'I';
}
void Fix(string &a){
if (a[0] != ' ') a = " " + a;
}
string Cross(string &a,string &b){
string ans;
Fix(a); Fix(b);
for (ll i = 1;i < a.size();i++){
if (a[i] == b[i]) ans += a[i];
else ans += Getchar(3 - Getnum(a[i]) - Getnum(b[i]));
}
return ans;
}
ll Hash(string &s){
ll res = 0; Fix(s);
for (ll i = 1;i < s.size();i++) res = (res*base + s[i] - 'A' + 1)%mod;
return res;
}
void BFS(){
queue<string> q;
q.push(s[1]); q.push(s[2]); q.push(s[3]);
mp[Hash(s[1])] = mp[Hash(s[2])] = mp[Hash(s[3])] = 1;
while(!q.empty()){
string t = q.front(); q.pop();
for (ll i = 1;i <= 3;i++){
string now = Cross(t,s[i]);
if (!mp[Hash(now)]) q.push(now),mp[Hash(now)] = 1;
}
}
}
ll st[4*N],lazy[4*N],pre[N],mu[N];
char c;
ll l,r;
ll cal(ll L,ll R,ll val){
ll p = (mu[n - R]*(pre[R - L])) % mod;
return (p*val) % mod;
}
void Pass(ll id,ll l,ll r){
ll mid = (l + r)/2;
ll t = lazy[id]; lazy[id] = 0;
if (!t) return;
st[id*2] = cal(l,mid,t); lazy[id*2] = t;
st[id*2 + 1] = cal(mid + 1,r,t); lazy[id*2 + 1] = t;
}
void upd(ll id,ll l,ll r,ll u,ll v,ll val){
if (v < l||r < u) return;
if (u <= l&&r <= v){
st[id] = cal(l,r,val); lazy[id] = val;
return;
}
ll mid = (l + r)/2; Pass(id,l,r);
upd(id*2,l,mid,u,v,val); upd(id*2 + 1,mid + 1,r,u,v,val);
st[id] = (st[id*2] + st[id*2 + 1])%mod;
}
ll Get(ll id,ll l,ll r,ll u,ll v){
if (v < l||r < u) return 0;
if (u <= l&&r <= v) return st[id];
ll mid = (l + r)/2; Pass(id,l,r);
return (Get(id*2,l,mid,u,v) + Get(id*2 + 1,mid + 1,r,u,v))%mod;
}
void Answer(){
ll have = Get(1,1,n,1,n);
if (mp.count(have)) cout<<"Yes\n";
else cout<<"No\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n;
cin>>s[1]>>s[2]>>s[3];
s[1] = " " + s[1]; s[2] = " " + s[2]; s[3] = " " + s[3];
mu[0] = 1; pre[0] = 1;
for (ll i = 1;i <= n;i++){
mu[i] = (mu[i - 1]*base)%mod;
pre[i] = (pre[i - 1] + mu[i])%mod;
}
BFS();
cin>>Q>>p; p = " " + p; //cout<<cal(4,4,1); return 0;
for (ll i = 1;i <= n;i++) upd(1,1,n,i,i,p[i] - 'A' + 1);
Answer();
while(Q--){
cin>>l>>r>>c;
upd(1,1,n,l,r,c - 'A' + 1); Answer();
}
}
Compilation message
Main.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
Main.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
Main.cpp: In function 'std::string Cross(std::string&, std::string&)':
Main.cpp:38:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (ll i = 1;i < a.size();i++){
| ~~^~~~~~~~~~
Main.cpp: In function 'long long int Hash(std::string&)':
Main.cpp:47:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (ll i = 1;i < s.size();i++) res = (res*base + s[i] - 'A' + 1)%mod;
| ~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
2252 KB |
Output is correct |
2 |
Correct |
95 ms |
2380 KB |
Output is correct |
3 |
Correct |
97 ms |
2244 KB |
Output is correct |
4 |
Correct |
78 ms |
2372 KB |
Output is correct |
5 |
Correct |
78 ms |
2312 KB |
Output is correct |
6 |
Correct |
87 ms |
2244 KB |
Output is correct |
7 |
Correct |
94 ms |
2324 KB |
Output is correct |
8 |
Correct |
84 ms |
2436 KB |
Output is correct |
9 |
Correct |
85 ms |
2484 KB |
Output is correct |
10 |
Correct |
84 ms |
2456 KB |
Output is correct |
11 |
Correct |
96 ms |
2368 KB |
Output is correct |
12 |
Correct |
99 ms |
2360 KB |
Output is correct |
13 |
Correct |
86 ms |
2460 KB |
Output is correct |
14 |
Correct |
83 ms |
2488 KB |
Output is correct |
15 |
Correct |
83 ms |
2388 KB |
Output is correct |
16 |
Correct |
83 ms |
2464 KB |
Output is correct |
17 |
Correct |
86 ms |
2380 KB |
Output is correct |
18 |
Correct |
92 ms |
2368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
2252 KB |
Output is correct |
2 |
Correct |
95 ms |
2380 KB |
Output is correct |
3 |
Correct |
97 ms |
2244 KB |
Output is correct |
4 |
Correct |
78 ms |
2372 KB |
Output is correct |
5 |
Correct |
78 ms |
2312 KB |
Output is correct |
6 |
Correct |
87 ms |
2244 KB |
Output is correct |
7 |
Correct |
94 ms |
2324 KB |
Output is correct |
8 |
Correct |
84 ms |
2436 KB |
Output is correct |
9 |
Correct |
85 ms |
2484 KB |
Output is correct |
10 |
Correct |
84 ms |
2456 KB |
Output is correct |
11 |
Correct |
96 ms |
2368 KB |
Output is correct |
12 |
Correct |
99 ms |
2360 KB |
Output is correct |
13 |
Correct |
86 ms |
2460 KB |
Output is correct |
14 |
Correct |
83 ms |
2488 KB |
Output is correct |
15 |
Correct |
83 ms |
2388 KB |
Output is correct |
16 |
Correct |
83 ms |
2464 KB |
Output is correct |
17 |
Correct |
86 ms |
2380 KB |
Output is correct |
18 |
Correct |
92 ms |
2368 KB |
Output is correct |
19 |
Correct |
465 ms |
17516 KB |
Output is correct |
20 |
Correct |
423 ms |
17404 KB |
Output is correct |
21 |
Correct |
300 ms |
16764 KB |
Output is correct |
22 |
Correct |
303 ms |
16172 KB |
Output is correct |
23 |
Correct |
166 ms |
4036 KB |
Output is correct |
24 |
Correct |
137 ms |
3936 KB |
Output is correct |
25 |
Correct |
337 ms |
17652 KB |
Output is correct |
26 |
Correct |
335 ms |
17512 KB |
Output is correct |
27 |
Correct |
347 ms |
17528 KB |
Output is correct |
28 |
Correct |
441 ms |
17432 KB |
Output is correct |
29 |
Correct |
325 ms |
17272 KB |
Output is correct |
30 |
Correct |
147 ms |
4076 KB |
Output is correct |
31 |
Correct |
379 ms |
17552 KB |
Output is correct |
32 |
Correct |
325 ms |
16840 KB |
Output is correct |
33 |
Correct |
140 ms |
3960 KB |
Output is correct |
34 |
Correct |
339 ms |
17508 KB |
Output is correct |
35 |
Correct |
251 ms |
15616 KB |
Output is correct |
36 |
Correct |
147 ms |
4040 KB |
Output is correct |
37 |
Correct |
144 ms |
4036 KB |
Output is correct |
38 |
Correct |
351 ms |
17280 KB |
Output is correct |
39 |
Correct |
284 ms |
17592 KB |
Output is correct |
40 |
Correct |
246 ms |
11488 KB |
Output is correct |
41 |
Correct |
574 ms |
17676 KB |
Output is correct |
42 |
Correct |
152 ms |
16912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
2252 KB |
Output is correct |
2 |
Correct |
95 ms |
2380 KB |
Output is correct |
3 |
Correct |
97 ms |
2244 KB |
Output is correct |
4 |
Correct |
78 ms |
2372 KB |
Output is correct |
5 |
Correct |
78 ms |
2312 KB |
Output is correct |
6 |
Correct |
87 ms |
2244 KB |
Output is correct |
7 |
Correct |
94 ms |
2324 KB |
Output is correct |
8 |
Correct |
84 ms |
2436 KB |
Output is correct |
9 |
Correct |
85 ms |
2484 KB |
Output is correct |
10 |
Correct |
84 ms |
2456 KB |
Output is correct |
11 |
Correct |
96 ms |
2368 KB |
Output is correct |
12 |
Correct |
99 ms |
2360 KB |
Output is correct |
13 |
Correct |
86 ms |
2460 KB |
Output is correct |
14 |
Correct |
83 ms |
2488 KB |
Output is correct |
15 |
Correct |
83 ms |
2388 KB |
Output is correct |
16 |
Correct |
83 ms |
2464 KB |
Output is correct |
17 |
Correct |
86 ms |
2380 KB |
Output is correct |
18 |
Correct |
92 ms |
2368 KB |
Output is correct |
19 |
Correct |
94 ms |
2328 KB |
Output is correct |
20 |
Correct |
102 ms |
2244 KB |
Output is correct |
21 |
Correct |
86 ms |
2408 KB |
Output is correct |
22 |
Correct |
74 ms |
2208 KB |
Output is correct |
23 |
Correct |
84 ms |
2368 KB |
Output is correct |
24 |
Correct |
80 ms |
2372 KB |
Output is correct |
25 |
Correct |
86 ms |
2500 KB |
Output is correct |
26 |
Correct |
79 ms |
2304 KB |
Output is correct |
27 |
Correct |
83 ms |
2352 KB |
Output is correct |
28 |
Correct |
78 ms |
2256 KB |
Output is correct |
29 |
Correct |
101 ms |
2436 KB |
Output is correct |
30 |
Correct |
75 ms |
2244 KB |
Output is correct |
31 |
Correct |
86 ms |
2456 KB |
Output is correct |
32 |
Correct |
92 ms |
2464 KB |
Output is correct |
33 |
Correct |
90 ms |
2372 KB |
Output is correct |
34 |
Correct |
79 ms |
2304 KB |
Output is correct |
35 |
Correct |
89 ms |
2500 KB |
Output is correct |
36 |
Correct |
96 ms |
2416 KB |
Output is correct |
37 |
Correct |
91 ms |
2412 KB |
Output is correct |
38 |
Correct |
87 ms |
2504 KB |
Output is correct |
39 |
Correct |
87 ms |
2384 KB |
Output is correct |
40 |
Correct |
106 ms |
2352 KB |
Output is correct |
41 |
Correct |
103 ms |
2352 KB |
Output is correct |
42 |
Correct |
87 ms |
2396 KB |
Output is correct |
43 |
Correct |
97 ms |
2400 KB |
Output is correct |
44 |
Correct |
106 ms |
2424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
2252 KB |
Output is correct |
2 |
Correct |
95 ms |
2380 KB |
Output is correct |
3 |
Correct |
97 ms |
2244 KB |
Output is correct |
4 |
Correct |
78 ms |
2372 KB |
Output is correct |
5 |
Correct |
78 ms |
2312 KB |
Output is correct |
6 |
Correct |
87 ms |
2244 KB |
Output is correct |
7 |
Correct |
94 ms |
2324 KB |
Output is correct |
8 |
Correct |
84 ms |
2436 KB |
Output is correct |
9 |
Correct |
85 ms |
2484 KB |
Output is correct |
10 |
Correct |
84 ms |
2456 KB |
Output is correct |
11 |
Correct |
96 ms |
2368 KB |
Output is correct |
12 |
Correct |
99 ms |
2360 KB |
Output is correct |
13 |
Correct |
86 ms |
2460 KB |
Output is correct |
14 |
Correct |
83 ms |
2488 KB |
Output is correct |
15 |
Correct |
83 ms |
2388 KB |
Output is correct |
16 |
Correct |
83 ms |
2464 KB |
Output is correct |
17 |
Correct |
86 ms |
2380 KB |
Output is correct |
18 |
Correct |
92 ms |
2368 KB |
Output is correct |
19 |
Correct |
465 ms |
17516 KB |
Output is correct |
20 |
Correct |
423 ms |
17404 KB |
Output is correct |
21 |
Correct |
300 ms |
16764 KB |
Output is correct |
22 |
Correct |
303 ms |
16172 KB |
Output is correct |
23 |
Correct |
166 ms |
4036 KB |
Output is correct |
24 |
Correct |
137 ms |
3936 KB |
Output is correct |
25 |
Correct |
337 ms |
17652 KB |
Output is correct |
26 |
Correct |
335 ms |
17512 KB |
Output is correct |
27 |
Correct |
347 ms |
17528 KB |
Output is correct |
28 |
Correct |
441 ms |
17432 KB |
Output is correct |
29 |
Correct |
325 ms |
17272 KB |
Output is correct |
30 |
Correct |
147 ms |
4076 KB |
Output is correct |
31 |
Correct |
379 ms |
17552 KB |
Output is correct |
32 |
Correct |
325 ms |
16840 KB |
Output is correct |
33 |
Correct |
140 ms |
3960 KB |
Output is correct |
34 |
Correct |
339 ms |
17508 KB |
Output is correct |
35 |
Correct |
251 ms |
15616 KB |
Output is correct |
36 |
Correct |
147 ms |
4040 KB |
Output is correct |
37 |
Correct |
144 ms |
4036 KB |
Output is correct |
38 |
Correct |
351 ms |
17280 KB |
Output is correct |
39 |
Correct |
284 ms |
17592 KB |
Output is correct |
40 |
Correct |
246 ms |
11488 KB |
Output is correct |
41 |
Correct |
574 ms |
17676 KB |
Output is correct |
42 |
Correct |
152 ms |
16912 KB |
Output is correct |
43 |
Correct |
94 ms |
2328 KB |
Output is correct |
44 |
Correct |
102 ms |
2244 KB |
Output is correct |
45 |
Correct |
86 ms |
2408 KB |
Output is correct |
46 |
Correct |
74 ms |
2208 KB |
Output is correct |
47 |
Correct |
84 ms |
2368 KB |
Output is correct |
48 |
Correct |
80 ms |
2372 KB |
Output is correct |
49 |
Correct |
86 ms |
2500 KB |
Output is correct |
50 |
Correct |
79 ms |
2304 KB |
Output is correct |
51 |
Correct |
83 ms |
2352 KB |
Output is correct |
52 |
Correct |
78 ms |
2256 KB |
Output is correct |
53 |
Correct |
101 ms |
2436 KB |
Output is correct |
54 |
Correct |
75 ms |
2244 KB |
Output is correct |
55 |
Correct |
86 ms |
2456 KB |
Output is correct |
56 |
Correct |
92 ms |
2464 KB |
Output is correct |
57 |
Correct |
90 ms |
2372 KB |
Output is correct |
58 |
Correct |
79 ms |
2304 KB |
Output is correct |
59 |
Correct |
89 ms |
2500 KB |
Output is correct |
60 |
Correct |
96 ms |
2416 KB |
Output is correct |
61 |
Correct |
91 ms |
2412 KB |
Output is correct |
62 |
Correct |
87 ms |
2504 KB |
Output is correct |
63 |
Correct |
87 ms |
2384 KB |
Output is correct |
64 |
Correct |
106 ms |
2352 KB |
Output is correct |
65 |
Correct |
103 ms |
2352 KB |
Output is correct |
66 |
Correct |
87 ms |
2396 KB |
Output is correct |
67 |
Correct |
97 ms |
2400 KB |
Output is correct |
68 |
Correct |
106 ms |
2424 KB |
Output is correct |
69 |
Correct |
494 ms |
16096 KB |
Output is correct |
70 |
Correct |
499 ms |
17208 KB |
Output is correct |
71 |
Correct |
147 ms |
3976 KB |
Output is correct |
72 |
Correct |
150 ms |
4028 KB |
Output is correct |
73 |
Correct |
136 ms |
4036 KB |
Output is correct |
74 |
Correct |
276 ms |
16232 KB |
Output is correct |
75 |
Correct |
165 ms |
3932 KB |
Output is correct |
76 |
Correct |
330 ms |
17424 KB |
Output is correct |
77 |
Correct |
351 ms |
16420 KB |
Output is correct |
78 |
Correct |
139 ms |
4080 KB |
Output is correct |
79 |
Correct |
137 ms |
3964 KB |
Output is correct |
80 |
Correct |
361 ms |
15364 KB |
Output is correct |
81 |
Correct |
149 ms |
4032 KB |
Output is correct |
82 |
Correct |
457 ms |
17288 KB |
Output is correct |
83 |
Correct |
432 ms |
16860 KB |
Output is correct |
84 |
Correct |
144 ms |
4064 KB |
Output is correct |
85 |
Correct |
150 ms |
4072 KB |
Output is correct |
86 |
Correct |
394 ms |
15688 KB |
Output is correct |
87 |
Correct |
435 ms |
17288 KB |
Output is correct |
88 |
Correct |
152 ms |
4036 KB |
Output is correct |
89 |
Correct |
376 ms |
16432 KB |
Output is correct |
90 |
Correct |
443 ms |
17316 KB |
Output is correct |
91 |
Correct |
150 ms |
3976 KB |
Output is correct |
92 |
Correct |
370 ms |
15724 KB |
Output is correct |
93 |
Correct |
143 ms |
4028 KB |
Output is correct |
94 |
Correct |
144 ms |
4020 KB |
Output is correct |
95 |
Correct |
147 ms |
4040 KB |
Output is correct |
96 |
Correct |
343 ms |
17224 KB |
Output is correct |
97 |
Correct |
297 ms |
17348 KB |
Output is correct |
98 |
Correct |
350 ms |
11632 KB |
Output is correct |
99 |
Correct |
579 ms |
17524 KB |
Output is correct |
100 |
Correct |
258 ms |
16768 KB |
Output is correct |