# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
85542 | 2018-11-20T20:15:49 Z | zoooma13 | Long Mansion (JOI17_long_mansion) | C++14 | 610 ms | 126456 KB |
#include <bits/stdc++.h> using namespace std; #define MAX_N 500005 int N; int C[MAX_N]; int B ,K; vector <int> Keys[MAX_N]; int Q; int X ,Y; int last[MAX_N]; int nl[MAX_N] ,nr[MAX_N]; int st[MAX_N] ,en[MAX_N]; int main() { scanf("%d",&N); for(int i=0; i<N-1; i++) scanf("%d",&C[i]); for(int i=0; i<N; i++) { scanf("%d",&B); while(B--){ scanf("%d",&K); Keys[i].push_back(K); } } memset(last ,-1 ,sizeof last); for(int i=0; i<N-1; i++){ for(int j : Keys[i]) last[j] = i; nl[i] = last[C[i]]; } memset(last ,-1 ,sizeof last); for(int i=N-2; ~i; i--){ for(int j : Keys[i+1]) last[j] = i+1; nr[i] = last[C[i]]; } auto can_left = [&](int i){ return (st[i] > 0 && ~nr[st[i]-1] && nr[st[i]-1] <= en[i]); }; auto can_right = [&](int i){ return (en[i] < N-1 && ~nl[en[i]] && st[i] <= nl[en[i]]); }; for(int i=0; i<N; i++) { st[i] = en[i] = i; while(true) { if(can_left(i)){ en[i] = max(en[i] ,en[st[i]-1]); st[i] = st[st[i]-1]; } else if(can_right(i)) en[i]++; else break; } } scanf("%d",&Q); while(Q--) { scanf("%d%d",&X,&Y); X-- ,Y--; printf(st[X]<=Y&&Y<=en[X] ? "YES\n" : "NO\n"); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 14204 KB | Output is correct |
2 | Correct | 17 ms | 14524 KB | Output is correct |
3 | Correct | 25 ms | 14644 KB | Output is correct |
4 | Correct | 24 ms | 14644 KB | Output is correct |
5 | Correct | 17 ms | 14744 KB | Output is correct |
6 | Correct | 18 ms | 14764 KB | Output is correct |
7 | Correct | 17 ms | 14856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 14204 KB | Output is correct |
2 | Correct | 17 ms | 14524 KB | Output is correct |
3 | Correct | 25 ms | 14644 KB | Output is correct |
4 | Correct | 24 ms | 14644 KB | Output is correct |
5 | Correct | 17 ms | 14744 KB | Output is correct |
6 | Correct | 18 ms | 14764 KB | Output is correct |
7 | Correct | 17 ms | 14856 KB | Output is correct |
8 | Correct | 159 ms | 20728 KB | Output is correct |
9 | Correct | 154 ms | 25044 KB | Output is correct |
10 | Correct | 156 ms | 29792 KB | Output is correct |
11 | Correct | 170 ms | 32044 KB | Output is correct |
12 | Correct | 145 ms | 32044 KB | Output is correct |
13 | Correct | 151 ms | 32044 KB | Output is correct |
14 | Correct | 170 ms | 32044 KB | Output is correct |
15 | Correct | 151 ms | 32044 KB | Output is correct |
16 | Correct | 142 ms | 32292 KB | Output is correct |
17 | Correct | 152 ms | 32292 KB | Output is correct |
18 | Correct | 179 ms | 32292 KB | Output is correct |
19 | Correct | 148 ms | 32292 KB | Output is correct |
20 | Correct | 144 ms | 32292 KB | Output is correct |
21 | Correct | 141 ms | 32292 KB | Output is correct |
22 | Correct | 162 ms | 32292 KB | Output is correct |
23 | Correct | 152 ms | 32292 KB | Output is correct |
24 | Correct | 151 ms | 32292 KB | Output is correct |
25 | Correct | 152 ms | 32292 KB | Output is correct |
26 | Correct | 149 ms | 32292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 271 ms | 42568 KB | Output is correct |
2 | Correct | 280 ms | 42692 KB | Output is correct |
3 | Correct | 260 ms | 42692 KB | Output is correct |
4 | Correct | 277 ms | 42692 KB | Output is correct |
5 | Correct | 283 ms | 42692 KB | Output is correct |
6 | Correct | 216 ms | 42692 KB | Output is correct |
7 | Correct | 248 ms | 42692 KB | Output is correct |
8 | Correct | 214 ms | 42692 KB | Output is correct |
9 | Correct | 213 ms | 42692 KB | Output is correct |
10 | Correct | 213 ms | 42692 KB | Output is correct |
11 | Correct | 214 ms | 42692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 14204 KB | Output is correct |
2 | Correct | 17 ms | 14524 KB | Output is correct |
3 | Correct | 25 ms | 14644 KB | Output is correct |
4 | Correct | 24 ms | 14644 KB | Output is correct |
5 | Correct | 17 ms | 14744 KB | Output is correct |
6 | Correct | 18 ms | 14764 KB | Output is correct |
7 | Correct | 17 ms | 14856 KB | Output is correct |
8 | Correct | 159 ms | 20728 KB | Output is correct |
9 | Correct | 154 ms | 25044 KB | Output is correct |
10 | Correct | 156 ms | 29792 KB | Output is correct |
11 | Correct | 170 ms | 32044 KB | Output is correct |
12 | Correct | 145 ms | 32044 KB | Output is correct |
13 | Correct | 151 ms | 32044 KB | Output is correct |
14 | Correct | 170 ms | 32044 KB | Output is correct |
15 | Correct | 151 ms | 32044 KB | Output is correct |
16 | Correct | 142 ms | 32292 KB | Output is correct |
17 | Correct | 152 ms | 32292 KB | Output is correct |
18 | Correct | 179 ms | 32292 KB | Output is correct |
19 | Correct | 148 ms | 32292 KB | Output is correct |
20 | Correct | 144 ms | 32292 KB | Output is correct |
21 | Correct | 141 ms | 32292 KB | Output is correct |
22 | Correct | 162 ms | 32292 KB | Output is correct |
23 | Correct | 152 ms | 32292 KB | Output is correct |
24 | Correct | 151 ms | 32292 KB | Output is correct |
25 | Correct | 152 ms | 32292 KB | Output is correct |
26 | Correct | 149 ms | 32292 KB | Output is correct |
27 | Correct | 271 ms | 42568 KB | Output is correct |
28 | Correct | 280 ms | 42692 KB | Output is correct |
29 | Correct | 260 ms | 42692 KB | Output is correct |
30 | Correct | 277 ms | 42692 KB | Output is correct |
31 | Correct | 283 ms | 42692 KB | Output is correct |
32 | Correct | 216 ms | 42692 KB | Output is correct |
33 | Correct | 248 ms | 42692 KB | Output is correct |
34 | Correct | 214 ms | 42692 KB | Output is correct |
35 | Correct | 213 ms | 42692 KB | Output is correct |
36 | Correct | 213 ms | 42692 KB | Output is correct |
37 | Correct | 214 ms | 42692 KB | Output is correct |
38 | Correct | 414 ms | 57024 KB | Output is correct |
39 | Correct | 409 ms | 62200 KB | Output is correct |
40 | Correct | 419 ms | 62200 KB | Output is correct |
41 | Correct | 376 ms | 62400 KB | Output is correct |
42 | Correct | 241 ms | 62400 KB | Output is correct |
43 | Correct | 232 ms | 62400 KB | Output is correct |
44 | Correct | 315 ms | 62400 KB | Output is correct |
45 | Correct | 326 ms | 62400 KB | Output is correct |
46 | Correct | 318 ms | 62400 KB | Output is correct |
47 | Correct | 234 ms | 62400 KB | Output is correct |
48 | Correct | 225 ms | 62400 KB | Output is correct |
49 | Correct | 324 ms | 62400 KB | Output is correct |
50 | Correct | 329 ms | 67376 KB | Output is correct |
51 | Correct | 345 ms | 77784 KB | Output is correct |
52 | Correct | 282 ms | 86908 KB | Output is correct |
53 | Correct | 364 ms | 102824 KB | Output is correct |
54 | Correct | 610 ms | 120348 KB | Output is correct |
55 | Correct | 356 ms | 126456 KB | Output is correct |