# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
683212 |
2023-01-17T23:21:48 Z |
NK_ |
Crossing (JOI21_crossing) |
C++17 |
|
502 ms |
27536 KB |
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
using ll = long long;
using str = string;
const int MOD = 1e9 + 7;
struct Seg {
const ll ID = 0;
vector<ll> pw, P;
vector<ll> seg, lz, LX, RX; int N, B; ll cmb(int a, int b) {
int len = RX[a] - LX[a] + 1;
return (seg[a] + (pw[__lg(len)] * seg[b])) % MOD;
};
void init(int n, int b) {
N = 1; while(N < n) N *= 2;
B = b;
seg.assign(2*N, ID), lz.assign(2*N, ID);
LX.assign(2*N, -1), RX.assign(2*N, -1);
pw = {B}; for(int i = 1; i <= __lg(N); i++) pw.push_back((pw.back() * 1LL * pw.back()) % MOD);
P = {1}; for(int i = 1; i <= __lg(N); i++) P.push_back(((P.back() * pw[i - 1]) + P.back()) % MOD);
build(1, 0, N-1);
}
void pull(int x) { seg[x] = cmb(2*x, 2*x+1); }
void push(int x, int L, int R) {
if (lz[x] == ID) return;
seg[x] = (P[__lg(R-L+1)] * lz[x]) % MOD;
// cerr << x << " " << L << " " << R << " => " << seg[x] << nl;
if (L != R) for(int i = 0; i < 2; i++) lz[2*x+i] = lz[x];
lz[x] = ID;
}
void build(int x, int L, int R) {
LX[x] = L, RX[x] = R;
if (L == R) return;
int M = (L+R)/2; build(2*x, L, M);
build(2*x+1, M+1, R);
}
void upd(int l, int r, int v, int x, int L, int R) {
push(x, L, R); if (r < L || R < l) return;
if (l <= L && R <= r) { lz[x] = v; push(x, L, R); return; }
int M = (L+R)/2; upd(l, r, v, 2*x, L, M);
upd(l, r, v, 2*x+1, M+1, R); pull(x);
}
ll get() { return seg[1]; }
void upd(int l, int r, int v) { upd(l, r, v, 1, 0, N-1); }
};
const ll BASE = 1009;
int main() {
cin.tie(0)->sync_with_stdio(0);
unordered_map<char, int> TO; TO['J'] = 1; TO['O'] = 2; TO['I'] = 3;
int N; cin >> N;
vector<str> A(3); for(auto &x : A) cin >> x;
str R;
auto comb = [&](const str &S, const str &T) {
R = "";
for(int i = 0; i < int(size(S)); i++) {
if (S[i] == T[i]) R += S[i];
else R += char('J' + 'O' + 'I' - S[i] - T[i]);
}
return R;
};
for(int _ = 0; _ < 2; _++) {
vector<str> add;
for(int i = 0; i < int(size(A)); i++) for(int j = i+1; j < int(size(A)); j++) {
add.push_back(comb(A[i], A[j]));
}
for(const auto &x : add) A.push_back(x);
sort(begin(A), end(A));
A.erase(unique(begin(A), end(A)), end(A));
}
vector<ll> HSH;
auto HASH = [&](const str& S) {
ll b = 1, H = 0;
for(auto c : S) {
H = (H + (b * TO[c])) % MOD;
b = (b * BASE) % MOD;
}
return H;
};
for(const str& x : A) HSH.push_back(HASH(x));
auto check = [&](const ll &x) -> bool {
for(const auto &v : HSH) if (v == x) return 1;
return 0;
};
Seg st; st.init(N, BASE);
int Q; cin >> Q;
str T; cin >> T;
for(int i = 0; i < N; i++) st.upd(i, i, TO[T[i]]);
cout << (check(st.get()) ? "Yes" : "No") << nl;
for(int q = 0; q < Q; q++) {
int l, r; char c; cin >> l >> r >> c; --l, --r;
st.upd(l, r, TO[c]);
cout << (check(st.get()) ? "Yes" : "No") << nl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
2236 KB |
Output is correct |
2 |
Correct |
124 ms |
2448 KB |
Output is correct |
3 |
Correct |
97 ms |
2276 KB |
Output is correct |
4 |
Correct |
93 ms |
2244 KB |
Output is correct |
5 |
Correct |
67 ms |
2232 KB |
Output is correct |
6 |
Correct |
82 ms |
2224 KB |
Output is correct |
7 |
Correct |
79 ms |
2380 KB |
Output is correct |
8 |
Correct |
71 ms |
2332 KB |
Output is correct |
9 |
Correct |
71 ms |
2388 KB |
Output is correct |
10 |
Correct |
76 ms |
2416 KB |
Output is correct |
11 |
Correct |
78 ms |
2384 KB |
Output is correct |
12 |
Correct |
72 ms |
2432 KB |
Output is correct |
13 |
Correct |
71 ms |
2380 KB |
Output is correct |
14 |
Correct |
117 ms |
2424 KB |
Output is correct |
15 |
Correct |
82 ms |
2404 KB |
Output is correct |
16 |
Correct |
71 ms |
2380 KB |
Output is correct |
17 |
Correct |
92 ms |
2480 KB |
Output is correct |
18 |
Correct |
88 ms |
2332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
2236 KB |
Output is correct |
2 |
Correct |
124 ms |
2448 KB |
Output is correct |
3 |
Correct |
97 ms |
2276 KB |
Output is correct |
4 |
Correct |
93 ms |
2244 KB |
Output is correct |
5 |
Correct |
67 ms |
2232 KB |
Output is correct |
6 |
Correct |
82 ms |
2224 KB |
Output is correct |
7 |
Correct |
79 ms |
2380 KB |
Output is correct |
8 |
Correct |
71 ms |
2332 KB |
Output is correct |
9 |
Correct |
71 ms |
2388 KB |
Output is correct |
10 |
Correct |
76 ms |
2416 KB |
Output is correct |
11 |
Correct |
78 ms |
2384 KB |
Output is correct |
12 |
Correct |
72 ms |
2432 KB |
Output is correct |
13 |
Correct |
71 ms |
2380 KB |
Output is correct |
14 |
Correct |
117 ms |
2424 KB |
Output is correct |
15 |
Correct |
82 ms |
2404 KB |
Output is correct |
16 |
Correct |
71 ms |
2380 KB |
Output is correct |
17 |
Correct |
92 ms |
2480 KB |
Output is correct |
18 |
Correct |
88 ms |
2332 KB |
Output is correct |
19 |
Correct |
368 ms |
21900 KB |
Output is correct |
20 |
Correct |
352 ms |
21648 KB |
Output is correct |
21 |
Correct |
264 ms |
21588 KB |
Output is correct |
22 |
Correct |
253 ms |
21376 KB |
Output is correct |
23 |
Correct |
122 ms |
4412 KB |
Output is correct |
24 |
Correct |
122 ms |
4308 KB |
Output is correct |
25 |
Correct |
289 ms |
21812 KB |
Output is correct |
26 |
Correct |
376 ms |
21860 KB |
Output is correct |
27 |
Correct |
323 ms |
21892 KB |
Output is correct |
28 |
Correct |
330 ms |
21752 KB |
Output is correct |
29 |
Correct |
336 ms |
21800 KB |
Output is correct |
30 |
Correct |
167 ms |
4420 KB |
Output is correct |
31 |
Correct |
296 ms |
21836 KB |
Output is correct |
32 |
Correct |
297 ms |
21672 KB |
Output is correct |
33 |
Correct |
139 ms |
4396 KB |
Output is correct |
34 |
Correct |
339 ms |
21808 KB |
Output is correct |
35 |
Correct |
262 ms |
21096 KB |
Output is correct |
36 |
Correct |
147 ms |
4376 KB |
Output is correct |
37 |
Correct |
116 ms |
4392 KB |
Output is correct |
38 |
Correct |
320 ms |
21624 KB |
Output is correct |
39 |
Correct |
216 ms |
21896 KB |
Output is correct |
40 |
Correct |
212 ms |
13100 KB |
Output is correct |
41 |
Correct |
502 ms |
21948 KB |
Output is correct |
42 |
Correct |
156 ms |
21272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
2236 KB |
Output is correct |
2 |
Correct |
124 ms |
2448 KB |
Output is correct |
3 |
Correct |
97 ms |
2276 KB |
Output is correct |
4 |
Correct |
93 ms |
2244 KB |
Output is correct |
5 |
Correct |
67 ms |
2232 KB |
Output is correct |
6 |
Correct |
82 ms |
2224 KB |
Output is correct |
7 |
Correct |
79 ms |
2380 KB |
Output is correct |
8 |
Correct |
71 ms |
2332 KB |
Output is correct |
9 |
Correct |
71 ms |
2388 KB |
Output is correct |
10 |
Correct |
76 ms |
2416 KB |
Output is correct |
11 |
Correct |
78 ms |
2384 KB |
Output is correct |
12 |
Correct |
72 ms |
2432 KB |
Output is correct |
13 |
Correct |
71 ms |
2380 KB |
Output is correct |
14 |
Correct |
117 ms |
2424 KB |
Output is correct |
15 |
Correct |
82 ms |
2404 KB |
Output is correct |
16 |
Correct |
71 ms |
2380 KB |
Output is correct |
17 |
Correct |
92 ms |
2480 KB |
Output is correct |
18 |
Correct |
88 ms |
2332 KB |
Output is correct |
19 |
Correct |
89 ms |
2248 KB |
Output is correct |
20 |
Correct |
86 ms |
2228 KB |
Output is correct |
21 |
Correct |
92 ms |
2404 KB |
Output is correct |
22 |
Correct |
66 ms |
2260 KB |
Output is correct |
23 |
Correct |
91 ms |
2372 KB |
Output is correct |
24 |
Correct |
114 ms |
2296 KB |
Output is correct |
25 |
Correct |
70 ms |
2428 KB |
Output is correct |
26 |
Correct |
68 ms |
2256 KB |
Output is correct |
27 |
Correct |
123 ms |
2396 KB |
Output is correct |
28 |
Correct |
69 ms |
2172 KB |
Output is correct |
29 |
Correct |
93 ms |
2444 KB |
Output is correct |
30 |
Correct |
72 ms |
2260 KB |
Output is correct |
31 |
Correct |
153 ms |
2452 KB |
Output is correct |
32 |
Correct |
70 ms |
2376 KB |
Output is correct |
33 |
Correct |
76 ms |
2452 KB |
Output is correct |
34 |
Correct |
69 ms |
2424 KB |
Output is correct |
35 |
Correct |
98 ms |
2416 KB |
Output is correct |
36 |
Correct |
78 ms |
2380 KB |
Output is correct |
37 |
Correct |
74 ms |
2440 KB |
Output is correct |
38 |
Correct |
79 ms |
2344 KB |
Output is correct |
39 |
Correct |
87 ms |
2392 KB |
Output is correct |
40 |
Correct |
92 ms |
2448 KB |
Output is correct |
41 |
Correct |
72 ms |
2372 KB |
Output is correct |
42 |
Correct |
74 ms |
2352 KB |
Output is correct |
43 |
Correct |
89 ms |
2364 KB |
Output is correct |
44 |
Correct |
81 ms |
2340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
2236 KB |
Output is correct |
2 |
Correct |
124 ms |
2448 KB |
Output is correct |
3 |
Correct |
97 ms |
2276 KB |
Output is correct |
4 |
Correct |
93 ms |
2244 KB |
Output is correct |
5 |
Correct |
67 ms |
2232 KB |
Output is correct |
6 |
Correct |
82 ms |
2224 KB |
Output is correct |
7 |
Correct |
79 ms |
2380 KB |
Output is correct |
8 |
Correct |
71 ms |
2332 KB |
Output is correct |
9 |
Correct |
71 ms |
2388 KB |
Output is correct |
10 |
Correct |
76 ms |
2416 KB |
Output is correct |
11 |
Correct |
78 ms |
2384 KB |
Output is correct |
12 |
Correct |
72 ms |
2432 KB |
Output is correct |
13 |
Correct |
71 ms |
2380 KB |
Output is correct |
14 |
Correct |
117 ms |
2424 KB |
Output is correct |
15 |
Correct |
82 ms |
2404 KB |
Output is correct |
16 |
Correct |
71 ms |
2380 KB |
Output is correct |
17 |
Correct |
92 ms |
2480 KB |
Output is correct |
18 |
Correct |
88 ms |
2332 KB |
Output is correct |
19 |
Correct |
368 ms |
21900 KB |
Output is correct |
20 |
Correct |
352 ms |
21648 KB |
Output is correct |
21 |
Correct |
264 ms |
21588 KB |
Output is correct |
22 |
Correct |
253 ms |
21376 KB |
Output is correct |
23 |
Correct |
122 ms |
4412 KB |
Output is correct |
24 |
Correct |
122 ms |
4308 KB |
Output is correct |
25 |
Correct |
289 ms |
21812 KB |
Output is correct |
26 |
Correct |
376 ms |
21860 KB |
Output is correct |
27 |
Correct |
323 ms |
21892 KB |
Output is correct |
28 |
Correct |
330 ms |
21752 KB |
Output is correct |
29 |
Correct |
336 ms |
21800 KB |
Output is correct |
30 |
Correct |
167 ms |
4420 KB |
Output is correct |
31 |
Correct |
296 ms |
21836 KB |
Output is correct |
32 |
Correct |
297 ms |
21672 KB |
Output is correct |
33 |
Correct |
139 ms |
4396 KB |
Output is correct |
34 |
Correct |
339 ms |
21808 KB |
Output is correct |
35 |
Correct |
262 ms |
21096 KB |
Output is correct |
36 |
Correct |
147 ms |
4376 KB |
Output is correct |
37 |
Correct |
116 ms |
4392 KB |
Output is correct |
38 |
Correct |
320 ms |
21624 KB |
Output is correct |
39 |
Correct |
216 ms |
21896 KB |
Output is correct |
40 |
Correct |
212 ms |
13100 KB |
Output is correct |
41 |
Correct |
502 ms |
21948 KB |
Output is correct |
42 |
Correct |
156 ms |
21272 KB |
Output is correct |
43 |
Correct |
89 ms |
2248 KB |
Output is correct |
44 |
Correct |
86 ms |
2228 KB |
Output is correct |
45 |
Correct |
92 ms |
2404 KB |
Output is correct |
46 |
Correct |
66 ms |
2260 KB |
Output is correct |
47 |
Correct |
91 ms |
2372 KB |
Output is correct |
48 |
Correct |
114 ms |
2296 KB |
Output is correct |
49 |
Correct |
70 ms |
2428 KB |
Output is correct |
50 |
Correct |
68 ms |
2256 KB |
Output is correct |
51 |
Correct |
123 ms |
2396 KB |
Output is correct |
52 |
Correct |
69 ms |
2172 KB |
Output is correct |
53 |
Correct |
93 ms |
2444 KB |
Output is correct |
54 |
Correct |
72 ms |
2260 KB |
Output is correct |
55 |
Correct |
153 ms |
2452 KB |
Output is correct |
56 |
Correct |
70 ms |
2376 KB |
Output is correct |
57 |
Correct |
76 ms |
2452 KB |
Output is correct |
58 |
Correct |
69 ms |
2424 KB |
Output is correct |
59 |
Correct |
98 ms |
2416 KB |
Output is correct |
60 |
Correct |
78 ms |
2380 KB |
Output is correct |
61 |
Correct |
74 ms |
2440 KB |
Output is correct |
62 |
Correct |
79 ms |
2344 KB |
Output is correct |
63 |
Correct |
87 ms |
2392 KB |
Output is correct |
64 |
Correct |
92 ms |
2448 KB |
Output is correct |
65 |
Correct |
72 ms |
2372 KB |
Output is correct |
66 |
Correct |
74 ms |
2352 KB |
Output is correct |
67 |
Correct |
89 ms |
2364 KB |
Output is correct |
68 |
Correct |
81 ms |
2340 KB |
Output is correct |
69 |
Correct |
341 ms |
25056 KB |
Output is correct |
70 |
Correct |
418 ms |
26836 KB |
Output is correct |
71 |
Correct |
124 ms |
4396 KB |
Output is correct |
72 |
Correct |
121 ms |
4428 KB |
Output is correct |
73 |
Correct |
132 ms |
4424 KB |
Output is correct |
74 |
Correct |
263 ms |
21976 KB |
Output is correct |
75 |
Correct |
116 ms |
4380 KB |
Output is correct |
76 |
Correct |
340 ms |
22152 KB |
Output is correct |
77 |
Correct |
250 ms |
21656 KB |
Output is correct |
78 |
Correct |
114 ms |
4428 KB |
Output is correct |
79 |
Correct |
118 ms |
4316 KB |
Output is correct |
80 |
Correct |
261 ms |
24796 KB |
Output is correct |
81 |
Correct |
120 ms |
4676 KB |
Output is correct |
82 |
Correct |
328 ms |
27484 KB |
Output is correct |
83 |
Correct |
358 ms |
26796 KB |
Output is correct |
84 |
Correct |
125 ms |
4624 KB |
Output is correct |
85 |
Correct |
122 ms |
4576 KB |
Output is correct |
86 |
Correct |
302 ms |
25508 KB |
Output is correct |
87 |
Correct |
326 ms |
26700 KB |
Output is correct |
88 |
Correct |
124 ms |
4700 KB |
Output is correct |
89 |
Correct |
307 ms |
26360 KB |
Output is correct |
90 |
Correct |
337 ms |
27228 KB |
Output is correct |
91 |
Correct |
134 ms |
4576 KB |
Output is correct |
92 |
Correct |
271 ms |
25724 KB |
Output is correct |
93 |
Correct |
144 ms |
4684 KB |
Output is correct |
94 |
Correct |
145 ms |
4592 KB |
Output is correct |
95 |
Correct |
116 ms |
4708 KB |
Output is correct |
96 |
Correct |
269 ms |
21600 KB |
Output is correct |
97 |
Correct |
212 ms |
27116 KB |
Output is correct |
98 |
Correct |
245 ms |
16444 KB |
Output is correct |
99 |
Correct |
445 ms |
27536 KB |
Output is correct |
100 |
Correct |
200 ms |
25860 KB |
Output is correct |