# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
125294 | 2019-07-05T04:54:55 Z | 구재현(#3066) | Long Mansion (JOI17_long_mansion) | C++14 | 712 ms | 116044 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; using lint = long long; using pi = pair<int, int>; int n, c[MAXN]; vector<int> key_loc[MAXN]; int L[20][MAXN], R[20][MAXN]; int up[MAXN], dn[MAXN]; pi rng[MAXN]; int main(){ scanf("%d",&n); for(int i=1; i<n; i++) scanf("%d",&c[i]); for(int i=1; i<=n; i++){ int x; scanf("%d",&x); for(int j=0; j<x; j++){ int y; scanf("%d",&y); key_loc[y].push_back(i); } } for(int i=1; i<n; i++){ auto p = lower_bound(key_loc[c[i]].begin(), key_loc[c[i]].end(), i + 1); if(p == key_loc[c[i]].end()) R[0][i] = n + 1; else R[0][i] = *p; if(p == key_loc[c[i]].begin()) L[0][i] = 0; else L[0][i] = *prev(p); } R[0][0] = n + 1; L[0][n + 1] = 0; for(int i=1; i<20; i++){ for(int j=0; j<=n+1; j++){ L[i][j] = L[i-1][j]; R[i][j] = R[i-1][j]; if(j >= (1 << (i - 1))){ L[i][j] = min(L[i][j], L[i-1][j - (1 << (i-1))]); R[i][j] = max(R[i][j], R[i-1][j - (1 << (i-1))]); } } } memset(dn, 0x3f, sizeof(dn)); for(int i=1; i<=n; i++){ int pos = R[0][i - 1] - 1; for(int j=19; j>=0; j--){ if(pos >= (1 << j) && L[j][pos] >= i){ pos -= (1 << j); } } if(L[0][pos] >= i) pos--; if(pos >= i) up[i] = max(up[i], pos); } for(int i=1; i<=n; i++){ int pos = L[0][i]; for(int j=19; j>=0; j--){ if(pos + (1 << j) <= n && R[j][pos + (1<<j) - 1] <= i){ pos += (1 << j); } } if(R[0][pos] <= i) pos++; pos++; if(pos <= i) dn[i] = min(dn[i], pos); } vector<pi> stk; for(int i=1; i<=n; i++){ while(!stk.empty() && stk.back().first <= max(i - 1, up[i])){ stk.pop_back(); } if(up[i] >= i) stk.emplace_back(up[i], i); if(stk.size()) rng[i].first = stk.back().second; else rng[i].first = 1; } stk.clear(); for(int i=n; i; i--){ while(!stk.empty() && stk.back().first >= min(i + 1, dn[i])){ stk.pop_back(); } if(dn[i] <= i) stk.emplace_back(dn[i], i); if(stk.size()) rng[i].second = stk.back().second; else rng[i].second = n; } int q; scanf("%d",&q); while(q--){ int x, y; scanf("%d %d",&x,&y); puts(rng[x].first <= y && y <= rng[x].second ? "YES" : "NO"); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 14712 KB | Output is correct |
2 | Correct | 18 ms | 14968 KB | Output is correct |
3 | Correct | 19 ms | 15352 KB | Output is correct |
4 | Correct | 17 ms | 14840 KB | Output is correct |
5 | Correct | 17 ms | 14712 KB | Output is correct |
6 | Correct | 17 ms | 14840 KB | Output is correct |
7 | Correct | 17 ms | 14840 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 14712 KB | Output is correct |
2 | Correct | 18 ms | 14968 KB | Output is correct |
3 | Correct | 19 ms | 15352 KB | Output is correct |
4 | Correct | 17 ms | 14840 KB | Output is correct |
5 | Correct | 17 ms | 14712 KB | Output is correct |
6 | Correct | 17 ms | 14840 KB | Output is correct |
7 | Correct | 17 ms | 14840 KB | Output is correct |
8 | Correct | 146 ms | 16200 KB | Output is correct |
9 | Correct | 144 ms | 16248 KB | Output is correct |
10 | Correct | 148 ms | 16624 KB | Output is correct |
11 | Correct | 147 ms | 17032 KB | Output is correct |
12 | Correct | 135 ms | 16248 KB | Output is correct |
13 | Correct | 141 ms | 16508 KB | Output is correct |
14 | Correct | 142 ms | 16504 KB | Output is correct |
15 | Correct | 140 ms | 16520 KB | Output is correct |
16 | Correct | 133 ms | 16664 KB | Output is correct |
17 | Correct | 141 ms | 16632 KB | Output is correct |
18 | Correct | 141 ms | 16476 KB | Output is correct |
19 | Correct | 140 ms | 16504 KB | Output is correct |
20 | Correct | 138 ms | 16632 KB | Output is correct |
21 | Correct | 134 ms | 16760 KB | Output is correct |
22 | Correct | 141 ms | 16504 KB | Output is correct |
23 | Correct | 141 ms | 16376 KB | Output is correct |
24 | Correct | 141 ms | 16460 KB | Output is correct |
25 | Correct | 141 ms | 16456 KB | Output is correct |
26 | Correct | 142 ms | 16376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 284 ms | 41132 KB | Output is correct |
2 | Correct | 285 ms | 42528 KB | Output is correct |
3 | Correct | 274 ms | 42360 KB | Output is correct |
4 | Correct | 281 ms | 42616 KB | Output is correct |
5 | Correct | 277 ms | 42832 KB | Output is correct |
6 | Correct | 238 ms | 40952 KB | Output is correct |
7 | Correct | 232 ms | 40824 KB | Output is correct |
8 | Correct | 230 ms | 40728 KB | Output is correct |
9 | Correct | 242 ms | 40872 KB | Output is correct |
10 | Correct | 232 ms | 40572 KB | Output is correct |
11 | Correct | 234 ms | 40440 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 14712 KB | Output is correct |
2 | Correct | 18 ms | 14968 KB | Output is correct |
3 | Correct | 19 ms | 15352 KB | Output is correct |
4 | Correct | 17 ms | 14840 KB | Output is correct |
5 | Correct | 17 ms | 14712 KB | Output is correct |
6 | Correct | 17 ms | 14840 KB | Output is correct |
7 | Correct | 17 ms | 14840 KB | Output is correct |
8 | Correct | 146 ms | 16200 KB | Output is correct |
9 | Correct | 144 ms | 16248 KB | Output is correct |
10 | Correct | 148 ms | 16624 KB | Output is correct |
11 | Correct | 147 ms | 17032 KB | Output is correct |
12 | Correct | 135 ms | 16248 KB | Output is correct |
13 | Correct | 141 ms | 16508 KB | Output is correct |
14 | Correct | 142 ms | 16504 KB | Output is correct |
15 | Correct | 140 ms | 16520 KB | Output is correct |
16 | Correct | 133 ms | 16664 KB | Output is correct |
17 | Correct | 141 ms | 16632 KB | Output is correct |
18 | Correct | 141 ms | 16476 KB | Output is correct |
19 | Correct | 140 ms | 16504 KB | Output is correct |
20 | Correct | 138 ms | 16632 KB | Output is correct |
21 | Correct | 134 ms | 16760 KB | Output is correct |
22 | Correct | 141 ms | 16504 KB | Output is correct |
23 | Correct | 141 ms | 16376 KB | Output is correct |
24 | Correct | 141 ms | 16460 KB | Output is correct |
25 | Correct | 141 ms | 16456 KB | Output is correct |
26 | Correct | 142 ms | 16376 KB | Output is correct |
27 | Correct | 284 ms | 41132 KB | Output is correct |
28 | Correct | 285 ms | 42528 KB | Output is correct |
29 | Correct | 274 ms | 42360 KB | Output is correct |
30 | Correct | 281 ms | 42616 KB | Output is correct |
31 | Correct | 277 ms | 42832 KB | Output is correct |
32 | Correct | 238 ms | 40952 KB | Output is correct |
33 | Correct | 232 ms | 40824 KB | Output is correct |
34 | Correct | 230 ms | 40728 KB | Output is correct |
35 | Correct | 242 ms | 40872 KB | Output is correct |
36 | Correct | 232 ms | 40572 KB | Output is correct |
37 | Correct | 234 ms | 40440 KB | Output is correct |
38 | Correct | 684 ms | 99432 KB | Output is correct |
39 | Correct | 712 ms | 116044 KB | Output is correct |
40 | Correct | 531 ms | 81368 KB | Output is correct |
41 | Correct | 547 ms | 113616 KB | Output is correct |
42 | Correct | 279 ms | 42360 KB | Output is correct |
43 | Correct | 275 ms | 42360 KB | Output is correct |
44 | Correct | 425 ms | 64008 KB | Output is correct |
45 | Correct | 416 ms | 64220 KB | Output is correct |
46 | Correct | 419 ms | 64684 KB | Output is correct |
47 | Correct | 265 ms | 42232 KB | Output is correct |
48 | Correct | 256 ms | 41968 KB | Output is correct |
49 | Correct | 380 ms | 62960 KB | Output is correct |
50 | Correct | 390 ms | 63404 KB | Output is correct |
51 | Correct | 415 ms | 64460 KB | Output is correct |
52 | Correct | 335 ms | 65348 KB | Output is correct |
53 | Correct | 426 ms | 87132 KB | Output is correct |
54 | Correct | 513 ms | 109420 KB | Output is correct |
55 | Correct | 430 ms | 87364 KB | Output is correct |