# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
885088 |
2023-12-09T01:28:28 Z |
Keys |
Crossing (JOI21_crossing) |
C++14 |
|
199 ms |
16552 KB |
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define endl '\n'
#define dbg(x) cerr << #x << " = " << x << endl;
typedef vector<int> vi;
typedef vector<string> vs;
const int base = 9973, mod = 1e9 + 7, N = 2e5 + 5;
int n, q, p[N], psum[N], st[N * 4], rset[N * 4];
string a[3], t;
set<int> se;
string joi = "$JOI";
int hash_c(char c) {
if (c == 'J') return 1;
else if (c == 'O') return 2;
else return 3;
}
int hash_s(string s) {
int ret = 0;
for (int i = 0; i < int(s.size()); i++) (ret += p[i] * hash_c(s[i]) % mod) %= mod;
return ret;
}
void pull(int v, int l, int r) {
int m = (l + r) / 2;
st[v] = (st[2 * v] + st[2 * v + 1] * p[m - l + 1] % mod) % mod;
}
void push(int v, int l, int r) {
if (rset[v] == 0) return;
int m = (l + r) / 2;
rset[2 * v + 1] = rset[2 * v] = rset[v];
st[v] = rset[v] * psum[r - l + 1] % mod;
rset[v] = 0;
}
void build(int v = 1, int l = 0, int r = n - 1) {
if (l == r) {
st[v] = hash_c(t[l]);
} else {
int m = (l + r) / 2;
build(v * 2, l, m);
build(v * 2 + 1, m + 1, r);
pull(v, l, r);
}
}
void upd(int ql, int qr, int x, int v = 1, int l = 0, int r = n - 1) {
push(v, l, r);
if (qr < l or ql > r) return;
if (l >= ql and r <= qr) {
rset[v] = x;
push(v, l, r);
return;
}
int m = (l + r) / 2;
upd(ql, qr, x, v * 2, l, m);
upd(ql, qr, x, v * 2 + 1, m + 1, r);
pull(v, l, r);
}
void comb(vs a) {
string s = a[0];
for (int i = 1; i < int(a.size()); i++) {
string ns = "";
for (int j = 0; j < n; j++) {
if (s[j] == a[i][j]) ns += s[j];
else ns += joi[6 - hash_c(s[j]) - hash_c(a[i][j])];
}
s = ns;
}
se.insert(hash_s(s));
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
p[0] = 1; for (int i = 1; i < N; i++) p[i] = p[i - 1] * base % mod;
for (int i = 1; i < N; i++) psum[i] = (psum[i - 1] + p[i - 1]) % mod;
cin >> n >> a[0] >> a[1] >> a[2] >> q >> t;
build();
comb({a[0]}); comb({a[1]}); comb({a[2]}); comb({a[0], a[1]}); comb({a[0], a[2]}); comb({a[1], a[2]});
comb({a[0], a[1], a[2]}); comb({a[0], a[2], a[1]}); comb({a[1], a[2], a[0]});
if (se.count(st[1])) cout << "Yes" << endl;
else cout << "No" << endl;
while (q--) {
int l, r; char c; cin >> l >> r >> c; int o = hash_c(c); l--; r--;
upd(l, r, o);
if (se.count(st[1])) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
Compilation message
Main.cpp: In function 'void push(int64_t, int64_t, int64_t)':
Main.cpp:37:7: warning: unused variable 'm' [-Wunused-variable]
37 | int m = (l + r) / 2;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
5972 KB |
Output is correct |
2 |
Correct |
67 ms |
6044 KB |
Output is correct |
3 |
Correct |
69 ms |
6220 KB |
Output is correct |
4 |
Correct |
60 ms |
6112 KB |
Output is correct |
5 |
Correct |
59 ms |
6228 KB |
Output is correct |
6 |
Correct |
60 ms |
6168 KB |
Output is correct |
7 |
Correct |
62 ms |
6236 KB |
Output is correct |
8 |
Correct |
61 ms |
6228 KB |
Output is correct |
9 |
Correct |
61 ms |
6240 KB |
Output is correct |
10 |
Correct |
62 ms |
6228 KB |
Output is correct |
11 |
Correct |
63 ms |
6240 KB |
Output is correct |
12 |
Correct |
60 ms |
6092 KB |
Output is correct |
13 |
Correct |
64 ms |
6228 KB |
Output is correct |
14 |
Correct |
61 ms |
6384 KB |
Output is correct |
15 |
Correct |
62 ms |
6188 KB |
Output is correct |
16 |
Correct |
62 ms |
6148 KB |
Output is correct |
17 |
Correct |
62 ms |
6228 KB |
Output is correct |
18 |
Correct |
66 ms |
6168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
5972 KB |
Output is correct |
2 |
Correct |
67 ms |
6044 KB |
Output is correct |
3 |
Correct |
69 ms |
6220 KB |
Output is correct |
4 |
Correct |
60 ms |
6112 KB |
Output is correct |
5 |
Correct |
59 ms |
6228 KB |
Output is correct |
6 |
Correct |
60 ms |
6168 KB |
Output is correct |
7 |
Correct |
62 ms |
6236 KB |
Output is correct |
8 |
Correct |
61 ms |
6228 KB |
Output is correct |
9 |
Correct |
61 ms |
6240 KB |
Output is correct |
10 |
Correct |
62 ms |
6228 KB |
Output is correct |
11 |
Correct |
63 ms |
6240 KB |
Output is correct |
12 |
Correct |
60 ms |
6092 KB |
Output is correct |
13 |
Correct |
64 ms |
6228 KB |
Output is correct |
14 |
Correct |
61 ms |
6384 KB |
Output is correct |
15 |
Correct |
62 ms |
6188 KB |
Output is correct |
16 |
Correct |
62 ms |
6148 KB |
Output is correct |
17 |
Correct |
62 ms |
6228 KB |
Output is correct |
18 |
Correct |
66 ms |
6168 KB |
Output is correct |
19 |
Correct |
199 ms |
16552 KB |
Output is correct |
20 |
Correct |
195 ms |
14720 KB |
Output is correct |
21 |
Incorrect |
132 ms |
16356 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
5972 KB |
Output is correct |
2 |
Correct |
67 ms |
6044 KB |
Output is correct |
3 |
Correct |
69 ms |
6220 KB |
Output is correct |
4 |
Correct |
60 ms |
6112 KB |
Output is correct |
5 |
Correct |
59 ms |
6228 KB |
Output is correct |
6 |
Correct |
60 ms |
6168 KB |
Output is correct |
7 |
Correct |
62 ms |
6236 KB |
Output is correct |
8 |
Correct |
61 ms |
6228 KB |
Output is correct |
9 |
Correct |
61 ms |
6240 KB |
Output is correct |
10 |
Correct |
62 ms |
6228 KB |
Output is correct |
11 |
Correct |
63 ms |
6240 KB |
Output is correct |
12 |
Correct |
60 ms |
6092 KB |
Output is correct |
13 |
Correct |
64 ms |
6228 KB |
Output is correct |
14 |
Correct |
61 ms |
6384 KB |
Output is correct |
15 |
Correct |
62 ms |
6188 KB |
Output is correct |
16 |
Correct |
62 ms |
6148 KB |
Output is correct |
17 |
Correct |
62 ms |
6228 KB |
Output is correct |
18 |
Correct |
66 ms |
6168 KB |
Output is correct |
19 |
Correct |
70 ms |
6336 KB |
Output is correct |
20 |
Correct |
71 ms |
6044 KB |
Output is correct |
21 |
Correct |
75 ms |
6196 KB |
Output is correct |
22 |
Correct |
85 ms |
6228 KB |
Output is correct |
23 |
Correct |
61 ms |
6228 KB |
Output is correct |
24 |
Correct |
84 ms |
6384 KB |
Output is correct |
25 |
Correct |
63 ms |
6100 KB |
Output is correct |
26 |
Correct |
91 ms |
6232 KB |
Output is correct |
27 |
Correct |
63 ms |
6228 KB |
Output is correct |
28 |
Correct |
55 ms |
6212 KB |
Output is correct |
29 |
Correct |
63 ms |
6224 KB |
Output is correct |
30 |
Correct |
57 ms |
6144 KB |
Output is correct |
31 |
Correct |
64 ms |
6180 KB |
Output is correct |
32 |
Correct |
64 ms |
6224 KB |
Output is correct |
33 |
Correct |
63 ms |
6228 KB |
Output is correct |
34 |
Correct |
58 ms |
6228 KB |
Output is correct |
35 |
Correct |
64 ms |
6224 KB |
Output is correct |
36 |
Correct |
65 ms |
6224 KB |
Output is correct |
37 |
Correct |
64 ms |
6180 KB |
Output is correct |
38 |
Correct |
79 ms |
6100 KB |
Output is correct |
39 |
Correct |
64 ms |
6224 KB |
Output is correct |
40 |
Correct |
65 ms |
6084 KB |
Output is correct |
41 |
Correct |
63 ms |
6044 KB |
Output is correct |
42 |
Correct |
64 ms |
6224 KB |
Output is correct |
43 |
Correct |
68 ms |
6036 KB |
Output is correct |
44 |
Correct |
64 ms |
6272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
5972 KB |
Output is correct |
2 |
Correct |
67 ms |
6044 KB |
Output is correct |
3 |
Correct |
69 ms |
6220 KB |
Output is correct |
4 |
Correct |
60 ms |
6112 KB |
Output is correct |
5 |
Correct |
59 ms |
6228 KB |
Output is correct |
6 |
Correct |
60 ms |
6168 KB |
Output is correct |
7 |
Correct |
62 ms |
6236 KB |
Output is correct |
8 |
Correct |
61 ms |
6228 KB |
Output is correct |
9 |
Correct |
61 ms |
6240 KB |
Output is correct |
10 |
Correct |
62 ms |
6228 KB |
Output is correct |
11 |
Correct |
63 ms |
6240 KB |
Output is correct |
12 |
Correct |
60 ms |
6092 KB |
Output is correct |
13 |
Correct |
64 ms |
6228 KB |
Output is correct |
14 |
Correct |
61 ms |
6384 KB |
Output is correct |
15 |
Correct |
62 ms |
6188 KB |
Output is correct |
16 |
Correct |
62 ms |
6148 KB |
Output is correct |
17 |
Correct |
62 ms |
6228 KB |
Output is correct |
18 |
Correct |
66 ms |
6168 KB |
Output is correct |
19 |
Correct |
199 ms |
16552 KB |
Output is correct |
20 |
Correct |
195 ms |
14720 KB |
Output is correct |
21 |
Incorrect |
132 ms |
16356 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |