#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 = 200002;
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 |
75 ms |
1612 KB |
Output is correct |
2 |
Correct |
83 ms |
1584 KB |
Output is correct |
3 |
Correct |
80 ms |
1648 KB |
Output is correct |
4 |
Correct |
76 ms |
1684 KB |
Output is correct |
5 |
Correct |
74 ms |
2364 KB |
Output is correct |
6 |
Correct |
71 ms |
2328 KB |
Output is correct |
7 |
Correct |
75 ms |
2364 KB |
Output is correct |
8 |
Correct |
82 ms |
2480 KB |
Output is correct |
9 |
Correct |
75 ms |
2376 KB |
Output is correct |
10 |
Correct |
76 ms |
2380 KB |
Output is correct |
11 |
Correct |
76 ms |
2408 KB |
Output is correct |
12 |
Correct |
77 ms |
2408 KB |
Output is correct |
13 |
Correct |
77 ms |
2364 KB |
Output is correct |
14 |
Correct |
76 ms |
2456 KB |
Output is correct |
15 |
Correct |
81 ms |
2452 KB |
Output is correct |
16 |
Correct |
75 ms |
2360 KB |
Output is correct |
17 |
Correct |
81 ms |
2436 KB |
Output is correct |
18 |
Correct |
78 ms |
2300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
1612 KB |
Output is correct |
2 |
Correct |
83 ms |
1584 KB |
Output is correct |
3 |
Correct |
80 ms |
1648 KB |
Output is correct |
4 |
Correct |
76 ms |
1684 KB |
Output is correct |
5 |
Correct |
74 ms |
2364 KB |
Output is correct |
6 |
Correct |
71 ms |
2328 KB |
Output is correct |
7 |
Correct |
75 ms |
2364 KB |
Output is correct |
8 |
Correct |
82 ms |
2480 KB |
Output is correct |
9 |
Correct |
75 ms |
2376 KB |
Output is correct |
10 |
Correct |
76 ms |
2380 KB |
Output is correct |
11 |
Correct |
76 ms |
2408 KB |
Output is correct |
12 |
Correct |
77 ms |
2408 KB |
Output is correct |
13 |
Correct |
77 ms |
2364 KB |
Output is correct |
14 |
Correct |
76 ms |
2456 KB |
Output is correct |
15 |
Correct |
81 ms |
2452 KB |
Output is correct |
16 |
Correct |
75 ms |
2360 KB |
Output is correct |
17 |
Correct |
81 ms |
2436 KB |
Output is correct |
18 |
Correct |
78 ms |
2300 KB |
Output is correct |
19 |
Runtime error |
62 ms |
59784 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
1612 KB |
Output is correct |
2 |
Correct |
83 ms |
1584 KB |
Output is correct |
3 |
Correct |
80 ms |
1648 KB |
Output is correct |
4 |
Correct |
76 ms |
1684 KB |
Output is correct |
5 |
Correct |
74 ms |
2364 KB |
Output is correct |
6 |
Correct |
71 ms |
2328 KB |
Output is correct |
7 |
Correct |
75 ms |
2364 KB |
Output is correct |
8 |
Correct |
82 ms |
2480 KB |
Output is correct |
9 |
Correct |
75 ms |
2376 KB |
Output is correct |
10 |
Correct |
76 ms |
2380 KB |
Output is correct |
11 |
Correct |
76 ms |
2408 KB |
Output is correct |
12 |
Correct |
77 ms |
2408 KB |
Output is correct |
13 |
Correct |
77 ms |
2364 KB |
Output is correct |
14 |
Correct |
76 ms |
2456 KB |
Output is correct |
15 |
Correct |
81 ms |
2452 KB |
Output is correct |
16 |
Correct |
75 ms |
2360 KB |
Output is correct |
17 |
Correct |
81 ms |
2436 KB |
Output is correct |
18 |
Correct |
78 ms |
2300 KB |
Output is correct |
19 |
Correct |
79 ms |
2308 KB |
Output is correct |
20 |
Correct |
81 ms |
2248 KB |
Output is correct |
21 |
Correct |
75 ms |
2352 KB |
Output is correct |
22 |
Correct |
70 ms |
2252 KB |
Output is correct |
23 |
Correct |
75 ms |
2376 KB |
Output is correct |
24 |
Correct |
73 ms |
2296 KB |
Output is correct |
25 |
Correct |
77 ms |
2620 KB |
Output is correct |
26 |
Correct |
72 ms |
2256 KB |
Output is correct |
27 |
Correct |
75 ms |
2508 KB |
Output is correct |
28 |
Correct |
69 ms |
2228 KB |
Output is correct |
29 |
Correct |
79 ms |
2456 KB |
Output is correct |
30 |
Correct |
74 ms |
2268 KB |
Output is correct |
31 |
Correct |
76 ms |
2412 KB |
Output is correct |
32 |
Correct |
75 ms |
2420 KB |
Output is correct |
33 |
Correct |
76 ms |
2400 KB |
Output is correct |
34 |
Correct |
70 ms |
2304 KB |
Output is correct |
35 |
Correct |
76 ms |
2416 KB |
Output is correct |
36 |
Correct |
79 ms |
2380 KB |
Output is correct |
37 |
Correct |
75 ms |
2376 KB |
Output is correct |
38 |
Correct |
76 ms |
2416 KB |
Output is correct |
39 |
Correct |
79 ms |
2516 KB |
Output is correct |
40 |
Correct |
77 ms |
2400 KB |
Output is correct |
41 |
Correct |
76 ms |
2408 KB |
Output is correct |
42 |
Correct |
75 ms |
2340 KB |
Output is correct |
43 |
Correct |
74 ms |
2324 KB |
Output is correct |
44 |
Correct |
80 ms |
2380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
1612 KB |
Output is correct |
2 |
Correct |
83 ms |
1584 KB |
Output is correct |
3 |
Correct |
80 ms |
1648 KB |
Output is correct |
4 |
Correct |
76 ms |
1684 KB |
Output is correct |
5 |
Correct |
74 ms |
2364 KB |
Output is correct |
6 |
Correct |
71 ms |
2328 KB |
Output is correct |
7 |
Correct |
75 ms |
2364 KB |
Output is correct |
8 |
Correct |
82 ms |
2480 KB |
Output is correct |
9 |
Correct |
75 ms |
2376 KB |
Output is correct |
10 |
Correct |
76 ms |
2380 KB |
Output is correct |
11 |
Correct |
76 ms |
2408 KB |
Output is correct |
12 |
Correct |
77 ms |
2408 KB |
Output is correct |
13 |
Correct |
77 ms |
2364 KB |
Output is correct |
14 |
Correct |
76 ms |
2456 KB |
Output is correct |
15 |
Correct |
81 ms |
2452 KB |
Output is correct |
16 |
Correct |
75 ms |
2360 KB |
Output is correct |
17 |
Correct |
81 ms |
2436 KB |
Output is correct |
18 |
Correct |
78 ms |
2300 KB |
Output is correct |
19 |
Runtime error |
62 ms |
59784 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |