#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 = 2e5 + 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 |
48 ms |
852 KB |
Output is correct |
2 |
Correct |
55 ms |
860 KB |
Output is correct |
3 |
Correct |
80 ms |
1020 KB |
Output is correct |
4 |
Correct |
49 ms |
848 KB |
Output is correct |
5 |
Correct |
66 ms |
852 KB |
Output is correct |
6 |
Correct |
47 ms |
888 KB |
Output is correct |
7 |
Correct |
69 ms |
896 KB |
Output is correct |
8 |
Correct |
53 ms |
848 KB |
Output is correct |
9 |
Correct |
49 ms |
852 KB |
Output is correct |
10 |
Correct |
49 ms |
852 KB |
Output is correct |
11 |
Correct |
50 ms |
852 KB |
Output is correct |
12 |
Correct |
50 ms |
852 KB |
Output is correct |
13 |
Correct |
52 ms |
920 KB |
Output is correct |
14 |
Correct |
48 ms |
976 KB |
Output is correct |
15 |
Correct |
49 ms |
852 KB |
Output is correct |
16 |
Correct |
48 ms |
860 KB |
Output is correct |
17 |
Correct |
54 ms |
976 KB |
Output is correct |
18 |
Correct |
78 ms |
1072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
852 KB |
Output is correct |
2 |
Correct |
55 ms |
860 KB |
Output is correct |
3 |
Correct |
80 ms |
1020 KB |
Output is correct |
4 |
Correct |
49 ms |
848 KB |
Output is correct |
5 |
Correct |
66 ms |
852 KB |
Output is correct |
6 |
Correct |
47 ms |
888 KB |
Output is correct |
7 |
Correct |
69 ms |
896 KB |
Output is correct |
8 |
Correct |
53 ms |
848 KB |
Output is correct |
9 |
Correct |
49 ms |
852 KB |
Output is correct |
10 |
Correct |
49 ms |
852 KB |
Output is correct |
11 |
Correct |
50 ms |
852 KB |
Output is correct |
12 |
Correct |
50 ms |
852 KB |
Output is correct |
13 |
Correct |
52 ms |
920 KB |
Output is correct |
14 |
Correct |
48 ms |
976 KB |
Output is correct |
15 |
Correct |
49 ms |
852 KB |
Output is correct |
16 |
Correct |
48 ms |
860 KB |
Output is correct |
17 |
Correct |
54 ms |
976 KB |
Output is correct |
18 |
Correct |
78 ms |
1072 KB |
Output is correct |
19 |
Correct |
222 ms |
12820 KB |
Output is correct |
20 |
Correct |
205 ms |
12100 KB |
Output is correct |
21 |
Correct |
160 ms |
12764 KB |
Output is correct |
22 |
Correct |
150 ms |
12328 KB |
Output is correct |
23 |
Correct |
94 ms |
1888 KB |
Output is correct |
24 |
Correct |
79 ms |
1896 KB |
Output is correct |
25 |
Correct |
170 ms |
12812 KB |
Output is correct |
26 |
Correct |
193 ms |
12856 KB |
Output is correct |
27 |
Correct |
192 ms |
12816 KB |
Output is correct |
28 |
Correct |
181 ms |
12824 KB |
Output is correct |
29 |
Correct |
167 ms |
12696 KB |
Output is correct |
30 |
Correct |
91 ms |
1892 KB |
Output is correct |
31 |
Correct |
174 ms |
12876 KB |
Output is correct |
32 |
Correct |
174 ms |
12692 KB |
Output is correct |
33 |
Correct |
85 ms |
1740 KB |
Output is correct |
34 |
Correct |
191 ms |
12828 KB |
Output is correct |
35 |
Correct |
153 ms |
11796 KB |
Output is correct |
36 |
Correct |
80 ms |
1876 KB |
Output is correct |
37 |
Correct |
78 ms |
1884 KB |
Output is correct |
38 |
Correct |
178 ms |
12048 KB |
Output is correct |
39 |
Correct |
133 ms |
11792 KB |
Output is correct |
40 |
Correct |
139 ms |
7624 KB |
Output is correct |
41 |
Correct |
247 ms |
13076 KB |
Output is correct |
42 |
Correct |
82 ms |
12052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
852 KB |
Output is correct |
2 |
Correct |
55 ms |
860 KB |
Output is correct |
3 |
Correct |
80 ms |
1020 KB |
Output is correct |
4 |
Correct |
49 ms |
848 KB |
Output is correct |
5 |
Correct |
66 ms |
852 KB |
Output is correct |
6 |
Correct |
47 ms |
888 KB |
Output is correct |
7 |
Correct |
69 ms |
896 KB |
Output is correct |
8 |
Correct |
53 ms |
848 KB |
Output is correct |
9 |
Correct |
49 ms |
852 KB |
Output is correct |
10 |
Correct |
49 ms |
852 KB |
Output is correct |
11 |
Correct |
50 ms |
852 KB |
Output is correct |
12 |
Correct |
50 ms |
852 KB |
Output is correct |
13 |
Correct |
52 ms |
920 KB |
Output is correct |
14 |
Correct |
48 ms |
976 KB |
Output is correct |
15 |
Correct |
49 ms |
852 KB |
Output is correct |
16 |
Correct |
48 ms |
860 KB |
Output is correct |
17 |
Correct |
54 ms |
976 KB |
Output is correct |
18 |
Correct |
78 ms |
1072 KB |
Output is correct |
19 |
Correct |
53 ms |
848 KB |
Output is correct |
20 |
Correct |
56 ms |
848 KB |
Output is correct |
21 |
Correct |
50 ms |
904 KB |
Output is correct |
22 |
Correct |
44 ms |
860 KB |
Output is correct |
23 |
Correct |
49 ms |
1080 KB |
Output is correct |
24 |
Correct |
66 ms |
848 KB |
Output is correct |
25 |
Correct |
56 ms |
848 KB |
Output is correct |
26 |
Correct |
48 ms |
852 KB |
Output is correct |
27 |
Correct |
48 ms |
1072 KB |
Output is correct |
28 |
Correct |
45 ms |
1008 KB |
Output is correct |
29 |
Correct |
51 ms |
1060 KB |
Output is correct |
30 |
Correct |
43 ms |
1024 KB |
Output is correct |
31 |
Correct |
50 ms |
860 KB |
Output is correct |
32 |
Correct |
52 ms |
848 KB |
Output is correct |
33 |
Correct |
50 ms |
852 KB |
Output is correct |
34 |
Correct |
48 ms |
856 KB |
Output is correct |
35 |
Correct |
51 ms |
856 KB |
Output is correct |
36 |
Correct |
75 ms |
2092 KB |
Output is correct |
37 |
Correct |
51 ms |
1884 KB |
Output is correct |
38 |
Correct |
52 ms |
2084 KB |
Output is correct |
39 |
Correct |
72 ms |
2036 KB |
Output is correct |
40 |
Correct |
61 ms |
1876 KB |
Output is correct |
41 |
Correct |
53 ms |
1876 KB |
Output is correct |
42 |
Correct |
53 ms |
1872 KB |
Output is correct |
43 |
Correct |
49 ms |
1872 KB |
Output is correct |
44 |
Correct |
54 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
852 KB |
Output is correct |
2 |
Correct |
55 ms |
860 KB |
Output is correct |
3 |
Correct |
80 ms |
1020 KB |
Output is correct |
4 |
Correct |
49 ms |
848 KB |
Output is correct |
5 |
Correct |
66 ms |
852 KB |
Output is correct |
6 |
Correct |
47 ms |
888 KB |
Output is correct |
7 |
Correct |
69 ms |
896 KB |
Output is correct |
8 |
Correct |
53 ms |
848 KB |
Output is correct |
9 |
Correct |
49 ms |
852 KB |
Output is correct |
10 |
Correct |
49 ms |
852 KB |
Output is correct |
11 |
Correct |
50 ms |
852 KB |
Output is correct |
12 |
Correct |
50 ms |
852 KB |
Output is correct |
13 |
Correct |
52 ms |
920 KB |
Output is correct |
14 |
Correct |
48 ms |
976 KB |
Output is correct |
15 |
Correct |
49 ms |
852 KB |
Output is correct |
16 |
Correct |
48 ms |
860 KB |
Output is correct |
17 |
Correct |
54 ms |
976 KB |
Output is correct |
18 |
Correct |
78 ms |
1072 KB |
Output is correct |
19 |
Correct |
222 ms |
12820 KB |
Output is correct |
20 |
Correct |
205 ms |
12100 KB |
Output is correct |
21 |
Correct |
160 ms |
12764 KB |
Output is correct |
22 |
Correct |
150 ms |
12328 KB |
Output is correct |
23 |
Correct |
94 ms |
1888 KB |
Output is correct |
24 |
Correct |
79 ms |
1896 KB |
Output is correct |
25 |
Correct |
170 ms |
12812 KB |
Output is correct |
26 |
Correct |
193 ms |
12856 KB |
Output is correct |
27 |
Correct |
192 ms |
12816 KB |
Output is correct |
28 |
Correct |
181 ms |
12824 KB |
Output is correct |
29 |
Correct |
167 ms |
12696 KB |
Output is correct |
30 |
Correct |
91 ms |
1892 KB |
Output is correct |
31 |
Correct |
174 ms |
12876 KB |
Output is correct |
32 |
Correct |
174 ms |
12692 KB |
Output is correct |
33 |
Correct |
85 ms |
1740 KB |
Output is correct |
34 |
Correct |
191 ms |
12828 KB |
Output is correct |
35 |
Correct |
153 ms |
11796 KB |
Output is correct |
36 |
Correct |
80 ms |
1876 KB |
Output is correct |
37 |
Correct |
78 ms |
1884 KB |
Output is correct |
38 |
Correct |
178 ms |
12048 KB |
Output is correct |
39 |
Correct |
133 ms |
11792 KB |
Output is correct |
40 |
Correct |
139 ms |
7624 KB |
Output is correct |
41 |
Correct |
247 ms |
13076 KB |
Output is correct |
42 |
Correct |
82 ms |
12052 KB |
Output is correct |
43 |
Correct |
53 ms |
848 KB |
Output is correct |
44 |
Correct |
56 ms |
848 KB |
Output is correct |
45 |
Correct |
50 ms |
904 KB |
Output is correct |
46 |
Correct |
44 ms |
860 KB |
Output is correct |
47 |
Correct |
49 ms |
1080 KB |
Output is correct |
48 |
Correct |
66 ms |
848 KB |
Output is correct |
49 |
Correct |
56 ms |
848 KB |
Output is correct |
50 |
Correct |
48 ms |
852 KB |
Output is correct |
51 |
Correct |
48 ms |
1072 KB |
Output is correct |
52 |
Correct |
45 ms |
1008 KB |
Output is correct |
53 |
Correct |
51 ms |
1060 KB |
Output is correct |
54 |
Correct |
43 ms |
1024 KB |
Output is correct |
55 |
Correct |
50 ms |
860 KB |
Output is correct |
56 |
Correct |
52 ms |
848 KB |
Output is correct |
57 |
Correct |
50 ms |
852 KB |
Output is correct |
58 |
Correct |
48 ms |
856 KB |
Output is correct |
59 |
Correct |
51 ms |
856 KB |
Output is correct |
60 |
Correct |
75 ms |
2092 KB |
Output is correct |
61 |
Correct |
51 ms |
1884 KB |
Output is correct |
62 |
Correct |
52 ms |
2084 KB |
Output is correct |
63 |
Correct |
72 ms |
2036 KB |
Output is correct |
64 |
Correct |
61 ms |
1876 KB |
Output is correct |
65 |
Correct |
53 ms |
1876 KB |
Output is correct |
66 |
Correct |
53 ms |
1872 KB |
Output is correct |
67 |
Correct |
49 ms |
1872 KB |
Output is correct |
68 |
Correct |
54 ms |
1876 KB |
Output is correct |
69 |
Correct |
345 ms |
23192 KB |
Output is correct |
70 |
Correct |
372 ms |
26196 KB |
Output is correct |
71 |
Correct |
85 ms |
3312 KB |
Output is correct |
72 |
Correct |
110 ms |
3444 KB |
Output is correct |
73 |
Correct |
83 ms |
3340 KB |
Output is correct |
74 |
Correct |
172 ms |
14524 KB |
Output is correct |
75 |
Correct |
80 ms |
3352 KB |
Output is correct |
76 |
Correct |
209 ms |
15408 KB |
Output is correct |
77 |
Correct |
170 ms |
14572 KB |
Output is correct |
78 |
Correct |
83 ms |
3276 KB |
Output is correct |
79 |
Correct |
88 ms |
3360 KB |
Output is correct |
80 |
Correct |
267 ms |
21624 KB |
Output is correct |
81 |
Correct |
109 ms |
3856 KB |
Output is correct |
82 |
Correct |
351 ms |
26928 KB |
Output is correct |
83 |
Correct |
324 ms |
26244 KB |
Output is correct |
84 |
Correct |
93 ms |
3792 KB |
Output is correct |
85 |
Correct |
91 ms |
3792 KB |
Output is correct |
86 |
Correct |
239 ms |
22432 KB |
Output is correct |
87 |
Correct |
292 ms |
26748 KB |
Output is correct |
88 |
Correct |
126 ms |
3792 KB |
Output is correct |
89 |
Correct |
250 ms |
25668 KB |
Output is correct |
90 |
Correct |
281 ms |
27144 KB |
Output is correct |
91 |
Correct |
92 ms |
4444 KB |
Output is correct |
92 |
Incorrect |
271 ms |
23100 KB |
Output isn't correct |
93 |
Halted |
0 ms |
0 KB |
- |