#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;
int base[N][4];
int add(ll x , ll y){
return (x + y) % mod;
}
int mul(ll x , ll y){
return (x * y) % mod;
}
struct Seg {
int siz;
vector<int> 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){
int 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 |
83 ms |
5892 KB |
Output is correct |
2 |
Correct |
88 ms |
5964 KB |
Output is correct |
3 |
Correct |
88 ms |
5964 KB |
Output is correct |
4 |
Correct |
87 ms |
5980 KB |
Output is correct |
5 |
Correct |
77 ms |
5808 KB |
Output is correct |
6 |
Correct |
76 ms |
5860 KB |
Output is correct |
7 |
Correct |
81 ms |
5840 KB |
Output is correct |
8 |
Correct |
80 ms |
5804 KB |
Output is correct |
9 |
Correct |
81 ms |
5876 KB |
Output is correct |
10 |
Correct |
81 ms |
5836 KB |
Output is correct |
11 |
Correct |
81 ms |
5872 KB |
Output is correct |
12 |
Correct |
81 ms |
5780 KB |
Output is correct |
13 |
Correct |
88 ms |
5816 KB |
Output is correct |
14 |
Correct |
81 ms |
5792 KB |
Output is correct |
15 |
Correct |
81 ms |
5836 KB |
Output is correct |
16 |
Correct |
81 ms |
5772 KB |
Output is correct |
17 |
Correct |
84 ms |
5772 KB |
Output is correct |
18 |
Correct |
86 ms |
5996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
5892 KB |
Output is correct |
2 |
Correct |
88 ms |
5964 KB |
Output is correct |
3 |
Correct |
88 ms |
5964 KB |
Output is correct |
4 |
Correct |
87 ms |
5980 KB |
Output is correct |
5 |
Correct |
77 ms |
5808 KB |
Output is correct |
6 |
Correct |
76 ms |
5860 KB |
Output is correct |
7 |
Correct |
81 ms |
5840 KB |
Output is correct |
8 |
Correct |
80 ms |
5804 KB |
Output is correct |
9 |
Correct |
81 ms |
5876 KB |
Output is correct |
10 |
Correct |
81 ms |
5836 KB |
Output is correct |
11 |
Correct |
81 ms |
5872 KB |
Output is correct |
12 |
Correct |
81 ms |
5780 KB |
Output is correct |
13 |
Correct |
88 ms |
5816 KB |
Output is correct |
14 |
Correct |
81 ms |
5792 KB |
Output is correct |
15 |
Correct |
81 ms |
5836 KB |
Output is correct |
16 |
Correct |
81 ms |
5772 KB |
Output is correct |
17 |
Correct |
84 ms |
5772 KB |
Output is correct |
18 |
Correct |
86 ms |
5996 KB |
Output is correct |
19 |
Correct |
238 ms |
24800 KB |
Output is correct |
20 |
Correct |
260 ms |
24696 KB |
Output is correct |
21 |
Correct |
168 ms |
24068 KB |
Output is correct |
22 |
Correct |
169 ms |
23360 KB |
Output is correct |
23 |
Correct |
131 ms |
7464 KB |
Output is correct |
24 |
Correct |
126 ms |
7524 KB |
Output is correct |
25 |
Correct |
179 ms |
24736 KB |
Output is correct |
26 |
Correct |
179 ms |
24740 KB |
Output is correct |
27 |
Correct |
210 ms |
24896 KB |
Output is correct |
28 |
Correct |
214 ms |
24732 KB |
Output is correct |
29 |
Correct |
196 ms |
24496 KB |
Output is correct |
30 |
Correct |
141 ms |
7548 KB |
Output is correct |
31 |
Correct |
203 ms |
24712 KB |
Output is correct |
32 |
Correct |
189 ms |
23852 KB |
Output is correct |
33 |
Correct |
123 ms |
7436 KB |
Output is correct |
34 |
Correct |
207 ms |
24732 KB |
Output is correct |
35 |
Correct |
159 ms |
22336 KB |
Output is correct |
36 |
Correct |
125 ms |
7356 KB |
Output is correct |
37 |
Correct |
126 ms |
7380 KB |
Output is correct |
38 |
Correct |
225 ms |
24732 KB |
Output is correct |
39 |
Correct |
149 ms |
24684 KB |
Output is correct |
40 |
Correct |
166 ms |
17124 KB |
Output is correct |
41 |
Correct |
255 ms |
24904 KB |
Output is correct |
42 |
Correct |
111 ms |
24872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
5892 KB |
Output is correct |
2 |
Correct |
88 ms |
5964 KB |
Output is correct |
3 |
Correct |
88 ms |
5964 KB |
Output is correct |
4 |
Correct |
87 ms |
5980 KB |
Output is correct |
5 |
Correct |
77 ms |
5808 KB |
Output is correct |
6 |
Correct |
76 ms |
5860 KB |
Output is correct |
7 |
Correct |
81 ms |
5840 KB |
Output is correct |
8 |
Correct |
80 ms |
5804 KB |
Output is correct |
9 |
Correct |
81 ms |
5876 KB |
Output is correct |
10 |
Correct |
81 ms |
5836 KB |
Output is correct |
11 |
Correct |
81 ms |
5872 KB |
Output is correct |
12 |
Correct |
81 ms |
5780 KB |
Output is correct |
13 |
Correct |
88 ms |
5816 KB |
Output is correct |
14 |
Correct |
81 ms |
5792 KB |
Output is correct |
15 |
Correct |
81 ms |
5836 KB |
Output is correct |
16 |
Correct |
81 ms |
5772 KB |
Output is correct |
17 |
Correct |
84 ms |
5772 KB |
Output is correct |
18 |
Correct |
86 ms |
5996 KB |
Output is correct |
19 |
Correct |
85 ms |
5956 KB |
Output is correct |
20 |
Correct |
91 ms |
5780 KB |
Output is correct |
21 |
Correct |
80 ms |
5860 KB |
Output is correct |
22 |
Correct |
74 ms |
5788 KB |
Output is correct |
23 |
Correct |
84 ms |
5864 KB |
Output is correct |
24 |
Correct |
81 ms |
5792 KB |
Output is correct |
25 |
Correct |
83 ms |
5836 KB |
Output is correct |
26 |
Correct |
79 ms |
5844 KB |
Output is correct |
27 |
Correct |
80 ms |
5828 KB |
Output is correct |
28 |
Correct |
75 ms |
5840 KB |
Output is correct |
29 |
Correct |
81 ms |
5804 KB |
Output is correct |
30 |
Correct |
78 ms |
5764 KB |
Output is correct |
31 |
Correct |
82 ms |
5772 KB |
Output is correct |
32 |
Correct |
84 ms |
5872 KB |
Output is correct |
33 |
Correct |
83 ms |
5828 KB |
Output is correct |
34 |
Correct |
79 ms |
5780 KB |
Output is correct |
35 |
Correct |
82 ms |
5756 KB |
Output is correct |
36 |
Correct |
81 ms |
5864 KB |
Output is correct |
37 |
Correct |
83 ms |
5752 KB |
Output is correct |
38 |
Correct |
81 ms |
5836 KB |
Output is correct |
39 |
Correct |
87 ms |
5784 KB |
Output is correct |
40 |
Correct |
82 ms |
5804 KB |
Output is correct |
41 |
Correct |
80 ms |
5868 KB |
Output is correct |
42 |
Correct |
84 ms |
5868 KB |
Output is correct |
43 |
Correct |
82 ms |
5836 KB |
Output is correct |
44 |
Correct |
82 ms |
5784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
5892 KB |
Output is correct |
2 |
Correct |
88 ms |
5964 KB |
Output is correct |
3 |
Correct |
88 ms |
5964 KB |
Output is correct |
4 |
Correct |
87 ms |
5980 KB |
Output is correct |
5 |
Correct |
77 ms |
5808 KB |
Output is correct |
6 |
Correct |
76 ms |
5860 KB |
Output is correct |
7 |
Correct |
81 ms |
5840 KB |
Output is correct |
8 |
Correct |
80 ms |
5804 KB |
Output is correct |
9 |
Correct |
81 ms |
5876 KB |
Output is correct |
10 |
Correct |
81 ms |
5836 KB |
Output is correct |
11 |
Correct |
81 ms |
5872 KB |
Output is correct |
12 |
Correct |
81 ms |
5780 KB |
Output is correct |
13 |
Correct |
88 ms |
5816 KB |
Output is correct |
14 |
Correct |
81 ms |
5792 KB |
Output is correct |
15 |
Correct |
81 ms |
5836 KB |
Output is correct |
16 |
Correct |
81 ms |
5772 KB |
Output is correct |
17 |
Correct |
84 ms |
5772 KB |
Output is correct |
18 |
Correct |
86 ms |
5996 KB |
Output is correct |
19 |
Correct |
238 ms |
24800 KB |
Output is correct |
20 |
Correct |
260 ms |
24696 KB |
Output is correct |
21 |
Correct |
168 ms |
24068 KB |
Output is correct |
22 |
Correct |
169 ms |
23360 KB |
Output is correct |
23 |
Correct |
131 ms |
7464 KB |
Output is correct |
24 |
Correct |
126 ms |
7524 KB |
Output is correct |
25 |
Correct |
179 ms |
24736 KB |
Output is correct |
26 |
Correct |
179 ms |
24740 KB |
Output is correct |
27 |
Correct |
210 ms |
24896 KB |
Output is correct |
28 |
Correct |
214 ms |
24732 KB |
Output is correct |
29 |
Correct |
196 ms |
24496 KB |
Output is correct |
30 |
Correct |
141 ms |
7548 KB |
Output is correct |
31 |
Correct |
203 ms |
24712 KB |
Output is correct |
32 |
Correct |
189 ms |
23852 KB |
Output is correct |
33 |
Correct |
123 ms |
7436 KB |
Output is correct |
34 |
Correct |
207 ms |
24732 KB |
Output is correct |
35 |
Correct |
159 ms |
22336 KB |
Output is correct |
36 |
Correct |
125 ms |
7356 KB |
Output is correct |
37 |
Correct |
126 ms |
7380 KB |
Output is correct |
38 |
Correct |
225 ms |
24732 KB |
Output is correct |
39 |
Correct |
149 ms |
24684 KB |
Output is correct |
40 |
Correct |
166 ms |
17124 KB |
Output is correct |
41 |
Correct |
255 ms |
24904 KB |
Output is correct |
42 |
Correct |
111 ms |
24872 KB |
Output is correct |
43 |
Correct |
85 ms |
5956 KB |
Output is correct |
44 |
Correct |
91 ms |
5780 KB |
Output is correct |
45 |
Correct |
80 ms |
5860 KB |
Output is correct |
46 |
Correct |
74 ms |
5788 KB |
Output is correct |
47 |
Correct |
84 ms |
5864 KB |
Output is correct |
48 |
Correct |
81 ms |
5792 KB |
Output is correct |
49 |
Correct |
83 ms |
5836 KB |
Output is correct |
50 |
Correct |
79 ms |
5844 KB |
Output is correct |
51 |
Correct |
80 ms |
5828 KB |
Output is correct |
52 |
Correct |
75 ms |
5840 KB |
Output is correct |
53 |
Correct |
81 ms |
5804 KB |
Output is correct |
54 |
Correct |
78 ms |
5764 KB |
Output is correct |
55 |
Correct |
82 ms |
5772 KB |
Output is correct |
56 |
Correct |
84 ms |
5872 KB |
Output is correct |
57 |
Correct |
83 ms |
5828 KB |
Output is correct |
58 |
Correct |
79 ms |
5780 KB |
Output is correct |
59 |
Correct |
82 ms |
5756 KB |
Output is correct |
60 |
Correct |
81 ms |
5864 KB |
Output is correct |
61 |
Correct |
83 ms |
5752 KB |
Output is correct |
62 |
Correct |
81 ms |
5836 KB |
Output is correct |
63 |
Correct |
87 ms |
5784 KB |
Output is correct |
64 |
Correct |
82 ms |
5804 KB |
Output is correct |
65 |
Correct |
80 ms |
5868 KB |
Output is correct |
66 |
Correct |
84 ms |
5868 KB |
Output is correct |
67 |
Correct |
82 ms |
5836 KB |
Output is correct |
68 |
Correct |
82 ms |
5784 KB |
Output is correct |
69 |
Correct |
221 ms |
23184 KB |
Output is correct |
70 |
Correct |
274 ms |
24680 KB |
Output is correct |
71 |
Correct |
124 ms |
7368 KB |
Output is correct |
72 |
Correct |
123 ms |
7460 KB |
Output is correct |
73 |
Correct |
123 ms |
7416 KB |
Output is correct |
74 |
Correct |
171 ms |
23096 KB |
Output is correct |
75 |
Correct |
126 ms |
7372 KB |
Output is correct |
76 |
Correct |
188 ms |
24760 KB |
Output is correct |
77 |
Correct |
175 ms |
23112 KB |
Output is correct |
78 |
Correct |
124 ms |
7364 KB |
Output is correct |
79 |
Correct |
129 ms |
7364 KB |
Output is correct |
80 |
Correct |
169 ms |
21932 KB |
Output is correct |
81 |
Correct |
123 ms |
7420 KB |
Output is correct |
82 |
Correct |
203 ms |
24724 KB |
Output is correct |
83 |
Correct |
188 ms |
24124 KB |
Output is correct |
84 |
Correct |
132 ms |
7356 KB |
Output is correct |
85 |
Correct |
141 ms |
7352 KB |
Output is correct |
86 |
Correct |
197 ms |
22396 KB |
Output is correct |
87 |
Correct |
199 ms |
24724 KB |
Output is correct |
88 |
Correct |
136 ms |
7372 KB |
Output is correct |
89 |
Correct |
184 ms |
23556 KB |
Output is correct |
90 |
Correct |
195 ms |
24732 KB |
Output is correct |
91 |
Correct |
130 ms |
7368 KB |
Output is correct |
92 |
Correct |
179 ms |
22564 KB |
Output is correct |
93 |
Correct |
122 ms |
7424 KB |
Output is correct |
94 |
Correct |
122 ms |
7368 KB |
Output is correct |
95 |
Correct |
123 ms |
7392 KB |
Output is correct |
96 |
Correct |
219 ms |
24672 KB |
Output is correct |
97 |
Correct |
148 ms |
24604 KB |
Output is correct |
98 |
Correct |
162 ms |
16876 KB |
Output is correct |
99 |
Correct |
264 ms |
24740 KB |
Output is correct |
100 |
Correct |
127 ms |
24828 KB |
Output is correct |