#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18;
vector<string> get_strings(string &xx, string &y, string &z){
string s[3] = {xx, y, z};
int n = int(s[0].length());
map<string, int> mp;
queue<string> q;
vector<string> ret;
for(int l = 0; l < 3; ++l) mp[s[l]] = 1, q.emplace(s[l]), ret.emplace_back(s[l]);
char t[3] = {'J', 'O', 'I'};
int cnt = 0;
while(!q.empty()){
string x = q.front(); q.pop();
string tt = ""; tt.resize(n);
for(string &u : ret){
for(int i = 0; i < n; ++i) if(x[i] == u[i]) tt[i] = x[i];
else{
int a, b;
for(int j = 0; j < 3; ++j) if(t[j] == x[i]) a = j;
for(int j = 0; j < 3; ++j) if(t[j] == u[i]) b = j;
if(a && b) tt[i] = t[0];
else if(max(a, b) > 1) tt[i] = t[1];
else tt[i] = t[2];
}
if(mp[tt] != 1) mp[tt] = 1, q.emplace(tt), ++cnt, ret.emplace_back(tt);//, cout << ":\n" << x << "\n" << u << "\n" << tt << "\n\n";
}
//~ cout << x << "\n";
}
return ret;
}
int base = 1;
struct seg{
vector<ll> t, p, tmp, powp;
ll mod;
void build(int i, int s, int e){
for(int j = s; j <= e; ++j) tmp[i] += powp[j];
int mid = (s+e)>>1;
if(s != e) build(i<<1, s, mid), build(i<<1|1, mid+1, e);
}
void init(int n, ll m, string &s){
while(base < n) base <<= 1;
t.resize(base<<1, 0), tmp.resize(base<<1, 0), powp.resize(base+1), p.resize(base<<1, 0);
mod = m;
powp[0] = 1;
for(int i = 1; i <= base; ++i) powp[i] = powp[i-1]*mod;
build(1, 1, base);
for(int i = 0; i < int(s.length()); ++i) t[i+base] = ll(s[i])*powp[i+1];
for(int i = base-1; i; --i) t[i] = t[i<<1]+t[i<<1|1];
}
void add(int i, ll pr){ t[i] = tmp[i]*pr, p[i] = pr; }
void push(int i){ if(p[i]) add(i<<1, p[i]), add(i<<1|1, p[i]), p[i] = 0; }
void update(int i, int s, int e, int x, int y, ll pr){
if(x <= s && e <= y) return void(add(i, pr));
int mid = (s+e)>>1; push(i);
if(x <= mid) update(i<<1, s, mid, x, y, pr);
if(mid < y) update(i<<1|1, mid+1, e, x, y, pr);
t[i] = t[i<<1]+t[i<<1|1];
}
};
void answer(){
int n, q; scanf("%d", &n);
string s[3] = {"", "", ""}, t="";
char c;
for(int l = 0; l < 3; ++l){
c = getchar_unlocked();
for(int i = 0; i < n; ++i) c = getchar_unlocked(), s[l] += c;
}
scanf("%d\n", &q);
for(int i = 0; i < n; ++i) c = getchar_unlocked(), t += c;
vector<string> st = get_strings(s[0], s[1], s[2]);
vector<ll> powp(n+1); powp[0] = 1;
for(int i = 1; i <= n; ++i) powp[i] = powp[i-1]*97ll;
vector<ll> powp1(n+1); powp1[0] = 1;
for(int i = 1; i <= n; ++i) powp1[i] = powp1[i-1]*1000000007ll;
vector<ll> powp2(n+1); powp2[0] = 1;
for(int i = 1; i <= n; ++i) powp2[i] = powp2[i-1]*2137ll;
unordered_map<ll, bool> mp9, mp10, mp11;
for(string &u : st){
ll hash = 0;
for(int i = 0; i < n; ++i) hash += ll(u[i])*powp[i+1];
mp9[hash] = 1;
hash = 0;
for(int i = 0; i < n; ++i) hash += ll(u[i])*powp1[i+1];
mp10[hash] = 1;
hash = 0;
for(int i = 0; i < n; ++i) hash += ll(u[i])*powp2[i+1];
mp11[hash] = 1;
//~ printf("%lld\n", hash);
}
seg seg, seg2, seg3; seg.init(n+1, 97, t); seg2.init(n+1, 1000000007, t), seg3.init(n+1, 2137, t);
printf(mp9[seg.t[1]] && mp10[seg2.t[1]] && mp11[seg3.t[1]] ? "Yes\n" : "No\n");
//~ printf("%lld\n", seg.t[1]);
for(++q; --q; ){
int a, b;
scanf("%d%d %c", &a, &b, &c);
seg.update(1, 1, base, a, b, ll(c));
seg2.update(1, 1, base, a, b, ll(c));
seg3.update(1, 1, base, a, b, ll(c));
printf(mp9[seg.t[1]] && mp10[seg2.t[1]] && mp11[seg3.t[1]] ? "Yes\n" : "No\n");
//~ printf("%lld\n", seg3.t[1]);
}
}
int main(){
int T = 1;
//~ ios_base::sync_with_stdio(0); cin.tie(0);
for(++T; --T; ) answer();
return 0;
}
Compilation message
Main.cpp: In function 'void answer()':
Main.cpp:69:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | int n, q; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | scanf("%d\n", &q);
| ~~~~~^~~~~~~~~~~~
Main.cpp:107:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | scanf("%d%d %c", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
6848 KB |
Output is correct |
2 |
Correct |
124 ms |
7400 KB |
Output is correct |
3 |
Correct |
127 ms |
3352 KB |
Output is correct |
4 |
Correct |
151 ms |
7288 KB |
Output is correct |
5 |
Correct |
126 ms |
7428 KB |
Output is correct |
6 |
Correct |
103 ms |
6884 KB |
Output is correct |
7 |
Correct |
124 ms |
7256 KB |
Output is correct |
8 |
Correct |
119 ms |
7608 KB |
Output is correct |
9 |
Correct |
140 ms |
7392 KB |
Output is correct |
10 |
Correct |
127 ms |
10432 KB |
Output is correct |
11 |
Correct |
113 ms |
7616 KB |
Output is correct |
12 |
Correct |
141 ms |
10516 KB |
Output is correct |
13 |
Correct |
129 ms |
7620 KB |
Output is correct |
14 |
Correct |
170 ms |
10432 KB |
Output is correct |
15 |
Correct |
114 ms |
7788 KB |
Output is correct |
16 |
Correct |
147 ms |
10396 KB |
Output is correct |
17 |
Correct |
115 ms |
7760 KB |
Output is correct |
18 |
Correct |
103 ms |
2240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
6848 KB |
Output is correct |
2 |
Correct |
124 ms |
7400 KB |
Output is correct |
3 |
Correct |
127 ms |
3352 KB |
Output is correct |
4 |
Correct |
151 ms |
7288 KB |
Output is correct |
5 |
Correct |
126 ms |
7428 KB |
Output is correct |
6 |
Correct |
103 ms |
6884 KB |
Output is correct |
7 |
Correct |
124 ms |
7256 KB |
Output is correct |
8 |
Correct |
119 ms |
7608 KB |
Output is correct |
9 |
Correct |
140 ms |
7392 KB |
Output is correct |
10 |
Correct |
127 ms |
10432 KB |
Output is correct |
11 |
Correct |
113 ms |
7616 KB |
Output is correct |
12 |
Correct |
141 ms |
10516 KB |
Output is correct |
13 |
Correct |
129 ms |
7620 KB |
Output is correct |
14 |
Correct |
170 ms |
10432 KB |
Output is correct |
15 |
Correct |
114 ms |
7788 KB |
Output is correct |
16 |
Correct |
147 ms |
10396 KB |
Output is correct |
17 |
Correct |
115 ms |
7760 KB |
Output is correct |
18 |
Correct |
103 ms |
2240 KB |
Output is correct |
19 |
Correct |
577 ms |
56224 KB |
Output is correct |
20 |
Correct |
537 ms |
56664 KB |
Output is correct |
21 |
Correct |
432 ms |
59092 KB |
Output is correct |
22 |
Correct |
422 ms |
55260 KB |
Output is correct |
23 |
Correct |
202 ms |
13512 KB |
Output is correct |
24 |
Correct |
237 ms |
13520 KB |
Output is correct |
25 |
Correct |
472 ms |
59684 KB |
Output is correct |
26 |
Correct |
471 ms |
56592 KB |
Output is correct |
27 |
Correct |
474 ms |
59520 KB |
Output is correct |
28 |
Correct |
548 ms |
56532 KB |
Output is correct |
29 |
Correct |
472 ms |
59392 KB |
Output is correct |
30 |
Correct |
273 ms |
13368 KB |
Output is correct |
31 |
Correct |
480 ms |
59516 KB |
Output is correct |
32 |
Correct |
480 ms |
55956 KB |
Output is correct |
33 |
Correct |
216 ms |
13396 KB |
Output is correct |
34 |
Correct |
464 ms |
56592 KB |
Output is correct |
35 |
Correct |
375 ms |
55080 KB |
Output is correct |
36 |
Correct |
235 ms |
13448 KB |
Output is correct |
37 |
Correct |
234 ms |
13388 KB |
Output is correct |
38 |
Correct |
386 ms |
55424 KB |
Output is correct |
39 |
Correct |
208 ms |
54776 KB |
Output is correct |
40 |
Incorrect |
374 ms |
54572 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
6848 KB |
Output is correct |
2 |
Correct |
124 ms |
7400 KB |
Output is correct |
3 |
Correct |
127 ms |
3352 KB |
Output is correct |
4 |
Correct |
151 ms |
7288 KB |
Output is correct |
5 |
Correct |
126 ms |
7428 KB |
Output is correct |
6 |
Correct |
103 ms |
6884 KB |
Output is correct |
7 |
Correct |
124 ms |
7256 KB |
Output is correct |
8 |
Correct |
119 ms |
7608 KB |
Output is correct |
9 |
Correct |
140 ms |
7392 KB |
Output is correct |
10 |
Correct |
127 ms |
10432 KB |
Output is correct |
11 |
Correct |
113 ms |
7616 KB |
Output is correct |
12 |
Correct |
141 ms |
10516 KB |
Output is correct |
13 |
Correct |
129 ms |
7620 KB |
Output is correct |
14 |
Correct |
170 ms |
10432 KB |
Output is correct |
15 |
Correct |
114 ms |
7788 KB |
Output is correct |
16 |
Correct |
147 ms |
10396 KB |
Output is correct |
17 |
Correct |
115 ms |
7760 KB |
Output is correct |
18 |
Correct |
103 ms |
2240 KB |
Output is correct |
19 |
Correct |
126 ms |
7004 KB |
Output is correct |
20 |
Correct |
127 ms |
3400 KB |
Output is correct |
21 |
Correct |
131 ms |
10572 KB |
Output is correct |
22 |
Correct |
130 ms |
6856 KB |
Output is correct |
23 |
Correct |
124 ms |
10444 KB |
Output is correct |
24 |
Correct |
148 ms |
7268 KB |
Output is correct |
25 |
Correct |
133 ms |
10440 KB |
Output is correct |
26 |
Correct |
120 ms |
7116 KB |
Output is correct |
27 |
Correct |
130 ms |
10568 KB |
Output is correct |
28 |
Correct |
125 ms |
7216 KB |
Output is correct |
29 |
Correct |
126 ms |
7544 KB |
Output is correct |
30 |
Correct |
108 ms |
6852 KB |
Output is correct |
31 |
Correct |
120 ms |
10464 KB |
Output is correct |
32 |
Correct |
134 ms |
10376 KB |
Output is correct |
33 |
Correct |
132 ms |
7500 KB |
Output is correct |
34 |
Correct |
124 ms |
7188 KB |
Output is correct |
35 |
Correct |
182 ms |
10340 KB |
Output is correct |
36 |
Correct |
125 ms |
7660 KB |
Output is correct |
37 |
Correct |
127 ms |
10432 KB |
Output is correct |
38 |
Correct |
124 ms |
7624 KB |
Output is correct |
39 |
Correct |
118 ms |
10424 KB |
Output is correct |
40 |
Correct |
134 ms |
7660 KB |
Output is correct |
41 |
Correct |
117 ms |
10432 KB |
Output is correct |
42 |
Correct |
137 ms |
7644 KB |
Output is correct |
43 |
Correct |
161 ms |
7324 KB |
Output is correct |
44 |
Correct |
129 ms |
7468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
6848 KB |
Output is correct |
2 |
Correct |
124 ms |
7400 KB |
Output is correct |
3 |
Correct |
127 ms |
3352 KB |
Output is correct |
4 |
Correct |
151 ms |
7288 KB |
Output is correct |
5 |
Correct |
126 ms |
7428 KB |
Output is correct |
6 |
Correct |
103 ms |
6884 KB |
Output is correct |
7 |
Correct |
124 ms |
7256 KB |
Output is correct |
8 |
Correct |
119 ms |
7608 KB |
Output is correct |
9 |
Correct |
140 ms |
7392 KB |
Output is correct |
10 |
Correct |
127 ms |
10432 KB |
Output is correct |
11 |
Correct |
113 ms |
7616 KB |
Output is correct |
12 |
Correct |
141 ms |
10516 KB |
Output is correct |
13 |
Correct |
129 ms |
7620 KB |
Output is correct |
14 |
Correct |
170 ms |
10432 KB |
Output is correct |
15 |
Correct |
114 ms |
7788 KB |
Output is correct |
16 |
Correct |
147 ms |
10396 KB |
Output is correct |
17 |
Correct |
115 ms |
7760 KB |
Output is correct |
18 |
Correct |
103 ms |
2240 KB |
Output is correct |
19 |
Correct |
577 ms |
56224 KB |
Output is correct |
20 |
Correct |
537 ms |
56664 KB |
Output is correct |
21 |
Correct |
432 ms |
59092 KB |
Output is correct |
22 |
Correct |
422 ms |
55260 KB |
Output is correct |
23 |
Correct |
202 ms |
13512 KB |
Output is correct |
24 |
Correct |
237 ms |
13520 KB |
Output is correct |
25 |
Correct |
472 ms |
59684 KB |
Output is correct |
26 |
Correct |
471 ms |
56592 KB |
Output is correct |
27 |
Correct |
474 ms |
59520 KB |
Output is correct |
28 |
Correct |
548 ms |
56532 KB |
Output is correct |
29 |
Correct |
472 ms |
59392 KB |
Output is correct |
30 |
Correct |
273 ms |
13368 KB |
Output is correct |
31 |
Correct |
480 ms |
59516 KB |
Output is correct |
32 |
Correct |
480 ms |
55956 KB |
Output is correct |
33 |
Correct |
216 ms |
13396 KB |
Output is correct |
34 |
Correct |
464 ms |
56592 KB |
Output is correct |
35 |
Correct |
375 ms |
55080 KB |
Output is correct |
36 |
Correct |
235 ms |
13448 KB |
Output is correct |
37 |
Correct |
234 ms |
13388 KB |
Output is correct |
38 |
Correct |
386 ms |
55424 KB |
Output is correct |
39 |
Correct |
208 ms |
54776 KB |
Output is correct |
40 |
Incorrect |
374 ms |
54572 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |