#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);
const int C = 7 , N = 300002;
vector<int> hashes;
ll base[N][4];
ll add(ll x , ll y){
return (x + y) % mod;
}
ll mul(ll x , ll y){
return (x * y) % mod;
}
struct Seg {
int siz;
vector<ll> hash;
vector<int> lazy;
void init(int n){
siz = 1;
while(siz < n)siz *= 2;
siz *= 2;
lazy.assign(siz * 2 , -1);
hash.assign(siz * 2 , 0);
}
void build(vector<int>& v , int x , int lx , int rx){
if(rx - lx == 1){
if(lx < (int)v.size())hash[x] = v[lx];
return;
}
int m = (lx + rx)/2;
build(v , 2 * x + 1 , lx , m);
build(v , 2 * x + 2 , m , rx);
hash[x] = add(hash[2 * x + 1] , mul(base[m-lx][3] , hash[2 *x + 2]));
//cout << x << ' ' << hash[x] << '\n';
}
void build(vector<int>& v){
build(v , 0 , 0 , siz);
}
void set(int l , int r , int v, int x , int lx , int rx){
if(lazy[x] != -1){
hash[x] = base[rx-lx][lazy[x]];
if(rx - lx != 1){
lazy[2 * x + 1] = lazy[x];
lazy[2 * x + 2] = lazy[x];
lazy[x] = -1;
}
}
if(rx <= l || r <= lx)return;
if(lx >= l && rx <= r){
hash[x] = base[rx-lx][v];
lazy[x] = v;
return;
}
int m = (lx + rx)/2;
set(l , r , v , 2 * x + 1 , lx , m);
set(l , r , v , 2 * x + 2 , m , rx);
hash[x] = add(hash[2 * x + 1] , mul(base[m-lx][3] , hash[2 *x + 2]));
}
void set(int l , int r , int v){
set(l , r , v , 0 , 0 , siz);
}
};
vector<int> convert(string s){
vector<int> ans;
for(int i = 0; i < (int)s.size(); i++){
if(s[i] == 'J')ans.pb(0);
else if(s[i] == 'O')ans.pb(1);
else ans.pb(2);
}
return ans;
}
vector<int> merge(vector<int> s , vector<int> t){
for(int i = 0; i < (int)s.size(); i++){
if(s[i] != t[i]){
if(s[i]!=0 && t[i] != 0)s[i] = 0;
else if(s[i]!=1 && t[i] != 1)s[i] = 1;
else s[i] = 2;
}
}
return s;
}
int hashing(vector<int>& v){
ll ans = 0;
for(int i = 0; i < (int)v.size(); i++){
ans = add(ans , mul(base[i][3] , v[i]));
}
return ans;
}
string find(int x){
for(int i = 0; i < 9; i++){
if(x == hashes[i])return "Yes";
}
return "No";
}
void solve(){
int n;
cin >> n;
string a,b,c;
cin >> a >> b >> c;
vector<vector<int>> v;
v.pb(convert(a));
v.pb(convert(b));
v.pb(convert(c));
v.pb(merge(v[0],v[1]));
v.pb(merge(v[1],v[2]));
v.pb(merge(v[0],v[2]));
v.pb(merge(v[3] , v[2]));
v.pb(merge(v[4] , v[0]));
v.pb(merge(v[5] , v[1]));
base[0][0] = 0;
base[0][1] = 0;
base[0][2] = 0;
base[0][3] = 1;
for(int i = 1; i < N; i++){
base[i][3] = mul(base[i-1][3],C);
for(int j = 0; j < 3; j++){
base[i][j] = add(base[i-1][j] , mul(j,base[i-1][3]));
}
}
for(int i = 0; i < 9; i++){
hashes.pb(hashing(v[i]));
//cout << hashes[i] << ' ';
}
int q;
cin >> q;
string t;
cin >> t;
vector<int> t1 = convert(t);
Seg st;
st.init(n);
st.build(t1);
cout << find(st.hash[0]) << '\n';
while(q--){
int l , r;
cin >> l >> r;
char c1;
cin >> c1;
int v1;
if(c1 == 'J')v1 = 0;
else if(c1 == 'O')v1 = 1;
else v1 = 2;
l--;
st.set(l , r , v1);
cout << find(st.hash[0]) << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
10524 KB |
Output is correct |
2 |
Correct |
90 ms |
10460 KB |
Output is correct |
3 |
Correct |
88 ms |
10564 KB |
Output is correct |
4 |
Correct |
81 ms |
10488 KB |
Output is correct |
5 |
Correct |
85 ms |
10488 KB |
Output is correct |
6 |
Correct |
79 ms |
10468 KB |
Output is correct |
7 |
Correct |
81 ms |
10356 KB |
Output is correct |
8 |
Correct |
84 ms |
10412 KB |
Output is correct |
9 |
Correct |
82 ms |
10504 KB |
Output is correct |
10 |
Correct |
83 ms |
10416 KB |
Output is correct |
11 |
Correct |
89 ms |
10320 KB |
Output is correct |
12 |
Correct |
84 ms |
10332 KB |
Output is correct |
13 |
Correct |
82 ms |
10356 KB |
Output is correct |
14 |
Correct |
90 ms |
10344 KB |
Output is correct |
15 |
Correct |
83 ms |
10444 KB |
Output is correct |
16 |
Correct |
82 ms |
10440 KB |
Output is correct |
17 |
Correct |
82 ms |
10380 KB |
Output is correct |
18 |
Correct |
86 ms |
10372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
10524 KB |
Output is correct |
2 |
Correct |
90 ms |
10460 KB |
Output is correct |
3 |
Correct |
88 ms |
10564 KB |
Output is correct |
4 |
Correct |
81 ms |
10488 KB |
Output is correct |
5 |
Correct |
85 ms |
10488 KB |
Output is correct |
6 |
Correct |
79 ms |
10468 KB |
Output is correct |
7 |
Correct |
81 ms |
10356 KB |
Output is correct |
8 |
Correct |
84 ms |
10412 KB |
Output is correct |
9 |
Correct |
82 ms |
10504 KB |
Output is correct |
10 |
Correct |
83 ms |
10416 KB |
Output is correct |
11 |
Correct |
89 ms |
10320 KB |
Output is correct |
12 |
Correct |
84 ms |
10332 KB |
Output is correct |
13 |
Correct |
82 ms |
10356 KB |
Output is correct |
14 |
Correct |
90 ms |
10344 KB |
Output is correct |
15 |
Correct |
83 ms |
10444 KB |
Output is correct |
16 |
Correct |
82 ms |
10440 KB |
Output is correct |
17 |
Correct |
82 ms |
10380 KB |
Output is correct |
18 |
Correct |
86 ms |
10372 KB |
Output is correct |
19 |
Correct |
240 ms |
34588 KB |
Output is correct |
20 |
Correct |
241 ms |
36312 KB |
Output is correct |
21 |
Correct |
180 ms |
35644 KB |
Output is correct |
22 |
Correct |
183 ms |
34540 KB |
Output is correct |
23 |
Correct |
158 ms |
13900 KB |
Output is correct |
24 |
Correct |
124 ms |
13896 KB |
Output is correct |
25 |
Correct |
186 ms |
36536 KB |
Output is correct |
26 |
Correct |
186 ms |
36504 KB |
Output is correct |
27 |
Correct |
198 ms |
36508 KB |
Output is correct |
28 |
Correct |
206 ms |
36472 KB |
Output is correct |
29 |
Correct |
201 ms |
36120 KB |
Output is correct |
30 |
Correct |
131 ms |
13976 KB |
Output is correct |
31 |
Correct |
209 ms |
36420 KB |
Output is correct |
32 |
Correct |
194 ms |
35376 KB |
Output is correct |
33 |
Correct |
127 ms |
13900 KB |
Output is correct |
34 |
Correct |
232 ms |
36472 KB |
Output is correct |
35 |
Correct |
171 ms |
33608 KB |
Output is correct |
36 |
Correct |
124 ms |
13904 KB |
Output is correct |
37 |
Correct |
128 ms |
13920 KB |
Output is correct |
38 |
Correct |
226 ms |
36264 KB |
Output is correct |
39 |
Correct |
182 ms |
36580 KB |
Output is correct |
40 |
Correct |
165 ms |
26340 KB |
Output is correct |
41 |
Correct |
262 ms |
36680 KB |
Output is correct |
42 |
Correct |
115 ms |
35872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
10524 KB |
Output is correct |
2 |
Correct |
90 ms |
10460 KB |
Output is correct |
3 |
Correct |
88 ms |
10564 KB |
Output is correct |
4 |
Correct |
81 ms |
10488 KB |
Output is correct |
5 |
Correct |
85 ms |
10488 KB |
Output is correct |
6 |
Correct |
79 ms |
10468 KB |
Output is correct |
7 |
Correct |
81 ms |
10356 KB |
Output is correct |
8 |
Correct |
84 ms |
10412 KB |
Output is correct |
9 |
Correct |
82 ms |
10504 KB |
Output is correct |
10 |
Correct |
83 ms |
10416 KB |
Output is correct |
11 |
Correct |
89 ms |
10320 KB |
Output is correct |
12 |
Correct |
84 ms |
10332 KB |
Output is correct |
13 |
Correct |
82 ms |
10356 KB |
Output is correct |
14 |
Correct |
90 ms |
10344 KB |
Output is correct |
15 |
Correct |
83 ms |
10444 KB |
Output is correct |
16 |
Correct |
82 ms |
10440 KB |
Output is correct |
17 |
Correct |
82 ms |
10380 KB |
Output is correct |
18 |
Correct |
86 ms |
10372 KB |
Output is correct |
19 |
Correct |
88 ms |
10316 KB |
Output is correct |
20 |
Correct |
89 ms |
10340 KB |
Output is correct |
21 |
Correct |
90 ms |
10332 KB |
Output is correct |
22 |
Correct |
77 ms |
10344 KB |
Output is correct |
23 |
Correct |
85 ms |
10368 KB |
Output is correct |
24 |
Correct |
81 ms |
10324 KB |
Output is correct |
25 |
Correct |
91 ms |
10340 KB |
Output is correct |
26 |
Correct |
82 ms |
10500 KB |
Output is correct |
27 |
Correct |
81 ms |
10364 KB |
Output is correct |
28 |
Correct |
77 ms |
10424 KB |
Output is correct |
29 |
Correct |
83 ms |
10340 KB |
Output is correct |
30 |
Correct |
76 ms |
10400 KB |
Output is correct |
31 |
Correct |
87 ms |
10468 KB |
Output is correct |
32 |
Correct |
86 ms |
10428 KB |
Output is correct |
33 |
Correct |
83 ms |
10388 KB |
Output is correct |
34 |
Correct |
76 ms |
10404 KB |
Output is correct |
35 |
Correct |
85 ms |
10352 KB |
Output is correct |
36 |
Correct |
84 ms |
10344 KB |
Output is correct |
37 |
Correct |
83 ms |
10404 KB |
Output is correct |
38 |
Correct |
83 ms |
10384 KB |
Output is correct |
39 |
Correct |
82 ms |
10392 KB |
Output is correct |
40 |
Correct |
83 ms |
10356 KB |
Output is correct |
41 |
Correct |
87 ms |
10344 KB |
Output is correct |
42 |
Correct |
82 ms |
10372 KB |
Output is correct |
43 |
Correct |
81 ms |
10316 KB |
Output is correct |
44 |
Correct |
87 ms |
10352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
10524 KB |
Output is correct |
2 |
Correct |
90 ms |
10460 KB |
Output is correct |
3 |
Correct |
88 ms |
10564 KB |
Output is correct |
4 |
Correct |
81 ms |
10488 KB |
Output is correct |
5 |
Correct |
85 ms |
10488 KB |
Output is correct |
6 |
Correct |
79 ms |
10468 KB |
Output is correct |
7 |
Correct |
81 ms |
10356 KB |
Output is correct |
8 |
Correct |
84 ms |
10412 KB |
Output is correct |
9 |
Correct |
82 ms |
10504 KB |
Output is correct |
10 |
Correct |
83 ms |
10416 KB |
Output is correct |
11 |
Correct |
89 ms |
10320 KB |
Output is correct |
12 |
Correct |
84 ms |
10332 KB |
Output is correct |
13 |
Correct |
82 ms |
10356 KB |
Output is correct |
14 |
Correct |
90 ms |
10344 KB |
Output is correct |
15 |
Correct |
83 ms |
10444 KB |
Output is correct |
16 |
Correct |
82 ms |
10440 KB |
Output is correct |
17 |
Correct |
82 ms |
10380 KB |
Output is correct |
18 |
Correct |
86 ms |
10372 KB |
Output is correct |
19 |
Correct |
240 ms |
34588 KB |
Output is correct |
20 |
Correct |
241 ms |
36312 KB |
Output is correct |
21 |
Correct |
180 ms |
35644 KB |
Output is correct |
22 |
Correct |
183 ms |
34540 KB |
Output is correct |
23 |
Correct |
158 ms |
13900 KB |
Output is correct |
24 |
Correct |
124 ms |
13896 KB |
Output is correct |
25 |
Correct |
186 ms |
36536 KB |
Output is correct |
26 |
Correct |
186 ms |
36504 KB |
Output is correct |
27 |
Correct |
198 ms |
36508 KB |
Output is correct |
28 |
Correct |
206 ms |
36472 KB |
Output is correct |
29 |
Correct |
201 ms |
36120 KB |
Output is correct |
30 |
Correct |
131 ms |
13976 KB |
Output is correct |
31 |
Correct |
209 ms |
36420 KB |
Output is correct |
32 |
Correct |
194 ms |
35376 KB |
Output is correct |
33 |
Correct |
127 ms |
13900 KB |
Output is correct |
34 |
Correct |
232 ms |
36472 KB |
Output is correct |
35 |
Correct |
171 ms |
33608 KB |
Output is correct |
36 |
Correct |
124 ms |
13904 KB |
Output is correct |
37 |
Correct |
128 ms |
13920 KB |
Output is correct |
38 |
Correct |
226 ms |
36264 KB |
Output is correct |
39 |
Correct |
182 ms |
36580 KB |
Output is correct |
40 |
Correct |
165 ms |
26340 KB |
Output is correct |
41 |
Correct |
262 ms |
36680 KB |
Output is correct |
42 |
Correct |
115 ms |
35872 KB |
Output is correct |
43 |
Correct |
88 ms |
10316 KB |
Output is correct |
44 |
Correct |
89 ms |
10340 KB |
Output is correct |
45 |
Correct |
90 ms |
10332 KB |
Output is correct |
46 |
Correct |
77 ms |
10344 KB |
Output is correct |
47 |
Correct |
85 ms |
10368 KB |
Output is correct |
48 |
Correct |
81 ms |
10324 KB |
Output is correct |
49 |
Correct |
91 ms |
10340 KB |
Output is correct |
50 |
Correct |
82 ms |
10500 KB |
Output is correct |
51 |
Correct |
81 ms |
10364 KB |
Output is correct |
52 |
Correct |
77 ms |
10424 KB |
Output is correct |
53 |
Correct |
83 ms |
10340 KB |
Output is correct |
54 |
Correct |
76 ms |
10400 KB |
Output is correct |
55 |
Correct |
87 ms |
10468 KB |
Output is correct |
56 |
Correct |
86 ms |
10428 KB |
Output is correct |
57 |
Correct |
83 ms |
10388 KB |
Output is correct |
58 |
Correct |
76 ms |
10404 KB |
Output is correct |
59 |
Correct |
85 ms |
10352 KB |
Output is correct |
60 |
Correct |
84 ms |
10344 KB |
Output is correct |
61 |
Correct |
83 ms |
10404 KB |
Output is correct |
62 |
Correct |
83 ms |
10384 KB |
Output is correct |
63 |
Correct |
82 ms |
10392 KB |
Output is correct |
64 |
Correct |
83 ms |
10356 KB |
Output is correct |
65 |
Correct |
87 ms |
10344 KB |
Output is correct |
66 |
Correct |
82 ms |
10372 KB |
Output is correct |
67 |
Correct |
81 ms |
10316 KB |
Output is correct |
68 |
Correct |
87 ms |
10352 KB |
Output is correct |
69 |
Correct |
236 ms |
34476 KB |
Output is correct |
70 |
Correct |
251 ms |
36296 KB |
Output is correct |
71 |
Correct |
131 ms |
14056 KB |
Output is correct |
72 |
Correct |
128 ms |
13900 KB |
Output is correct |
73 |
Correct |
125 ms |
14000 KB |
Output is correct |
74 |
Correct |
170 ms |
34376 KB |
Output is correct |
75 |
Correct |
127 ms |
13868 KB |
Output is correct |
76 |
Correct |
191 ms |
36420 KB |
Output is correct |
77 |
Correct |
179 ms |
34624 KB |
Output is correct |
78 |
Correct |
133 ms |
14080 KB |
Output is correct |
79 |
Correct |
127 ms |
13896 KB |
Output is correct |
80 |
Correct |
180 ms |
33148 KB |
Output is correct |
81 |
Correct |
125 ms |
13888 KB |
Output is correct |
82 |
Correct |
196 ms |
36496 KB |
Output is correct |
83 |
Correct |
192 ms |
35788 KB |
Output is correct |
84 |
Correct |
126 ms |
13864 KB |
Output is correct |
85 |
Correct |
128 ms |
13936 KB |
Output is correct |
86 |
Correct |
193 ms |
33740 KB |
Output is correct |
87 |
Correct |
204 ms |
36408 KB |
Output is correct |
88 |
Correct |
133 ms |
13900 KB |
Output is correct |
89 |
Correct |
188 ms |
35036 KB |
Output is correct |
90 |
Correct |
209 ms |
36380 KB |
Output is correct |
91 |
Correct |
132 ms |
13868 KB |
Output is correct |
92 |
Correct |
178 ms |
33628 KB |
Output is correct |
93 |
Correct |
128 ms |
13976 KB |
Output is correct |
94 |
Correct |
128 ms |
13900 KB |
Output is correct |
95 |
Correct |
124 ms |
13988 KB |
Output is correct |
96 |
Correct |
219 ms |
36208 KB |
Output is correct |
97 |
Correct |
153 ms |
36636 KB |
Output is correct |
98 |
Correct |
168 ms |
26332 KB |
Output is correct |
99 |
Correct |
271 ms |
36636 KB |
Output is correct |
100 |
Correct |
138 ms |
35896 KB |
Output is correct |