# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21133 | 2017-04-05T02:46:37 Z | khsoo01 | Long Mansion (JOI17_long_mansion) | C++11 | 469 ms | 48576 KB |
#include<bits/stdc++.h> using namespace std; const int inf = 1e9; int n, a[500005], l[500005], r[500005], lst[500005]; int q, xl[500005], xr[500005]; vector<int> st, ky[500005]; struct minseg { int val[1111111], lim; void init () { for(lim=1;lim<=n+1;lim<<=1); val[lim] = inf; for(int i=1;i<=n;i++) { val[lim + i] = l[i]; } for(int i=lim;--i;) { val[i] = min(val[2*i], val[2*i+1]); } } void update (int P, int V) { P += lim; val[P] = V; P >>= 1; while(P) { val[P] = min(val[2*P], val[2*P+1]); P >>= 1; } } int query (int X, int SS, int SE, int P) { if(SS == SE) return SS; int mid = (SS+SE)/2; return (val[2*P] < X ? query(X, SS, mid, 2*P) : query(X, mid+1, SE, 2*P+1)); } int query (int X) {return query(X, 0, lim-1, 1);} } seg; int main() { scanf("%d",&n); for(int i=1;i<n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { int M; scanf("%d",&M); for(int j=0;j<M;j++) { int tmp; scanf("%d",&tmp); ky[i].push_back(tmp); } } for(int i=1;i<n;i++) { for(auto &j : ky[i]) lst[j] = i; l[i+1] = lst[a[i]]; } for(int i=1;i<=n;i++) lst[i] = n+1; r[n] = n+1; for(int i=n;i>1;i--) { for(auto &j : ky[i]) lst[j] = i; r[i-1] = lst[a[i-1]]; } seg.init(); for(int i=1;i<=n;i++) { xl[i] = i; xr[i] = i; seg.update(i, inf); while(true) { xr[i] = seg.query(xl[i]) - 1; if(xl[i] == 1 || r[xl[i]-1] > xr[i]) break; xl[i] = st.back(); st.pop_back(); } st.push_back(xl[i]); } scanf("%d",&q); for(int i=1;i<=q;i++) { int A, B; scanf("%d%d",&A,&B); puts(xl[A] <= B && B <= xr[A] ? "YES" : "NO"); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 29928 KB | Output is correct |
2 | Correct | 3 ms | 29928 KB | Output is correct |
3 | Correct | 9 ms | 29928 KB | Output is correct |
4 | Correct | 6 ms | 29928 KB | Output is correct |
5 | Correct | 6 ms | 29928 KB | Output is correct |
6 | Correct | 3 ms | 29928 KB | Output is correct |
7 | Correct | 3 ms | 29928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 29928 KB | Output is correct |
2 | Correct | 3 ms | 29928 KB | Output is correct |
3 | Correct | 9 ms | 29928 KB | Output is correct |
4 | Correct | 6 ms | 29928 KB | Output is correct |
5 | Correct | 6 ms | 29928 KB | Output is correct |
6 | Correct | 3 ms | 29928 KB | Output is correct |
7 | Correct | 3 ms | 29928 KB | Output is correct |
8 | Correct | 129 ms | 29928 KB | Output is correct |
9 | Correct | 133 ms | 29928 KB | Output is correct |
10 | Correct | 136 ms | 29928 KB | Output is correct |
11 | Correct | 129 ms | 29928 KB | Output is correct |
12 | Correct | 126 ms | 29796 KB | Output is correct |
13 | Correct | 136 ms | 29928 KB | Output is correct |
14 | Correct | 139 ms | 29928 KB | Output is correct |
15 | Correct | 133 ms | 29928 KB | Output is correct |
16 | Correct | 119 ms | 29928 KB | Output is correct |
17 | Correct | 123 ms | 29928 KB | Output is correct |
18 | Correct | 126 ms | 29928 KB | Output is correct |
19 | Correct | 126 ms | 29928 KB | Output is correct |
20 | Correct | 123 ms | 29928 KB | Output is correct |
21 | Correct | 129 ms | 29928 KB | Output is correct |
22 | Correct | 136 ms | 29928 KB | Output is correct |
23 | Correct | 123 ms | 29928 KB | Output is correct |
24 | Correct | 146 ms | 29928 KB | Output is correct |
25 | Correct | 129 ms | 29928 KB | Output is correct |
26 | Correct | 126 ms | 29928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 269 ms | 33756 KB | Output is correct |
2 | Correct | 269 ms | 33624 KB | Output is correct |
3 | Correct | 256 ms | 33492 KB | Output is correct |
4 | Correct | 276 ms | 33624 KB | Output is correct |
5 | Correct | 279 ms | 33624 KB | Output is correct |
6 | Correct | 223 ms | 32964 KB | Output is correct |
7 | Correct | 203 ms | 32964 KB | Output is correct |
8 | Correct | 176 ms | 32964 KB | Output is correct |
9 | Correct | 196 ms | 32964 KB | Output is correct |
10 | Correct | 199 ms | 32964 KB | Output is correct |
11 | Correct | 206 ms | 32964 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 29928 KB | Output is correct |
2 | Correct | 3 ms | 29928 KB | Output is correct |
3 | Correct | 9 ms | 29928 KB | Output is correct |
4 | Correct | 6 ms | 29928 KB | Output is correct |
5 | Correct | 6 ms | 29928 KB | Output is correct |
6 | Correct | 3 ms | 29928 KB | Output is correct |
7 | Correct | 3 ms | 29928 KB | Output is correct |
8 | Correct | 129 ms | 29928 KB | Output is correct |
9 | Correct | 133 ms | 29928 KB | Output is correct |
10 | Correct | 136 ms | 29928 KB | Output is correct |
11 | Correct | 129 ms | 29928 KB | Output is correct |
12 | Correct | 126 ms | 29796 KB | Output is correct |
13 | Correct | 136 ms | 29928 KB | Output is correct |
14 | Correct | 139 ms | 29928 KB | Output is correct |
15 | Correct | 133 ms | 29928 KB | Output is correct |
16 | Correct | 119 ms | 29928 KB | Output is correct |
17 | Correct | 123 ms | 29928 KB | Output is correct |
18 | Correct | 126 ms | 29928 KB | Output is correct |
19 | Correct | 126 ms | 29928 KB | Output is correct |
20 | Correct | 123 ms | 29928 KB | Output is correct |
21 | Correct | 129 ms | 29928 KB | Output is correct |
22 | Correct | 136 ms | 29928 KB | Output is correct |
23 | Correct | 123 ms | 29928 KB | Output is correct |
24 | Correct | 146 ms | 29928 KB | Output is correct |
25 | Correct | 129 ms | 29928 KB | Output is correct |
26 | Correct | 126 ms | 29928 KB | Output is correct |
27 | Correct | 269 ms | 33756 KB | Output is correct |
28 | Correct | 269 ms | 33624 KB | Output is correct |
29 | Correct | 256 ms | 33492 KB | Output is correct |
30 | Correct | 276 ms | 33624 KB | Output is correct |
31 | Correct | 279 ms | 33624 KB | Output is correct |
32 | Correct | 223 ms | 32964 KB | Output is correct |
33 | Correct | 203 ms | 32964 KB | Output is correct |
34 | Correct | 176 ms | 32964 KB | Output is correct |
35 | Correct | 196 ms | 32964 KB | Output is correct |
36 | Correct | 199 ms | 32964 KB | Output is correct |
37 | Correct | 206 ms | 32964 KB | Output is correct |
38 | Correct | 426 ms | 45452 KB | Output is correct |
39 | Correct | 443 ms | 48576 KB | Output is correct |
40 | Correct | 413 ms | 42348 KB | Output is correct |
41 | Correct | 469 ms | 45372 KB | Output is correct |
42 | Correct | 216 ms | 33124 KB | Output is correct |
43 | Correct | 249 ms | 32964 KB | Output is correct |
44 | Correct | 349 ms | 36132 KB | Output is correct |
45 | Correct | 296 ms | 36132 KB | Output is correct |
46 | Correct | 329 ms | 36132 KB | Output is correct |
47 | Correct | 233 ms | 32964 KB | Output is correct |
48 | Correct | 269 ms | 32964 KB | Output is correct |
49 | Correct | 316 ms | 36000 KB | Output is correct |
50 | Correct | 316 ms | 36000 KB | Output is correct |
51 | Correct | 313 ms | 36000 KB | Output is correct |
52 | Correct | 323 ms | 36900 KB | Output is correct |
53 | Correct | 353 ms | 40024 KB | Output is correct |
54 | Correct | 443 ms | 43916 KB | Output is correct |
55 | Correct | 373 ms | 40792 KB | Output is correct |