# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
83518 | 2018-11-08T17:06:32 Z | nikolapesic2802 | Long Mansion (JOI17_long_mansion) | C++14 | 482 ms | 122196 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define pb push_back using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; ///find_by_order(),order_of_key() const int N=5*1e5+5; vector<int> hi(N),lo(N),l(N),r(N); bool on(int l,int r,int x){return x>=l&&x<=r;} bool can(int l,int r,int x){return (hi[x]>=0&&on(l,r,hi[x]))||(lo[x]>=0&&on(l,r,lo[x]));} int main() { int n; scanf("%i",&n); vector<int> cor(n-1); for(int i=0;i<n-1;i++) scanf("%i",&cor[i]); vector<vector<int> > sobe(n); for(int i=0;i<n;i++) { int b; scanf("%i",&b); for(int j=0;j<b;j++) { int a; scanf("%i",&a); sobe[i].pb(a); } } vector<int> keys(n,-1); for(int i=0;i<n-1;i++) { for(auto p:sobe[i]) keys[p]=i; lo[i]=keys[cor[i]]; } fill(keys.begin(),keys.end(),-1); for(int i=n-1;i>0;i--) { for(auto p:sobe[i]) keys[p]=i; hi[i-1]=keys[cor[i-1]]; } for(int i=0;i<n;i++) { l[i]=r[i]=i; while(true) { if(l[i]>0&&can(l[i],r[i],l[i]-1)) { r[i]=max(r[i],r[l[i]-1]); l[i]=l[l[i]-1]; } else if(r[i]<n-1&&can(l[i],r[i],r[i])) r[i]++; else break; } } int q; scanf("%i",&q); for(int i=0;i<q;i++) { int x,y; scanf("%i %i",&x,&y); x--; y--; if(on(l[x],r[x],y)) printf("YES\n"); else printf("NO\n"); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 8312 KB | Output is correct |
2 | Correct | 13 ms | 8436 KB | Output is correct |
3 | Correct | 12 ms | 8528 KB | Output is correct |
4 | Correct | 12 ms | 8544 KB | Output is correct |
5 | Correct | 11 ms | 8692 KB | Output is correct |
6 | Correct | 12 ms | 8692 KB | Output is correct |
7 | Correct | 11 ms | 8864 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 8312 KB | Output is correct |
2 | Correct | 13 ms | 8436 KB | Output is correct |
3 | Correct | 12 ms | 8528 KB | Output is correct |
4 | Correct | 12 ms | 8544 KB | Output is correct |
5 | Correct | 11 ms | 8692 KB | Output is correct |
6 | Correct | 12 ms | 8692 KB | Output is correct |
7 | Correct | 11 ms | 8864 KB | Output is correct |
8 | Correct | 178 ms | 14676 KB | Output is correct |
9 | Correct | 176 ms | 19144 KB | Output is correct |
10 | Correct | 172 ms | 23844 KB | Output is correct |
11 | Correct | 163 ms | 28692 KB | Output is correct |
12 | Correct | 156 ms | 29168 KB | Output is correct |
13 | Correct | 148 ms | 29344 KB | Output is correct |
14 | Correct | 148 ms | 29344 KB | Output is correct |
15 | Correct | 156 ms | 29344 KB | Output is correct |
16 | Correct | 152 ms | 29440 KB | Output is correct |
17 | Correct | 146 ms | 29440 KB | Output is correct |
18 | Correct | 164 ms | 29440 KB | Output is correct |
19 | Correct | 149 ms | 29440 KB | Output is correct |
20 | Correct | 151 ms | 29440 KB | Output is correct |
21 | Correct | 137 ms | 29440 KB | Output is correct |
22 | Correct | 157 ms | 29440 KB | Output is correct |
23 | Correct | 157 ms | 29440 KB | Output is correct |
24 | Correct | 157 ms | 29440 KB | Output is correct |
25 | Correct | 162 ms | 29440 KB | Output is correct |
26 | Correct | 152 ms | 29440 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 302 ms | 35840 KB | Output is correct |
2 | Correct | 314 ms | 35864 KB | Output is correct |
3 | Correct | 278 ms | 35864 KB | Output is correct |
4 | Correct | 307 ms | 35864 KB | Output is correct |
5 | Correct | 321 ms | 35964 KB | Output is correct |
6 | Correct | 235 ms | 35964 KB | Output is correct |
7 | Correct | 232 ms | 35964 KB | Output is correct |
8 | Correct | 273 ms | 35964 KB | Output is correct |
9 | Correct | 220 ms | 35964 KB | Output is correct |
10 | Correct | 216 ms | 35964 KB | Output is correct |
11 | Correct | 221 ms | 35964 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 8312 KB | Output is correct |
2 | Correct | 13 ms | 8436 KB | Output is correct |
3 | Correct | 12 ms | 8528 KB | Output is correct |
4 | Correct | 12 ms | 8544 KB | Output is correct |
5 | Correct | 11 ms | 8692 KB | Output is correct |
6 | Correct | 12 ms | 8692 KB | Output is correct |
7 | Correct | 11 ms | 8864 KB | Output is correct |
8 | Correct | 178 ms | 14676 KB | Output is correct |
9 | Correct | 176 ms | 19144 KB | Output is correct |
10 | Correct | 172 ms | 23844 KB | Output is correct |
11 | Correct | 163 ms | 28692 KB | Output is correct |
12 | Correct | 156 ms | 29168 KB | Output is correct |
13 | Correct | 148 ms | 29344 KB | Output is correct |
14 | Correct | 148 ms | 29344 KB | Output is correct |
15 | Correct | 156 ms | 29344 KB | Output is correct |
16 | Correct | 152 ms | 29440 KB | Output is correct |
17 | Correct | 146 ms | 29440 KB | Output is correct |
18 | Correct | 164 ms | 29440 KB | Output is correct |
19 | Correct | 149 ms | 29440 KB | Output is correct |
20 | Correct | 151 ms | 29440 KB | Output is correct |
21 | Correct | 137 ms | 29440 KB | Output is correct |
22 | Correct | 157 ms | 29440 KB | Output is correct |
23 | Correct | 157 ms | 29440 KB | Output is correct |
24 | Correct | 157 ms | 29440 KB | Output is correct |
25 | Correct | 162 ms | 29440 KB | Output is correct |
26 | Correct | 152 ms | 29440 KB | Output is correct |
27 | Correct | 302 ms | 35840 KB | Output is correct |
28 | Correct | 314 ms | 35864 KB | Output is correct |
29 | Correct | 278 ms | 35864 KB | Output is correct |
30 | Correct | 307 ms | 35864 KB | Output is correct |
31 | Correct | 321 ms | 35964 KB | Output is correct |
32 | Correct | 235 ms | 35964 KB | Output is correct |
33 | Correct | 232 ms | 35964 KB | Output is correct |
34 | Correct | 273 ms | 35964 KB | Output is correct |
35 | Correct | 220 ms | 35964 KB | Output is correct |
36 | Correct | 216 ms | 35964 KB | Output is correct |
37 | Correct | 221 ms | 35964 KB | Output is correct |
38 | Correct | 425 ms | 53944 KB | Output is correct |
39 | Correct | 456 ms | 60288 KB | Output is correct |
40 | Correct | 409 ms | 60288 KB | Output is correct |
41 | Correct | 482 ms | 60608 KB | Output is correct |
42 | Correct | 249 ms | 60608 KB | Output is correct |
43 | Correct | 234 ms | 60608 KB | Output is correct |
44 | Correct | 344 ms | 60608 KB | Output is correct |
45 | Correct | 342 ms | 60608 KB | Output is correct |
46 | Correct | 333 ms | 60608 KB | Output is correct |
47 | Correct | 244 ms | 60608 KB | Output is correct |
48 | Correct | 280 ms | 60608 KB | Output is correct |
49 | Correct | 357 ms | 60608 KB | Output is correct |
50 | Correct | 326 ms | 61912 KB | Output is correct |
51 | Correct | 334 ms | 72356 KB | Output is correct |
52 | Correct | 318 ms | 81464 KB | Output is correct |
53 | Correct | 371 ms | 98408 KB | Output is correct |
54 | Correct | 465 ms | 117404 KB | Output is correct |
55 | Correct | 357 ms | 122196 KB | Output is correct |