# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
125487 | 2019-07-05T13:17:01 Z | imyujin | Long Mansion (JOI17_long_mansion) | C++14 | 1177 ms | 145976 KB |
#include <stdio.h> #include <vector> #include <algorithm> #include <queue> using namespace std; #define MAXN 500005 int N; vector<int> A[MAXN]; int B[MAXN], C[MAXN], X[MAXN], Y[MAXN]; int left[MAXN], rig[MAXN], lefinv[MAXN], riginv[MAXN]; int L[MAXN], R[MAXN], Rinv[MAXN]; int lastkey[MAXN], sparse[20][MAXN]; vector<int> mn[MAXN], mnt[MAXN]; void findleft(vector<int> A[], int C[], int left[]) { for(int i = 1; i <= N; i++) lastkey[i] = 0; for(int i = 1; i < N; i++) { for(auto a : A[i]) lastkey[a] = i; left[i] = lastkey[C[i]]; } left[0] = left[N] = 0; } void setL(int left[], int rig[], int L[]) { priority_queue<int> pq, pqt; //printf("*\n"); for(int i = 0; i <= N; i++) sparse[0][i] = left[i]; for(int i = 1; i < 20; i++) for(int j = (1 << i) - 1; j <= N; j++) sparse[i][j] = min(sparse[i - 1][j], sparse[i - 1][j - (1 << i - 1)]); //for(int i = 0; i <= N; i++) printf("(%d %d)", sparse[0][i], sparse[1][i]); //printf("\n"); for(int i = 1; i <= N; i++) { mn[i].clear(); mnt[i].clear(); } for(int i = 0; i <= N; i++) { int t = rig[i] - 1; for(int j = 19; j >= 0; j--) if(t - (1 << j) + 1 >= 0 && sparse[j][t] > i) t -= (1 << j); t = max(t, i); //printf("i = %d, t = %d\n", i, t); mn[i + 1].push_back(i + 1); mnt[t + 1].push_back(i + 1); } //pq.push(0); for(int i = 1; i <= N; i++) { for(auto a : mn[i]) pq.push(a); for(auto a : mnt[i]) pqt.push(a); while(!pqt.empty() && pq.top() == pqt.top()) { pq.pop(); pqt.pop(); } L[i] = pq.top(); } //for(int i = 0; i <= N; i++) printf("%d ", L[i]); //printf("\n"); } int main() { int Q; scanf("%d", &N); for(int i = 1; i < N; i++) scanf("%d", C + i); for(int i = 1; i <= N; i++) { scanf("%d", B + i); for(int j = 0; j < B[i]; j++) { int t; scanf("%d", &t); A[i].push_back(t); } } scanf("%d", &Q); for(int i = 0; i < Q; i++) scanf("%d%d", X + i, Y + i); findleft(A, C, left); for(int i = 1; i <= N / 2; i++) swap(A[i], A[N - i + 1]); for(int i = 1; i <= (N - 1) / 2; i++) swap(C[i], C[N - i]); findleft(A, C, lefinv); for(int i = 0; i <= N; i++) { rig[i] = N - lefinv[N - i] + 1; riginv[i] = N - left[N - i] + 1; } //for(int i = 0; i <= N; i++) printf("i = %d, left = %d, rig = %d, leftinv = %d\n", i, left[i], rig[i], lefinv[i]); setL(left, rig, L); setL(lefinv, riginv, Rinv); for(int i = 1; i <= N; i++) R[i] = N - Rinv[N - i + 1] + 1; for(int i = 0; i < Q; i++) { if(L[X[i]] <= Y[i] && Y[i] <= R[X[i]]) printf("YES\n"); else printf("NO\n"); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 36088 KB | Output is correct |
2 | Correct | 39 ms | 36376 KB | Output is correct |
3 | Correct | 39 ms | 36700 KB | Output is correct |
4 | Correct | 38 ms | 36176 KB | Output is correct |
5 | Correct | 38 ms | 36092 KB | Output is correct |
6 | Correct | 38 ms | 36156 KB | Output is correct |
7 | Correct | 38 ms | 36200 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 36088 KB | Output is correct |
2 | Correct | 39 ms | 36376 KB | Output is correct |
3 | Correct | 39 ms | 36700 KB | Output is correct |
4 | Correct | 38 ms | 36176 KB | Output is correct |
5 | Correct | 38 ms | 36092 KB | Output is correct |
6 | Correct | 38 ms | 36156 KB | Output is correct |
7 | Correct | 38 ms | 36200 KB | Output is correct |
8 | Correct | 185 ms | 45172 KB | Output is correct |
9 | Correct | 182 ms | 45076 KB | Output is correct |
10 | Correct | 182 ms | 45532 KB | Output is correct |
11 | Correct | 178 ms | 45956 KB | Output is correct |
12 | Correct | 168 ms | 45172 KB | Output is correct |
13 | Correct | 163 ms | 45364 KB | Output is correct |
14 | Correct | 165 ms | 45384 KB | Output is correct |
15 | Correct | 167 ms | 45464 KB | Output is correct |
16 | Correct | 165 ms | 45636 KB | Output is correct |
17 | Correct | 164 ms | 45432 KB | Output is correct |
18 | Correct | 165 ms | 45460 KB | Output is correct |
19 | Correct | 167 ms | 45344 KB | Output is correct |
20 | Correct | 185 ms | 45532 KB | Output is correct |
21 | Correct | 164 ms | 45676 KB | Output is correct |
22 | Correct | 166 ms | 45660 KB | Output is correct |
23 | Correct | 183 ms | 45512 KB | Output is correct |
24 | Correct | 175 ms | 45436 KB | Output is correct |
25 | Correct | 175 ms | 45624 KB | Output is correct |
26 | Correct | 174 ms | 45772 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 365 ms | 65548 KB | Output is correct |
2 | Correct | 352 ms | 65556 KB | Output is correct |
3 | Correct | 342 ms | 65756 KB | Output is correct |
4 | Correct | 359 ms | 65652 KB | Output is correct |
5 | Correct | 363 ms | 65676 KB | Output is correct |
6 | Correct | 294 ms | 65896 KB | Output is correct |
7 | Correct | 282 ms | 66068 KB | Output is correct |
8 | Correct | 283 ms | 66168 KB | Output is correct |
9 | Correct | 281 ms | 66008 KB | Output is correct |
10 | Correct | 281 ms | 66168 KB | Output is correct |
11 | Correct | 286 ms | 66108 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 36088 KB | Output is correct |
2 | Correct | 39 ms | 36376 KB | Output is correct |
3 | Correct | 39 ms | 36700 KB | Output is correct |
4 | Correct | 38 ms | 36176 KB | Output is correct |
5 | Correct | 38 ms | 36092 KB | Output is correct |
6 | Correct | 38 ms | 36156 KB | Output is correct |
7 | Correct | 38 ms | 36200 KB | Output is correct |
8 | Correct | 185 ms | 45172 KB | Output is correct |
9 | Correct | 182 ms | 45076 KB | Output is correct |
10 | Correct | 182 ms | 45532 KB | Output is correct |
11 | Correct | 178 ms | 45956 KB | Output is correct |
12 | Correct | 168 ms | 45172 KB | Output is correct |
13 | Correct | 163 ms | 45364 KB | Output is correct |
14 | Correct | 165 ms | 45384 KB | Output is correct |
15 | Correct | 167 ms | 45464 KB | Output is correct |
16 | Correct | 165 ms | 45636 KB | Output is correct |
17 | Correct | 164 ms | 45432 KB | Output is correct |
18 | Correct | 165 ms | 45460 KB | Output is correct |
19 | Correct | 167 ms | 45344 KB | Output is correct |
20 | Correct | 185 ms | 45532 KB | Output is correct |
21 | Correct | 164 ms | 45676 KB | Output is correct |
22 | Correct | 166 ms | 45660 KB | Output is correct |
23 | Correct | 183 ms | 45512 KB | Output is correct |
24 | Correct | 175 ms | 45436 KB | Output is correct |
25 | Correct | 175 ms | 45624 KB | Output is correct |
26 | Correct | 174 ms | 45772 KB | Output is correct |
27 | Correct | 365 ms | 65548 KB | Output is correct |
28 | Correct | 352 ms | 65556 KB | Output is correct |
29 | Correct | 342 ms | 65756 KB | Output is correct |
30 | Correct | 359 ms | 65652 KB | Output is correct |
31 | Correct | 363 ms | 65676 KB | Output is correct |
32 | Correct | 294 ms | 65896 KB | Output is correct |
33 | Correct | 282 ms | 66068 KB | Output is correct |
34 | Correct | 283 ms | 66168 KB | Output is correct |
35 | Correct | 281 ms | 66008 KB | Output is correct |
36 | Correct | 281 ms | 66168 KB | Output is correct |
37 | Correct | 286 ms | 66108 KB | Output is correct |
38 | Correct | 1154 ms | 124504 KB | Output is correct |
39 | Correct | 1177 ms | 145976 KB | Output is correct |
40 | Correct | 774 ms | 105044 KB | Output is correct |
41 | Correct | 833 ms | 145372 KB | Output is correct |
42 | Correct | 378 ms | 65108 KB | Output is correct |
43 | Correct | 333 ms | 65020 KB | Output is correct |
44 | Correct | 516 ms | 85144 KB | Output is correct |
45 | Correct | 502 ms | 85112 KB | Output is correct |
46 | Correct | 475 ms | 84984 KB | Output is correct |
47 | Correct | 299 ms | 64972 KB | Output is correct |
48 | Correct | 293 ms | 64760 KB | Output is correct |
49 | Correct | 450 ms | 85080 KB | Output is correct |
50 | Correct | 435 ms | 85132 KB | Output is correct |
51 | Correct | 440 ms | 84772 KB | Output is correct |
52 | Correct | 428 ms | 81116 KB | Output is correct |
53 | Correct | 577 ms | 98052 KB | Output is correct |
54 | Correct | 650 ms | 115548 KB | Output is correct |
55 | Correct | 542 ms | 97648 KB | Output is correct |