# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
490886 | 2021-11-29T15:57:39 Z | ntabc05101 | Long Mansion (JOI17_long_mansion) | C++14 | 247 ms | 52364 KB |
#include<bits/stdc++.h> using namespace std; #define taskname "" int main() { if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } else { if (fopen(taskname".in", "r")) { freopen(taskname".in", "r", stdin); freopen(taskname".out", "w", stdout); } } cin.tie(0)->sync_with_stdio(0); int n; cin >> n; int c[n - 1]; for (int i = 0; i < n - 1; i++) { cin >> c[i]; c[i]--; } vector<int> a[n]; for (int i = 0, b; i < n; i++) { cin >> b; a[i].resize(b); for (auto &x: a[i]) { cin >> x; x--; } } int pos[n]; memset(pos, -1, sizeof(pos)); int lo[n - 1], hi[n - 1]; for (int i = 0; i < n - 1; i++) { for (auto &x: a[i]) { pos[x] = i; } lo[i] = pos[c[i]]; } memset(pos, -1, sizeof(pos)); for (int i = n - 2; i >= 0; i--) { for (auto &x: a[i + 1]) { pos[x] = i + 1; } hi[i] = pos[c[i]]; } int l[n], r[n]; memset(l, 0, sizeof(l)); memset(r, 0, sizeof(r)); for (int i = 0, x, y; i < n; i++) { l[i] = r[i] = i; while (1) { x = l[i] - 1; if (x >= 0 && ((hi[x] >= l[i] && hi[x] <= r[i]) || (lo[x] >= l[i] && lo[x] <= r[i]))) { r[i] = max(r[i], r[x]); l[i] = l[x]; } else { if (r[i] < n - 1 && ((hi[r[i]] >= l[i] && hi[r[i]] <= r[i]) || (lo[r[i]] >= l[i] && lo[r[i]] <= r[i]))) { r[i]++; } else { break; } } } } int q; cin >> q; while (q--) { int x, y; cin >> x >> y; x--; y--; cout << (y >= l[x] && y <= r[x] ? "YES": "NO") << "\n"; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 460 KB | Output is correct |
2 | Correct | 3 ms | 588 KB | Output is correct |
3 | Correct | 3 ms | 716 KB | Output is correct |
4 | Correct | 3 ms | 516 KB | Output is correct |
5 | Correct | 2 ms | 460 KB | Output is correct |
6 | Correct | 2 ms | 460 KB | Output is correct |
7 | Correct | 2 ms | 460 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 460 KB | Output is correct |
2 | Correct | 3 ms | 588 KB | Output is correct |
3 | Correct | 3 ms | 716 KB | Output is correct |
4 | Correct | 3 ms | 516 KB | Output is correct |
5 | Correct | 2 ms | 460 KB | Output is correct |
6 | Correct | 2 ms | 460 KB | Output is correct |
7 | Correct | 2 ms | 460 KB | Output is correct |
8 | Correct | 101 ms | 6348 KB | Output is correct |
9 | Correct | 98 ms | 6292 KB | Output is correct |
10 | Correct | 90 ms | 6684 KB | Output is correct |
11 | Correct | 96 ms | 7108 KB | Output is correct |
12 | Correct | 89 ms | 5852 KB | Output is correct |
13 | Correct | 86 ms | 6472 KB | Output is correct |
14 | Correct | 98 ms | 6468 KB | Output is correct |
15 | Correct | 94 ms | 6516 KB | Output is correct |
16 | Correct | 89 ms | 6296 KB | Output is correct |
17 | Correct | 98 ms | 6528 KB | Output is correct |
18 | Correct | 94 ms | 6516 KB | Output is correct |
19 | Correct | 97 ms | 6564 KB | Output is correct |
20 | Correct | 90 ms | 6520 KB | Output is correct |
21 | Correct | 93 ms | 6272 KB | Output is correct |
22 | Correct | 106 ms | 6408 KB | Output is correct |
23 | Correct | 91 ms | 6220 KB | Output is correct |
24 | Correct | 102 ms | 6216 KB | Output is correct |
25 | Correct | 96 ms | 6276 KB | Output is correct |
26 | Correct | 93 ms | 6316 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 145 ms | 15396 KB | Output is correct |
2 | Correct | 144 ms | 17056 KB | Output is correct |
3 | Correct | 153 ms | 16836 KB | Output is correct |
4 | Correct | 152 ms | 17120 KB | Output is correct |
5 | Correct | 154 ms | 17028 KB | Output is correct |
6 | Correct | 126 ms | 16340 KB | Output is correct |
7 | Correct | 128 ms | 16064 KB | Output is correct |
8 | Correct | 130 ms | 16148 KB | Output is correct |
9 | Correct | 129 ms | 16128 KB | Output is correct |
10 | Correct | 133 ms | 16132 KB | Output is correct |
11 | Correct | 130 ms | 16068 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 460 KB | Output is correct |
2 | Correct | 3 ms | 588 KB | Output is correct |
3 | Correct | 3 ms | 716 KB | Output is correct |
4 | Correct | 3 ms | 516 KB | Output is correct |
5 | Correct | 2 ms | 460 KB | Output is correct |
6 | Correct | 2 ms | 460 KB | Output is correct |
7 | Correct | 2 ms | 460 KB | Output is correct |
8 | Correct | 101 ms | 6348 KB | Output is correct |
9 | Correct | 98 ms | 6292 KB | Output is correct |
10 | Correct | 90 ms | 6684 KB | Output is correct |
11 | Correct | 96 ms | 7108 KB | Output is correct |
12 | Correct | 89 ms | 5852 KB | Output is correct |
13 | Correct | 86 ms | 6472 KB | Output is correct |
14 | Correct | 98 ms | 6468 KB | Output is correct |
15 | Correct | 94 ms | 6516 KB | Output is correct |
16 | Correct | 89 ms | 6296 KB | Output is correct |
17 | Correct | 98 ms | 6528 KB | Output is correct |
18 | Correct | 94 ms | 6516 KB | Output is correct |
19 | Correct | 97 ms | 6564 KB | Output is correct |
20 | Correct | 90 ms | 6520 KB | Output is correct |
21 | Correct | 93 ms | 6272 KB | Output is correct |
22 | Correct | 106 ms | 6408 KB | Output is correct |
23 | Correct | 91 ms | 6220 KB | Output is correct |
24 | Correct | 102 ms | 6216 KB | Output is correct |
25 | Correct | 96 ms | 6276 KB | Output is correct |
26 | Correct | 93 ms | 6316 KB | Output is correct |
27 | Correct | 145 ms | 15396 KB | Output is correct |
28 | Correct | 144 ms | 17056 KB | Output is correct |
29 | Correct | 153 ms | 16836 KB | Output is correct |
30 | Correct | 152 ms | 17120 KB | Output is correct |
31 | Correct | 154 ms | 17028 KB | Output is correct |
32 | Correct | 126 ms | 16340 KB | Output is correct |
33 | Correct | 128 ms | 16064 KB | Output is correct |
34 | Correct | 130 ms | 16148 KB | Output is correct |
35 | Correct | 129 ms | 16128 KB | Output is correct |
36 | Correct | 133 ms | 16132 KB | Output is correct |
37 | Correct | 130 ms | 16068 KB | Output is correct |
38 | Correct | 217 ms | 44732 KB | Output is correct |
39 | Correct | 244 ms | 52364 KB | Output is correct |
40 | Correct | 208 ms | 35804 KB | Output is correct |
41 | Correct | 237 ms | 50732 KB | Output is correct |
42 | Correct | 136 ms | 17192 KB | Output is correct |
43 | Correct | 144 ms | 17300 KB | Output is correct |
44 | Correct | 168 ms | 27716 KB | Output is correct |
45 | Correct | 177 ms | 27892 KB | Output is correct |
46 | Correct | 206 ms | 27952 KB | Output is correct |
47 | Correct | 134 ms | 17312 KB | Output is correct |
48 | Correct | 137 ms | 17068 KB | Output is correct |
49 | Correct | 179 ms | 27716 KB | Output is correct |
50 | Correct | 174 ms | 27772 KB | Output is correct |
51 | Correct | 219 ms | 28072 KB | Output is correct |
52 | Correct | 164 ms | 26680 KB | Output is correct |
53 | Correct | 194 ms | 36156 KB | Output is correct |
54 | Correct | 247 ms | 45652 KB | Output is correct |
55 | Correct | 207 ms | 36392 KB | Output is correct |