#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
#define int long long
using namespace std;
const int base = 137;
const int modu = 1e9 + 7;
const int maxn = 3e5 + 5;
//////////
int pw[maxn],pre[maxn];
char gc(int x){
if (x == 1) return 'J';
if (x == 2) return 'O';
return 'I';
}
int gn(char x){
if (x == 'J') return 1;
if (x == 'O') return 2;
return 3;
}
struct Hash{
vector <int> pre;
void hashing(const string&s){
if (!s.size()) return;
pre.clear();
pre.push_back((ll)pw[1] * (ll)(s[0] - 96) % modu);
for (int i = 1 ; i < s.size() ; i++)
pre.push_back(((ll)pre[i - 1] + (ll)(s[i] - 96) * (ll)pw[i + 1] % modu) % modu);
for (int &t : pre)
if (t < 0) t += modu;
}
int Val(){
if (!pre.size()) return -1;
return pre.back();
}
};
void prepare_pw(int n){
for (int i = 0 ; i <= n ; i++){
pw[i] = (!i) ? 1 : (ll)pw[i - 1] * (ll)base % modu;
pre[i] = (!i) ? 1 : (ll)(pre[i - 1] + pw[i]) % modu;
}
}
set <int> s;
vector <string> S;
bool contain(int x){
if (!s.size() || *s.rbegin() < x) return 0;
int y = *s.lower_bound(x);
return (y == x);
}
string Xor(const string &a,const string &b){
string c = a;
for (int i = 0 ; i < a.size() ; i++){
int x = 6 - gn(a[i]) - gn(b[i]);
if (x % 3 == 0) x = 3;
else x %= 3;
c[i] = gc(x);
}
return c;
}
void insertion(const string &t){
Hash Hash;
Hash.hashing(t);
if (contain(Hash.Val())) return;
s.insert(Hash.Val());
S.push_back(t);
vector <string> lst;
for (const string &st : S){
string k = Xor(t,st);
Hash.hashing(k);
if (!contain(Hash.Val()))
lst.push_back(k);
}
if (lst.size())
for (const string &k : lst)
insertion(k);
}
void gen_string(int N){
for (int id = 1 ; id <= 3 ; id++){
string t;
cin >> t;
insertion(t);
}
}
////////////
struct segment_tree{
int seg[4*maxn],lazy[4*maxn];
void downlazy(int v,int l,int r){
if (!lazy[v]) return;
int sum = (pre[r] - pre[l - 1]) % modu;
seg[v] = (ll)sum * (ll)lazy[v] % modu;
if (l != r){
lazy[2*v + 1] = lazy[v];
lazy[2*v + 2] = lazy[v];
}
lazy[v] = 0;
}
void update(int l,int r,int v,int lx,int rx,int val){
downlazy(v,l,r);
if (l > rx || r < lx) return;
if (l >= lx && r <= rx){
lazy[v] = val;
downlazy(v,l,r);
return;
}
int w = (l + r)/2;
update(l,w,2*v + 1,lx,rx,val);
update(w + 1,r,2*v + 2,lx,rx,val);
seg[v] = (ll)(seg[2*v + 1] + seg[2*v + 2]) % modu;
}
int calc(){
if (seg[0] < 0) seg[0] += modu;
return seg[0];
}
} seg;
void print_ans(bool x){
if (x) cout << "Yes";
else cout << "No";
cout << "\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//freopen("crossing.inp","r",stdin);
// freopen("crossing.out","w",stdout);
int N;
cin >> N;
prepare_pw(N);
gen_string(N);
int Q;
string QR;
cin >> Q >> QR;
for (int i = 1 ; i <= N ; i++)
seg.update(1,N,0,i,i,(int)QR[i - 1] - 96);
print_ans(contain(seg.calc()));
while (Q--){
int l,r;char c;
cin >> l >> r >> c;
seg.update(1,N,0,l,r,c - 96);
print_ans(contain(seg.calc()));
}
return 0;
}
Compilation message
Main.cpp: In member function 'void Hash::hashing(const string&)':
Main.cpp:35:22: 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]
35 | for (int i = 1 ; i < s.size() ; i++)
| ~~^~~~~~~~~~
Main.cpp: In function 'std::string Xor(const string&, const string&)':
Main.cpp:64: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]
64 | for (int i = 0 ; i < a.size() ; i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
2392 KB |
Output is correct |
2 |
Correct |
83 ms |
2452 KB |
Output is correct |
3 |
Correct |
57 ms |
2368 KB |
Output is correct |
4 |
Correct |
67 ms |
2372 KB |
Output is correct |
5 |
Correct |
67 ms |
2384 KB |
Output is correct |
6 |
Correct |
48 ms |
2484 KB |
Output is correct |
7 |
Correct |
68 ms |
2444 KB |
Output is correct |
8 |
Correct |
51 ms |
2592 KB |
Output is correct |
9 |
Correct |
73 ms |
2388 KB |
Output is correct |
10 |
Correct |
52 ms |
2620 KB |
Output is correct |
11 |
Correct |
73 ms |
2388 KB |
Output is correct |
12 |
Correct |
52 ms |
2384 KB |
Output is correct |
13 |
Correct |
52 ms |
2584 KB |
Output is correct |
14 |
Correct |
53 ms |
2612 KB |
Output is correct |
15 |
Correct |
75 ms |
2404 KB |
Output is correct |
16 |
Correct |
52 ms |
2388 KB |
Output is correct |
17 |
Correct |
52 ms |
2384 KB |
Output is correct |
18 |
Correct |
53 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
2392 KB |
Output is correct |
2 |
Correct |
83 ms |
2452 KB |
Output is correct |
3 |
Correct |
57 ms |
2368 KB |
Output is correct |
4 |
Correct |
67 ms |
2372 KB |
Output is correct |
5 |
Correct |
67 ms |
2384 KB |
Output is correct |
6 |
Correct |
48 ms |
2484 KB |
Output is correct |
7 |
Correct |
68 ms |
2444 KB |
Output is correct |
8 |
Correct |
51 ms |
2592 KB |
Output is correct |
9 |
Correct |
73 ms |
2388 KB |
Output is correct |
10 |
Correct |
52 ms |
2620 KB |
Output is correct |
11 |
Correct |
73 ms |
2388 KB |
Output is correct |
12 |
Correct |
52 ms |
2384 KB |
Output is correct |
13 |
Correct |
52 ms |
2584 KB |
Output is correct |
14 |
Correct |
53 ms |
2612 KB |
Output is correct |
15 |
Correct |
75 ms |
2404 KB |
Output is correct |
16 |
Correct |
52 ms |
2388 KB |
Output is correct |
17 |
Correct |
52 ms |
2384 KB |
Output is correct |
18 |
Correct |
53 ms |
2384 KB |
Output is correct |
19 |
Correct |
270 ms |
16552 KB |
Output is correct |
20 |
Correct |
238 ms |
15824 KB |
Output is correct |
21 |
Correct |
175 ms |
16184 KB |
Output is correct |
22 |
Correct |
178 ms |
15660 KB |
Output is correct |
23 |
Correct |
113 ms |
4024 KB |
Output is correct |
24 |
Correct |
84 ms |
4200 KB |
Output is correct |
25 |
Correct |
194 ms |
16352 KB |
Output is correct |
26 |
Correct |
230 ms |
16428 KB |
Output is correct |
27 |
Correct |
196 ms |
16408 KB |
Output is correct |
28 |
Correct |
203 ms |
16408 KB |
Output is correct |
29 |
Correct |
190 ms |
16276 KB |
Output is correct |
30 |
Correct |
125 ms |
4196 KB |
Output is correct |
31 |
Correct |
218 ms |
16488 KB |
Output is correct |
32 |
Correct |
230 ms |
16252 KB |
Output is correct |
33 |
Correct |
89 ms |
4228 KB |
Output is correct |
34 |
Correct |
206 ms |
16404 KB |
Output is correct |
35 |
Correct |
162 ms |
15144 KB |
Output is correct |
36 |
Correct |
99 ms |
4148 KB |
Output is correct |
37 |
Correct |
116 ms |
4008 KB |
Output is correct |
38 |
Correct |
208 ms |
15556 KB |
Output is correct |
39 |
Correct |
146 ms |
15380 KB |
Output is correct |
40 |
Correct |
147 ms |
10900 KB |
Output is correct |
41 |
Correct |
272 ms |
16580 KB |
Output is correct |
42 |
Correct |
105 ms |
15124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
2392 KB |
Output is correct |
2 |
Correct |
83 ms |
2452 KB |
Output is correct |
3 |
Correct |
57 ms |
2368 KB |
Output is correct |
4 |
Correct |
67 ms |
2372 KB |
Output is correct |
5 |
Correct |
67 ms |
2384 KB |
Output is correct |
6 |
Correct |
48 ms |
2484 KB |
Output is correct |
7 |
Correct |
68 ms |
2444 KB |
Output is correct |
8 |
Correct |
51 ms |
2592 KB |
Output is correct |
9 |
Correct |
73 ms |
2388 KB |
Output is correct |
10 |
Correct |
52 ms |
2620 KB |
Output is correct |
11 |
Correct |
73 ms |
2388 KB |
Output is correct |
12 |
Correct |
52 ms |
2384 KB |
Output is correct |
13 |
Correct |
52 ms |
2584 KB |
Output is correct |
14 |
Correct |
53 ms |
2612 KB |
Output is correct |
15 |
Correct |
75 ms |
2404 KB |
Output is correct |
16 |
Correct |
52 ms |
2388 KB |
Output is correct |
17 |
Correct |
52 ms |
2384 KB |
Output is correct |
18 |
Correct |
53 ms |
2384 KB |
Output is correct |
19 |
Correct |
57 ms |
2388 KB |
Output is correct |
20 |
Correct |
60 ms |
2312 KB |
Output is correct |
21 |
Correct |
51 ms |
2388 KB |
Output is correct |
22 |
Correct |
45 ms |
2396 KB |
Output is correct |
23 |
Correct |
80 ms |
2424 KB |
Output is correct |
24 |
Correct |
50 ms |
2480 KB |
Output is correct |
25 |
Correct |
54 ms |
2576 KB |
Output is correct |
26 |
Correct |
48 ms |
2384 KB |
Output is correct |
27 |
Correct |
80 ms |
2388 KB |
Output is correct |
28 |
Correct |
56 ms |
2332 KB |
Output is correct |
29 |
Correct |
75 ms |
2476 KB |
Output is correct |
30 |
Correct |
47 ms |
2368 KB |
Output is correct |
31 |
Correct |
53 ms |
2592 KB |
Output is correct |
32 |
Correct |
80 ms |
2388 KB |
Output is correct |
33 |
Correct |
57 ms |
2388 KB |
Output is correct |
34 |
Correct |
49 ms |
2384 KB |
Output is correct |
35 |
Correct |
54 ms |
2384 KB |
Output is correct |
36 |
Correct |
53 ms |
2388 KB |
Output is correct |
37 |
Correct |
53 ms |
2560 KB |
Output is correct |
38 |
Correct |
54 ms |
2388 KB |
Output is correct |
39 |
Correct |
75 ms |
2384 KB |
Output is correct |
40 |
Correct |
58 ms |
2388 KB |
Output is correct |
41 |
Correct |
60 ms |
2508 KB |
Output is correct |
42 |
Correct |
63 ms |
2852 KB |
Output is correct |
43 |
Correct |
76 ms |
2384 KB |
Output is correct |
44 |
Correct |
54 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
2392 KB |
Output is correct |
2 |
Correct |
83 ms |
2452 KB |
Output is correct |
3 |
Correct |
57 ms |
2368 KB |
Output is correct |
4 |
Correct |
67 ms |
2372 KB |
Output is correct |
5 |
Correct |
67 ms |
2384 KB |
Output is correct |
6 |
Correct |
48 ms |
2484 KB |
Output is correct |
7 |
Correct |
68 ms |
2444 KB |
Output is correct |
8 |
Correct |
51 ms |
2592 KB |
Output is correct |
9 |
Correct |
73 ms |
2388 KB |
Output is correct |
10 |
Correct |
52 ms |
2620 KB |
Output is correct |
11 |
Correct |
73 ms |
2388 KB |
Output is correct |
12 |
Correct |
52 ms |
2384 KB |
Output is correct |
13 |
Correct |
52 ms |
2584 KB |
Output is correct |
14 |
Correct |
53 ms |
2612 KB |
Output is correct |
15 |
Correct |
75 ms |
2404 KB |
Output is correct |
16 |
Correct |
52 ms |
2388 KB |
Output is correct |
17 |
Correct |
52 ms |
2384 KB |
Output is correct |
18 |
Correct |
53 ms |
2384 KB |
Output is correct |
19 |
Correct |
270 ms |
16552 KB |
Output is correct |
20 |
Correct |
238 ms |
15824 KB |
Output is correct |
21 |
Correct |
175 ms |
16184 KB |
Output is correct |
22 |
Correct |
178 ms |
15660 KB |
Output is correct |
23 |
Correct |
113 ms |
4024 KB |
Output is correct |
24 |
Correct |
84 ms |
4200 KB |
Output is correct |
25 |
Correct |
194 ms |
16352 KB |
Output is correct |
26 |
Correct |
230 ms |
16428 KB |
Output is correct |
27 |
Correct |
196 ms |
16408 KB |
Output is correct |
28 |
Correct |
203 ms |
16408 KB |
Output is correct |
29 |
Correct |
190 ms |
16276 KB |
Output is correct |
30 |
Correct |
125 ms |
4196 KB |
Output is correct |
31 |
Correct |
218 ms |
16488 KB |
Output is correct |
32 |
Correct |
230 ms |
16252 KB |
Output is correct |
33 |
Correct |
89 ms |
4228 KB |
Output is correct |
34 |
Correct |
206 ms |
16404 KB |
Output is correct |
35 |
Correct |
162 ms |
15144 KB |
Output is correct |
36 |
Correct |
99 ms |
4148 KB |
Output is correct |
37 |
Correct |
116 ms |
4008 KB |
Output is correct |
38 |
Correct |
208 ms |
15556 KB |
Output is correct |
39 |
Correct |
146 ms |
15380 KB |
Output is correct |
40 |
Correct |
147 ms |
10900 KB |
Output is correct |
41 |
Correct |
272 ms |
16580 KB |
Output is correct |
42 |
Correct |
105 ms |
15124 KB |
Output is correct |
43 |
Correct |
57 ms |
2388 KB |
Output is correct |
44 |
Correct |
60 ms |
2312 KB |
Output is correct |
45 |
Correct |
51 ms |
2388 KB |
Output is correct |
46 |
Correct |
45 ms |
2396 KB |
Output is correct |
47 |
Correct |
80 ms |
2424 KB |
Output is correct |
48 |
Correct |
50 ms |
2480 KB |
Output is correct |
49 |
Correct |
54 ms |
2576 KB |
Output is correct |
50 |
Correct |
48 ms |
2384 KB |
Output is correct |
51 |
Correct |
80 ms |
2388 KB |
Output is correct |
52 |
Correct |
56 ms |
2332 KB |
Output is correct |
53 |
Correct |
75 ms |
2476 KB |
Output is correct |
54 |
Correct |
47 ms |
2368 KB |
Output is correct |
55 |
Correct |
53 ms |
2592 KB |
Output is correct |
56 |
Correct |
80 ms |
2388 KB |
Output is correct |
57 |
Correct |
57 ms |
2388 KB |
Output is correct |
58 |
Correct |
49 ms |
2384 KB |
Output is correct |
59 |
Correct |
54 ms |
2384 KB |
Output is correct |
60 |
Correct |
53 ms |
2388 KB |
Output is correct |
61 |
Correct |
53 ms |
2560 KB |
Output is correct |
62 |
Correct |
54 ms |
2388 KB |
Output is correct |
63 |
Correct |
75 ms |
2384 KB |
Output is correct |
64 |
Correct |
58 ms |
2388 KB |
Output is correct |
65 |
Correct |
60 ms |
2508 KB |
Output is correct |
66 |
Correct |
63 ms |
2852 KB |
Output is correct |
67 |
Correct |
76 ms |
2384 KB |
Output is correct |
68 |
Correct |
54 ms |
2384 KB |
Output is correct |
69 |
Correct |
357 ms |
24740 KB |
Output is correct |
70 |
Correct |
376 ms |
27592 KB |
Output is correct |
71 |
Correct |
88 ms |
4076 KB |
Output is correct |
72 |
Correct |
91 ms |
4272 KB |
Output is correct |
73 |
Correct |
100 ms |
4140 KB |
Output is correct |
74 |
Correct |
186 ms |
15900 KB |
Output is correct |
75 |
Correct |
113 ms |
4256 KB |
Output is correct |
76 |
Correct |
213 ms |
17200 KB |
Output is correct |
77 |
Correct |
194 ms |
16064 KB |
Output is correct |
78 |
Correct |
103 ms |
4116 KB |
Output is correct |
79 |
Correct |
89 ms |
4136 KB |
Output is correct |
80 |
Correct |
273 ms |
23000 KB |
Output is correct |
81 |
Correct |
97 ms |
4420 KB |
Output is correct |
82 |
Correct |
387 ms |
28628 KB |
Output is correct |
83 |
Correct |
360 ms |
27704 KB |
Output is correct |
84 |
Correct |
117 ms |
4552 KB |
Output is correct |
85 |
Correct |
97 ms |
4560 KB |
Output is correct |
86 |
Correct |
272 ms |
23984 KB |
Output is correct |
87 |
Correct |
306 ms |
28616 KB |
Output is correct |
88 |
Correct |
103 ms |
4512 KB |
Output is correct |
89 |
Correct |
300 ms |
26936 KB |
Output is correct |
90 |
Correct |
337 ms |
28356 KB |
Output is correct |
91 |
Correct |
97 ms |
4296 KB |
Output is correct |
92 |
Incorrect |
298 ms |
22952 KB |
Output isn't correct |
93 |
Halted |
0 ms |
0 KB |
- |