#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 20;
const ll MAXN = 2e5 + 100;
const ll P = 29;
ll powP[2*MAXN];
ll inv;
struct Node {
ll len, hash;
Node() { }
Node(ll _len, ll _hash) : len(_len), hash(_hash) { }
};
Node merge(Node A, Node B) {
Node new_node;
new_node.hash = (A.hash * powP[B.len] + B.hash) % MOD;
new_node.len = A.len + B.len;
return new_node;
}
set<ll> hashes;
vector<int> new_seq;
vector<int> cross(vector<int> A, vector<int> B) {
int n = A.size();
vector<int> q;
for (int i = 0; i < n; i++)
q.push_back((2 * (A[i] + B[i])) % 3);
return q;
}
Node sg[4*MAXN];
ll lazy[4*MAXN];
ll expo(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 2)
res = (res * a) % MOD;
a = (a * a) % MOD;
b /= 2;
}
return res;
}
void push(int k, int a, int b) {
if (lazy[k] != -1) {
int l = sg[k].len;
sg[k].hash = (lazy[k] * (((powP[l] - 1) * inv) % MOD)) % MOD;
if (a != b) {
lazy[2*k] = lazy[k];
lazy[2*k+1] = lazy[k];
}
lazy[k] = -1;
}
}
void init(int k, int a, int b) {
if (a == b) {
sg[k].len = 1;
sg[k].hash = new_seq[a-1] + 1;
return ;
}
init(2*k, a, (a+b)/2);
init(2*k+1, (a+b)/2+1, b);
sg[k] = merge(sg[2*k], sg[2*k+1]);
}
void update(int k, int a, int b, int q_l, int q_r, int val) {
push(k, a, b);
if (b < q_l || a > q_r)
return ;
if (q_l <= a && b <= q_r) {
lazy[k] = val;
push(k, a, b);
return ;
}
update(2*k, a, (a+b)/2, q_l, q_r, val);
update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
sg[k] = merge(sg[2*k], sg[2*k+1]);
}
int main() {
fast
inv = expo(P-1, MOD-2);
powP[0] = 1;
for (int i = 1; i < 2*MAXN; i++)
powP[i] = (powP[i-1] * P) % MOD;
memset(lazy, -1, sizeof(lazy));
int N;
cin >> N;
vector<int> s[3];
for (int seq = 0; seq < 3; seq++)
for (int i = 0; i < N; i++) {
char ch;
cin >> ch;
s[seq].push_back(ch == 'J' ? 0 : (ch == 'O' ? 1 : 2));
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (i == j && j == k)
continue;
vector<int> c = cross(s[i], s[j]);
c = cross(c, s[k]);
ll hash = 0;
for (int i = 0; i < N; i++)
hash = (hash * P + (c[i] + 1)) % MOD;
hashes.insert(hash);
}
}
}
int q;
cin >> q;
for (int i = 0; i < N; i++) {
char ch;
cin >> ch;
new_seq.push_back(ch == 'J' ? 0 : (ch == 'O' ? 1 : 2));
}
init(1, 1, N);
push(1, 1, N);
if (hashes.count(sg[1].hash))
cout << "Yes\n";
else
cout << "No\n";
while (q--) {
int l, r, val; char ch;
cin >> l >> r >> ch;
val = ch == 'J' ? 0 : (ch == 'O' ? 1 : 2);
update(1, 1, N, l, r, val + 1);
push(1, 1, N);
if (hashes.count(sg[1].hash))
cout << "Yes\n";
else
cout << "No\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
10580 KB |
Output is correct |
2 |
Correct |
66 ms |
10576 KB |
Output is correct |
3 |
Correct |
72 ms |
10564 KB |
Output is correct |
4 |
Correct |
60 ms |
10576 KB |
Output is correct |
5 |
Correct |
59 ms |
10560 KB |
Output is correct |
6 |
Correct |
56 ms |
10576 KB |
Output is correct |
7 |
Correct |
70 ms |
10652 KB |
Output is correct |
8 |
Correct |
66 ms |
10580 KB |
Output is correct |
9 |
Correct |
61 ms |
10580 KB |
Output is correct |
10 |
Correct |
59 ms |
10580 KB |
Output is correct |
11 |
Correct |
60 ms |
10424 KB |
Output is correct |
12 |
Correct |
65 ms |
10704 KB |
Output is correct |
13 |
Correct |
64 ms |
10580 KB |
Output is correct |
14 |
Correct |
62 ms |
10564 KB |
Output is correct |
15 |
Correct |
61 ms |
10580 KB |
Output is correct |
16 |
Correct |
61 ms |
10612 KB |
Output is correct |
17 |
Correct |
64 ms |
10648 KB |
Output is correct |
18 |
Correct |
64 ms |
10572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
10580 KB |
Output is correct |
2 |
Correct |
66 ms |
10576 KB |
Output is correct |
3 |
Correct |
72 ms |
10564 KB |
Output is correct |
4 |
Correct |
60 ms |
10576 KB |
Output is correct |
5 |
Correct |
59 ms |
10560 KB |
Output is correct |
6 |
Correct |
56 ms |
10576 KB |
Output is correct |
7 |
Correct |
70 ms |
10652 KB |
Output is correct |
8 |
Correct |
66 ms |
10580 KB |
Output is correct |
9 |
Correct |
61 ms |
10580 KB |
Output is correct |
10 |
Correct |
59 ms |
10580 KB |
Output is correct |
11 |
Correct |
60 ms |
10424 KB |
Output is correct |
12 |
Correct |
65 ms |
10704 KB |
Output is correct |
13 |
Correct |
64 ms |
10580 KB |
Output is correct |
14 |
Correct |
62 ms |
10564 KB |
Output is correct |
15 |
Correct |
61 ms |
10580 KB |
Output is correct |
16 |
Correct |
61 ms |
10612 KB |
Output is correct |
17 |
Correct |
64 ms |
10648 KB |
Output is correct |
18 |
Correct |
64 ms |
10572 KB |
Output is correct |
19 |
Correct |
272 ms |
23412 KB |
Output is correct |
20 |
Correct |
278 ms |
23640 KB |
Output is correct |
21 |
Correct |
188 ms |
23140 KB |
Output is correct |
22 |
Correct |
191 ms |
22740 KB |
Output is correct |
23 |
Correct |
95 ms |
13012 KB |
Output is correct |
24 |
Correct |
103 ms |
13000 KB |
Output is correct |
25 |
Correct |
203 ms |
23372 KB |
Output is correct |
26 |
Correct |
234 ms |
23388 KB |
Output is correct |
27 |
Correct |
218 ms |
23488 KB |
Output is correct |
28 |
Correct |
273 ms |
23384 KB |
Output is correct |
29 |
Correct |
213 ms |
23344 KB |
Output is correct |
30 |
Correct |
106 ms |
13008 KB |
Output is correct |
31 |
Correct |
226 ms |
23844 KB |
Output is correct |
32 |
Correct |
205 ms |
22908 KB |
Output is correct |
33 |
Correct |
99 ms |
12848 KB |
Output is correct |
34 |
Correct |
220 ms |
23472 KB |
Output is correct |
35 |
Correct |
171 ms |
22284 KB |
Output is correct |
36 |
Correct |
99 ms |
13008 KB |
Output is correct |
37 |
Correct |
95 ms |
12792 KB |
Output is correct |
38 |
Correct |
253 ms |
23668 KB |
Output is correct |
39 |
Correct |
178 ms |
23392 KB |
Output is correct |
40 |
Correct |
159 ms |
17404 KB |
Output is correct |
41 |
Correct |
298 ms |
23700 KB |
Output is correct |
42 |
Correct |
108 ms |
23744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
10580 KB |
Output is correct |
2 |
Correct |
66 ms |
10576 KB |
Output is correct |
3 |
Correct |
72 ms |
10564 KB |
Output is correct |
4 |
Correct |
60 ms |
10576 KB |
Output is correct |
5 |
Correct |
59 ms |
10560 KB |
Output is correct |
6 |
Correct |
56 ms |
10576 KB |
Output is correct |
7 |
Correct |
70 ms |
10652 KB |
Output is correct |
8 |
Correct |
66 ms |
10580 KB |
Output is correct |
9 |
Correct |
61 ms |
10580 KB |
Output is correct |
10 |
Correct |
59 ms |
10580 KB |
Output is correct |
11 |
Correct |
60 ms |
10424 KB |
Output is correct |
12 |
Correct |
65 ms |
10704 KB |
Output is correct |
13 |
Correct |
64 ms |
10580 KB |
Output is correct |
14 |
Correct |
62 ms |
10564 KB |
Output is correct |
15 |
Correct |
61 ms |
10580 KB |
Output is correct |
16 |
Correct |
61 ms |
10612 KB |
Output is correct |
17 |
Correct |
64 ms |
10648 KB |
Output is correct |
18 |
Correct |
64 ms |
10572 KB |
Output is correct |
19 |
Correct |
73 ms |
10544 KB |
Output is correct |
20 |
Correct |
80 ms |
10656 KB |
Output is correct |
21 |
Correct |
63 ms |
10576 KB |
Output is correct |
22 |
Correct |
53 ms |
10544 KB |
Output is correct |
23 |
Correct |
64 ms |
10584 KB |
Output is correct |
24 |
Correct |
58 ms |
10580 KB |
Output is correct |
25 |
Correct |
67 ms |
10600 KB |
Output is correct |
26 |
Correct |
57 ms |
10580 KB |
Output is correct |
27 |
Correct |
59 ms |
10472 KB |
Output is correct |
28 |
Correct |
55 ms |
10412 KB |
Output is correct |
29 |
Correct |
66 ms |
10576 KB |
Output is correct |
30 |
Correct |
57 ms |
10832 KB |
Output is correct |
31 |
Correct |
61 ms |
10576 KB |
Output is correct |
32 |
Correct |
61 ms |
10580 KB |
Output is correct |
33 |
Correct |
64 ms |
10548 KB |
Output is correct |
34 |
Correct |
57 ms |
10576 KB |
Output is correct |
35 |
Correct |
62 ms |
10576 KB |
Output is correct |
36 |
Correct |
64 ms |
10432 KB |
Output is correct |
37 |
Correct |
63 ms |
10580 KB |
Output is correct |
38 |
Correct |
63 ms |
10576 KB |
Output is correct |
39 |
Correct |
63 ms |
10580 KB |
Output is correct |
40 |
Correct |
63 ms |
10592 KB |
Output is correct |
41 |
Correct |
62 ms |
10576 KB |
Output is correct |
42 |
Correct |
63 ms |
10580 KB |
Output is correct |
43 |
Correct |
67 ms |
10440 KB |
Output is correct |
44 |
Correct |
69 ms |
10632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
10580 KB |
Output is correct |
2 |
Correct |
66 ms |
10576 KB |
Output is correct |
3 |
Correct |
72 ms |
10564 KB |
Output is correct |
4 |
Correct |
60 ms |
10576 KB |
Output is correct |
5 |
Correct |
59 ms |
10560 KB |
Output is correct |
6 |
Correct |
56 ms |
10576 KB |
Output is correct |
7 |
Correct |
70 ms |
10652 KB |
Output is correct |
8 |
Correct |
66 ms |
10580 KB |
Output is correct |
9 |
Correct |
61 ms |
10580 KB |
Output is correct |
10 |
Correct |
59 ms |
10580 KB |
Output is correct |
11 |
Correct |
60 ms |
10424 KB |
Output is correct |
12 |
Correct |
65 ms |
10704 KB |
Output is correct |
13 |
Correct |
64 ms |
10580 KB |
Output is correct |
14 |
Correct |
62 ms |
10564 KB |
Output is correct |
15 |
Correct |
61 ms |
10580 KB |
Output is correct |
16 |
Correct |
61 ms |
10612 KB |
Output is correct |
17 |
Correct |
64 ms |
10648 KB |
Output is correct |
18 |
Correct |
64 ms |
10572 KB |
Output is correct |
19 |
Correct |
272 ms |
23412 KB |
Output is correct |
20 |
Correct |
278 ms |
23640 KB |
Output is correct |
21 |
Correct |
188 ms |
23140 KB |
Output is correct |
22 |
Correct |
191 ms |
22740 KB |
Output is correct |
23 |
Correct |
95 ms |
13012 KB |
Output is correct |
24 |
Correct |
103 ms |
13000 KB |
Output is correct |
25 |
Correct |
203 ms |
23372 KB |
Output is correct |
26 |
Correct |
234 ms |
23388 KB |
Output is correct |
27 |
Correct |
218 ms |
23488 KB |
Output is correct |
28 |
Correct |
273 ms |
23384 KB |
Output is correct |
29 |
Correct |
213 ms |
23344 KB |
Output is correct |
30 |
Correct |
106 ms |
13008 KB |
Output is correct |
31 |
Correct |
226 ms |
23844 KB |
Output is correct |
32 |
Correct |
205 ms |
22908 KB |
Output is correct |
33 |
Correct |
99 ms |
12848 KB |
Output is correct |
34 |
Correct |
220 ms |
23472 KB |
Output is correct |
35 |
Correct |
171 ms |
22284 KB |
Output is correct |
36 |
Correct |
99 ms |
13008 KB |
Output is correct |
37 |
Correct |
95 ms |
12792 KB |
Output is correct |
38 |
Correct |
253 ms |
23668 KB |
Output is correct |
39 |
Correct |
178 ms |
23392 KB |
Output is correct |
40 |
Correct |
159 ms |
17404 KB |
Output is correct |
41 |
Correct |
298 ms |
23700 KB |
Output is correct |
42 |
Correct |
108 ms |
23744 KB |
Output is correct |
43 |
Correct |
73 ms |
10544 KB |
Output is correct |
44 |
Correct |
80 ms |
10656 KB |
Output is correct |
45 |
Correct |
63 ms |
10576 KB |
Output is correct |
46 |
Correct |
53 ms |
10544 KB |
Output is correct |
47 |
Correct |
64 ms |
10584 KB |
Output is correct |
48 |
Correct |
58 ms |
10580 KB |
Output is correct |
49 |
Correct |
67 ms |
10600 KB |
Output is correct |
50 |
Correct |
57 ms |
10580 KB |
Output is correct |
51 |
Correct |
59 ms |
10472 KB |
Output is correct |
52 |
Correct |
55 ms |
10412 KB |
Output is correct |
53 |
Correct |
66 ms |
10576 KB |
Output is correct |
54 |
Correct |
57 ms |
10832 KB |
Output is correct |
55 |
Correct |
61 ms |
10576 KB |
Output is correct |
56 |
Correct |
61 ms |
10580 KB |
Output is correct |
57 |
Correct |
64 ms |
10548 KB |
Output is correct |
58 |
Correct |
57 ms |
10576 KB |
Output is correct |
59 |
Correct |
62 ms |
10576 KB |
Output is correct |
60 |
Correct |
64 ms |
10432 KB |
Output is correct |
61 |
Correct |
63 ms |
10580 KB |
Output is correct |
62 |
Correct |
63 ms |
10576 KB |
Output is correct |
63 |
Correct |
63 ms |
10580 KB |
Output is correct |
64 |
Correct |
63 ms |
10592 KB |
Output is correct |
65 |
Correct |
62 ms |
10576 KB |
Output is correct |
66 |
Correct |
63 ms |
10580 KB |
Output is correct |
67 |
Correct |
67 ms |
10440 KB |
Output is correct |
68 |
Correct |
69 ms |
10632 KB |
Output is correct |
69 |
Correct |
239 ms |
22764 KB |
Output is correct |
70 |
Correct |
276 ms |
23392 KB |
Output is correct |
71 |
Correct |
98 ms |
12944 KB |
Output is correct |
72 |
Correct |
100 ms |
12888 KB |
Output is correct |
73 |
Correct |
99 ms |
12816 KB |
Output is correct |
74 |
Correct |
198 ms |
22740 KB |
Output is correct |
75 |
Correct |
98 ms |
12916 KB |
Output is correct |
76 |
Correct |
207 ms |
23484 KB |
Output is correct |
77 |
Correct |
187 ms |
26032 KB |
Output is correct |
78 |
Correct |
102 ms |
15316 KB |
Output is correct |
79 |
Correct |
100 ms |
15312 KB |
Output is correct |
80 |
Correct |
175 ms |
25340 KB |
Output is correct |
81 |
Correct |
101 ms |
15316 KB |
Output is correct |
82 |
Correct |
229 ms |
27216 KB |
Output is correct |
83 |
Correct |
200 ms |
26656 KB |
Output is correct |
84 |
Correct |
103 ms |
15204 KB |
Output is correct |
85 |
Correct |
100 ms |
15192 KB |
Output is correct |
86 |
Correct |
205 ms |
25460 KB |
Output is correct |
87 |
Correct |
230 ms |
27364 KB |
Output is correct |
88 |
Correct |
109 ms |
15192 KB |
Output is correct |
89 |
Correct |
205 ms |
26360 KB |
Output is correct |
90 |
Correct |
228 ms |
27320 KB |
Output is correct |
91 |
Correct |
108 ms |
15316 KB |
Output is correct |
92 |
Correct |
172 ms |
25392 KB |
Output is correct |
93 |
Correct |
100 ms |
15192 KB |
Output is correct |
94 |
Correct |
99 ms |
15312 KB |
Output is correct |
95 |
Correct |
99 ms |
15220 KB |
Output is correct |
96 |
Correct |
239 ms |
27016 KB |
Output is correct |
97 |
Correct |
180 ms |
27120 KB |
Output is correct |
98 |
Correct |
170 ms |
20736 KB |
Output is correct |
99 |
Correct |
293 ms |
27476 KB |
Output is correct |
100 |
Correct |
113 ms |
26716 KB |
Output is correct |