#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll mod=1e9+7,hs1=31,hs2=101;
pii s[1<<19];
ll lz[1<<19],pow1[200005],pow2[200005],sum1[200005],sum2[200005];
int n;
string sa,sb,sc;
map<pii,bool> have;
void push(int l, int r, int idx) {
if (lz[idx]) {
s[idx].first=(lz[idx]*sum1[r-l+1]*pow1[l])%mod;
s[idx].second=(lz[idx]*sum2[r-l+1]*pow2[l])%mod;
if (l!=r) {
lz[2*idx]=lz[idx];
lz[2*idx+1]=lz[idx];
}
lz[idx]=0;
}
}
void update(int l, int r, int idx, int x, int y, int val) {
push(l,r,idx);
if (x>r || y<l) return;
if (x<=l && r<=y) {
lz[idx]=val;
push(l,r,idx);
} else {
int mid=(l+r)/2;
update(l,mid,2*idx,x,y,val);
update(mid+1,r,2*idx+1,x,y,val);
s[idx].first=(s[2*idx].first+s[2*idx+1].first)%mod;
s[idx].second=(s[2*idx].second+s[2*idx+1].second)%mod;
}
}
void check() {
push(0,n-1,1);
if (have[s[1]]) cout<<"Yes\n";
else cout<<"No\n";
}
string merge(string a, string b) {
string res="";
for (int i=0; i<n; ++i) {
if (a[i]==b[i]) res+=a[i];
else {
map<char,bool> have;
have[a[i]]=true;
have[b[i]]=true;
if (!have['J']) res+='J';
if (!have['O']) res+='O';
if (!have['I']) res+='I';
}
}
return res;
}
pii to_hash(string a) {
ll res1=0,res2=0;
for (int i=0; i<n; ++i) {
if (a[i]=='J') {
res1=(res1+pow1[i])%mod;
res2=(res2+pow2[i])%mod;
} else if (a[i]=='O') {
res1=(res1+2*pow1[i])%mod;
res2=(res2+2*pow2[i])%mod;
} else {
res1=(res1+3*pow1[i])%mod;
res2=(res2+3*pow2[i])%mod;
}
}
return pii(res1,res2);
}
void f(vector<string> v) {
string res=v[0];
for (int i=1; i<v.size(); ++i) res=merge(res,v[i]);
have[to_hash(res)]=true;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
pow1[0]=1; sum1[1]=1;
pow2[0]=1; sum2[1]=1;
for (int i=1; i<=200003; ++i) pow1[i]=(pow1[i-1]*hs1)%mod, pow2[i]=(pow2[i-1]*hs2)%mod;
for (int i=2; i<=200003; ++i) sum1[i]=(sum1[i-1]+pow1[i-1])%mod, sum2[i]=(sum2[i-1]+pow2[i-1])%mod;
cin>>n>>sa>>sb>>sc;
f({sa}); f({sb}); f({sc});
f({sa,sb}); f({sb,sc}); f({sc,sa});
f({sa,sb,sc}); f({sb,sc,sa}); f({sc,sa,sb});
int m; string st;
cin>>m>>st;
for (int i=0; i<n; ++i) {
if (st[i]=='J') update(0,n-1,1,i,i,1);
else if (st[i]=='O') update(0,n-1,1,i,i,2);
else update(0,n-1,1,i,i,3);
}
check();
while (m--) {
int l,r; char c;
cin>>l>>r>>c;
--l; --r;
if (c=='J') update(0,n-1,1,l,r,1);
else if (c=='O') update(0,n-1,1,l,r,2);
else update(0,n-1,1,l,r,3);
check();
}
}
Compilation message
Main.cpp: In function 'void f(std::vector<std::__cxx11::basic_string<char> >)':
Main.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for (int i=1; i<v.size(); ++i) res=merge(res,v[i]);
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
17932 KB |
Output is correct |
2 |
Correct |
132 ms |
18892 KB |
Output is correct |
3 |
Correct |
111 ms |
12156 KB |
Output is correct |
4 |
Correct |
138 ms |
18884 KB |
Output is correct |
5 |
Correct |
133 ms |
18884 KB |
Output is correct |
6 |
Correct |
120 ms |
17996 KB |
Output is correct |
7 |
Correct |
125 ms |
18300 KB |
Output is correct |
8 |
Correct |
144 ms |
19228 KB |
Output is correct |
9 |
Correct |
122 ms |
18788 KB |
Output is correct |
10 |
Correct |
134 ms |
20232 KB |
Output is correct |
11 |
Correct |
136 ms |
19476 KB |
Output is correct |
12 |
Correct |
148 ms |
20276 KB |
Output is correct |
13 |
Correct |
127 ms |
19408 KB |
Output is correct |
14 |
Correct |
139 ms |
20320 KB |
Output is correct |
15 |
Correct |
133 ms |
19536 KB |
Output is correct |
16 |
Correct |
140 ms |
20268 KB |
Output is correct |
17 |
Correct |
168 ms |
19508 KB |
Output is correct |
18 |
Correct |
93 ms |
10492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
17932 KB |
Output is correct |
2 |
Correct |
132 ms |
18892 KB |
Output is correct |
3 |
Correct |
111 ms |
12156 KB |
Output is correct |
4 |
Correct |
138 ms |
18884 KB |
Output is correct |
5 |
Correct |
133 ms |
18884 KB |
Output is correct |
6 |
Correct |
120 ms |
17996 KB |
Output is correct |
7 |
Correct |
125 ms |
18300 KB |
Output is correct |
8 |
Correct |
144 ms |
19228 KB |
Output is correct |
9 |
Correct |
122 ms |
18788 KB |
Output is correct |
10 |
Correct |
134 ms |
20232 KB |
Output is correct |
11 |
Correct |
136 ms |
19476 KB |
Output is correct |
12 |
Correct |
148 ms |
20276 KB |
Output is correct |
13 |
Correct |
127 ms |
19408 KB |
Output is correct |
14 |
Correct |
139 ms |
20320 KB |
Output is correct |
15 |
Correct |
133 ms |
19536 KB |
Output is correct |
16 |
Correct |
140 ms |
20268 KB |
Output is correct |
17 |
Correct |
168 ms |
19508 KB |
Output is correct |
18 |
Correct |
93 ms |
10492 KB |
Output is correct |
19 |
Correct |
450 ms |
33756 KB |
Output is correct |
20 |
Correct |
399 ms |
33552 KB |
Output is correct |
21 |
Correct |
323 ms |
35200 KB |
Output is correct |
22 |
Correct |
307 ms |
32868 KB |
Output is correct |
23 |
Correct |
193 ms |
22836 KB |
Output is correct |
24 |
Correct |
171 ms |
21528 KB |
Output is correct |
25 |
Correct |
339 ms |
36092 KB |
Output is correct |
26 |
Correct |
344 ms |
34172 KB |
Output is correct |
27 |
Correct |
357 ms |
36444 KB |
Output is correct |
28 |
Correct |
363 ms |
34044 KB |
Output is correct |
29 |
Correct |
412 ms |
36128 KB |
Output is correct |
30 |
Correct |
191 ms |
22728 KB |
Output is correct |
31 |
Correct |
476 ms |
36372 KB |
Output is correct |
32 |
Correct |
391 ms |
33712 KB |
Output is correct |
33 |
Correct |
172 ms |
21372 KB |
Output is correct |
34 |
Correct |
361 ms |
34168 KB |
Output is correct |
35 |
Correct |
302 ms |
33652 KB |
Output is correct |
36 |
Correct |
193 ms |
21584 KB |
Output is correct |
37 |
Correct |
170 ms |
21580 KB |
Output is correct |
38 |
Correct |
308 ms |
30804 KB |
Output is correct |
39 |
Correct |
227 ms |
29396 KB |
Output is correct |
40 |
Correct |
297 ms |
27780 KB |
Output is correct |
41 |
Correct |
349 ms |
25456 KB |
Output is correct |
42 |
Correct |
107 ms |
23684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
17932 KB |
Output is correct |
2 |
Correct |
132 ms |
18892 KB |
Output is correct |
3 |
Correct |
111 ms |
12156 KB |
Output is correct |
4 |
Correct |
138 ms |
18884 KB |
Output is correct |
5 |
Correct |
133 ms |
18884 KB |
Output is correct |
6 |
Correct |
120 ms |
17996 KB |
Output is correct |
7 |
Correct |
125 ms |
18300 KB |
Output is correct |
8 |
Correct |
144 ms |
19228 KB |
Output is correct |
9 |
Correct |
122 ms |
18788 KB |
Output is correct |
10 |
Correct |
134 ms |
20232 KB |
Output is correct |
11 |
Correct |
136 ms |
19476 KB |
Output is correct |
12 |
Correct |
148 ms |
20276 KB |
Output is correct |
13 |
Correct |
127 ms |
19408 KB |
Output is correct |
14 |
Correct |
139 ms |
20320 KB |
Output is correct |
15 |
Correct |
133 ms |
19536 KB |
Output is correct |
16 |
Correct |
140 ms |
20268 KB |
Output is correct |
17 |
Correct |
168 ms |
19508 KB |
Output is correct |
18 |
Correct |
93 ms |
10492 KB |
Output is correct |
19 |
Correct |
124 ms |
18316 KB |
Output is correct |
20 |
Correct |
108 ms |
12232 KB |
Output is correct |
21 |
Correct |
124 ms |
19664 KB |
Output is correct |
22 |
Correct |
107 ms |
17532 KB |
Output is correct |
23 |
Correct |
150 ms |
19680 KB |
Output is correct |
24 |
Correct |
125 ms |
18588 KB |
Output is correct |
25 |
Correct |
130 ms |
19536 KB |
Output is correct |
26 |
Correct |
158 ms |
18168 KB |
Output is correct |
27 |
Correct |
149 ms |
19660 KB |
Output is correct |
28 |
Correct |
135 ms |
18500 KB |
Output is correct |
29 |
Correct |
134 ms |
19012 KB |
Output is correct |
30 |
Correct |
107 ms |
17876 KB |
Output is correct |
31 |
Correct |
128 ms |
19916 KB |
Output is correct |
32 |
Correct |
125 ms |
19740 KB |
Output is correct |
33 |
Correct |
136 ms |
19212 KB |
Output is correct |
34 |
Correct |
148 ms |
18120 KB |
Output is correct |
35 |
Correct |
132 ms |
20204 KB |
Output is correct |
36 |
Correct |
130 ms |
19532 KB |
Output is correct |
37 |
Correct |
148 ms |
20212 KB |
Output is correct |
38 |
Correct |
124 ms |
19448 KB |
Output is correct |
39 |
Correct |
165 ms |
20276 KB |
Output is correct |
40 |
Correct |
125 ms |
19452 KB |
Output is correct |
41 |
Correct |
129 ms |
20268 KB |
Output is correct |
42 |
Correct |
126 ms |
19424 KB |
Output is correct |
43 |
Correct |
121 ms |
18716 KB |
Output is correct |
44 |
Correct |
133 ms |
19156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
17932 KB |
Output is correct |
2 |
Correct |
132 ms |
18892 KB |
Output is correct |
3 |
Correct |
111 ms |
12156 KB |
Output is correct |
4 |
Correct |
138 ms |
18884 KB |
Output is correct |
5 |
Correct |
133 ms |
18884 KB |
Output is correct |
6 |
Correct |
120 ms |
17996 KB |
Output is correct |
7 |
Correct |
125 ms |
18300 KB |
Output is correct |
8 |
Correct |
144 ms |
19228 KB |
Output is correct |
9 |
Correct |
122 ms |
18788 KB |
Output is correct |
10 |
Correct |
134 ms |
20232 KB |
Output is correct |
11 |
Correct |
136 ms |
19476 KB |
Output is correct |
12 |
Correct |
148 ms |
20276 KB |
Output is correct |
13 |
Correct |
127 ms |
19408 KB |
Output is correct |
14 |
Correct |
139 ms |
20320 KB |
Output is correct |
15 |
Correct |
133 ms |
19536 KB |
Output is correct |
16 |
Correct |
140 ms |
20268 KB |
Output is correct |
17 |
Correct |
168 ms |
19508 KB |
Output is correct |
18 |
Correct |
93 ms |
10492 KB |
Output is correct |
19 |
Correct |
450 ms |
33756 KB |
Output is correct |
20 |
Correct |
399 ms |
33552 KB |
Output is correct |
21 |
Correct |
323 ms |
35200 KB |
Output is correct |
22 |
Correct |
307 ms |
32868 KB |
Output is correct |
23 |
Correct |
193 ms |
22836 KB |
Output is correct |
24 |
Correct |
171 ms |
21528 KB |
Output is correct |
25 |
Correct |
339 ms |
36092 KB |
Output is correct |
26 |
Correct |
344 ms |
34172 KB |
Output is correct |
27 |
Correct |
357 ms |
36444 KB |
Output is correct |
28 |
Correct |
363 ms |
34044 KB |
Output is correct |
29 |
Correct |
412 ms |
36128 KB |
Output is correct |
30 |
Correct |
191 ms |
22728 KB |
Output is correct |
31 |
Correct |
476 ms |
36372 KB |
Output is correct |
32 |
Correct |
391 ms |
33712 KB |
Output is correct |
33 |
Correct |
172 ms |
21372 KB |
Output is correct |
34 |
Correct |
361 ms |
34168 KB |
Output is correct |
35 |
Correct |
302 ms |
33652 KB |
Output is correct |
36 |
Correct |
193 ms |
21584 KB |
Output is correct |
37 |
Correct |
170 ms |
21580 KB |
Output is correct |
38 |
Correct |
308 ms |
30804 KB |
Output is correct |
39 |
Correct |
227 ms |
29396 KB |
Output is correct |
40 |
Correct |
297 ms |
27780 KB |
Output is correct |
41 |
Correct |
349 ms |
25456 KB |
Output is correct |
42 |
Correct |
107 ms |
23684 KB |
Output is correct |
43 |
Correct |
124 ms |
18316 KB |
Output is correct |
44 |
Correct |
108 ms |
12232 KB |
Output is correct |
45 |
Correct |
124 ms |
19664 KB |
Output is correct |
46 |
Correct |
107 ms |
17532 KB |
Output is correct |
47 |
Correct |
150 ms |
19680 KB |
Output is correct |
48 |
Correct |
125 ms |
18588 KB |
Output is correct |
49 |
Correct |
130 ms |
19536 KB |
Output is correct |
50 |
Correct |
158 ms |
18168 KB |
Output is correct |
51 |
Correct |
149 ms |
19660 KB |
Output is correct |
52 |
Correct |
135 ms |
18500 KB |
Output is correct |
53 |
Correct |
134 ms |
19012 KB |
Output is correct |
54 |
Correct |
107 ms |
17876 KB |
Output is correct |
55 |
Correct |
128 ms |
19916 KB |
Output is correct |
56 |
Correct |
125 ms |
19740 KB |
Output is correct |
57 |
Correct |
136 ms |
19212 KB |
Output is correct |
58 |
Correct |
148 ms |
18120 KB |
Output is correct |
59 |
Correct |
132 ms |
20204 KB |
Output is correct |
60 |
Correct |
130 ms |
19532 KB |
Output is correct |
61 |
Correct |
148 ms |
20212 KB |
Output is correct |
62 |
Correct |
124 ms |
19448 KB |
Output is correct |
63 |
Correct |
165 ms |
20276 KB |
Output is correct |
64 |
Correct |
125 ms |
19452 KB |
Output is correct |
65 |
Correct |
129 ms |
20268 KB |
Output is correct |
66 |
Correct |
126 ms |
19424 KB |
Output is correct |
67 |
Correct |
121 ms |
18716 KB |
Output is correct |
68 |
Correct |
133 ms |
19156 KB |
Output is correct |
69 |
Correct |
511 ms |
32184 KB |
Output is correct |
70 |
Correct |
540 ms |
33644 KB |
Output is correct |
71 |
Correct |
219 ms |
21568 KB |
Output is correct |
72 |
Correct |
183 ms |
21580 KB |
Output is correct |
73 |
Correct |
232 ms |
21580 KB |
Output is correct |
74 |
Correct |
386 ms |
34180 KB |
Output is correct |
75 |
Correct |
194 ms |
22756 KB |
Output is correct |
76 |
Correct |
435 ms |
36012 KB |
Output is correct |
77 |
Correct |
379 ms |
33064 KB |
Output is correct |
78 |
Correct |
195 ms |
21608 KB |
Output is correct |
79 |
Correct |
185 ms |
21608 KB |
Output is correct |
80 |
Correct |
469 ms |
33928 KB |
Output is correct |
81 |
Correct |
196 ms |
22748 KB |
Output is correct |
82 |
Correct |
507 ms |
35992 KB |
Output is correct |
83 |
Correct |
440 ms |
33440 KB |
Output is correct |
84 |
Correct |
182 ms |
21452 KB |
Output is correct |
85 |
Correct |
192 ms |
21632 KB |
Output is correct |
86 |
Correct |
415 ms |
32664 KB |
Output is correct |
87 |
Correct |
464 ms |
34016 KB |
Output is correct |
88 |
Correct |
186 ms |
20928 KB |
Output is correct |
89 |
Correct |
431 ms |
33268 KB |
Output is correct |
90 |
Correct |
517 ms |
34332 KB |
Output is correct |
91 |
Correct |
224 ms |
21048 KB |
Output is correct |
92 |
Correct |
394 ms |
33588 KB |
Output is correct |
93 |
Correct |
216 ms |
21708 KB |
Output is correct |
94 |
Correct |
194 ms |
21576 KB |
Output is correct |
95 |
Correct |
202 ms |
21548 KB |
Output is correct |
96 |
Correct |
346 ms |
30872 KB |
Output is correct |
97 |
Correct |
254 ms |
30752 KB |
Output is correct |
98 |
Correct |
395 ms |
27684 KB |
Output is correct |
99 |
Correct |
483 ms |
24824 KB |
Output is correct |
100 |
Correct |
226 ms |
23040 KB |
Output is correct |