# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
582057 | 2022-06-23T10:42:22 Z | urd05 | Long Mansion (JOI17_long_mansion) | C++17 | 1302 ms | 262144 KB |
#include <bits/stdc++.h> using namespace std; int n; int c[500000]; vector<int> vec[500001]; typedef pair<int,int> P; vector<int> v[500001]; P ret[500001]; int l[500001]; int r[500001]; vector<int> lev[500001]; //l[i]의 인버스 vector<int> rev[500001]; //r[i]의 인버스 priority_queue<int,vector<int>,greater<int>> pqr; priority_queue<int,vector<int>,greater<int>> pre; priority_queue<int> pql; priority_queue<int> ple; vector<int> vl[500001]; vector<int> erl[500001]; vector<int> vr[500001]; vector<int> err[500001]; int main(void) { scanf("%d",&n); for(int i=1;i<n;i++) { scanf("%d",&c[i]); vec[c[i]].push_back(i*2+1); } for(int i=1;i<=n;i++) { int k; scanf("%d",&k); for(int j=0;j<k;j++) { int x; scanf("%d",&x); v[x].push_back(i*2); } } for(int i=1;i<=n;i++) { vec[i].push_back(1); vec[i].push_back(2*n+1); sort(vec[i].begin(),vec[i].end()); v[i].push_back(0); v[i].push_back(2*n+2); sort(v[i].begin(),v[i].end()); } rev[n].push_back(0); lev[1].push_back(n); for(int i=1;i<n;i++) { int pos=2*i+1; auto iter=lower_bound(v[c[i]].begin(),v[c[i]].end(),pos); r[i]=(*iter)/2; iter--; l[i]=(*iter)/2; rev[r[i]].push_back(i); lev[l[i]].push_back(i); } set<int> s; for(int i=0;i<rev[n+1].size();i++) { s.insert(rev[n+1][i]); } for(int i=n-1;i>0;i--) { for(int j=0;j<rev[i+1].size();j++) { s.insert(rev[i+1][j]); } auto iter=s.lower_bound(l[i]); if (iter==s.end()) { continue; } int pos=(*s.lower_bound(l[i]))+1; vr[pos].push_back(i); err[i].push_back(i); } s.clear(); for(int i=0;i<lev[0].size();i++) { s.insert(lev[0][i]); } for(int i=1;i<n;i++) { for(int j=0;j<lev[i].size();j++) { s.insert(lev[i][j]); } auto iter=s.lower_bound(r[i]); if (iter==s.begin()) { continue; } iter--; int pos=(*iter); if (i+1<=pos) { vl[i+1].push_back(i+1); erl[pos].push_back(i+1); } } pql.push(1); pqr.push(n); for(int i=1;i<=n;i++) { for(int j=0;j<vl[i].size();j++) { pql.push(vl[i][j]); } for(int j=0;j<vr[i].size();j++) { pqr.push(vr[i][j]); } while (!ple.empty()&&pql.top()==ple.top()) { pql.pop(); ple.pop(); } while (!pre.empty()&&pqr.top()==pre.top()) { pre.pop(); pqr.pop(); } ret[i]=P(pql.top(),pqr.top()); for(int j=0;j<erl[i].size();j++) { ple.push(erl[i][j]); } for(int j=0;j<err[i].size();j++) { pre.push(err[i][j]); } //printf("%d %d\n",ret[i].first,ret[i].second); } int q; scanf("%d",&q); for(int i=0;i<q;i++) { int x,y; scanf("%d %d",&x,&y); if (ret[x].first<=y&&y<=ret[x].second) { printf("YES\n"); } else { printf("NO\n"); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 94896 KB | Output is correct |
2 | Correct | 54 ms | 95016 KB | Output is correct |
3 | Correct | 57 ms | 95716 KB | Output is correct |
4 | Correct | 52 ms | 94820 KB | Output is correct |
5 | Correct | 59 ms | 94856 KB | Output is correct |
6 | Correct | 57 ms | 94864 KB | Output is correct |
7 | Correct | 53 ms | 94832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 94896 KB | Output is correct |
2 | Correct | 54 ms | 95016 KB | Output is correct |
3 | Correct | 57 ms | 95716 KB | Output is correct |
4 | Correct | 52 ms | 94820 KB | Output is correct |
5 | Correct | 59 ms | 94856 KB | Output is correct |
6 | Correct | 57 ms | 94864 KB | Output is correct |
7 | Correct | 53 ms | 94832 KB | Output is correct |
8 | Correct | 183 ms | 98256 KB | Output is correct |
9 | Correct | 202 ms | 98232 KB | Output is correct |
10 | Correct | 194 ms | 98624 KB | Output is correct |
11 | Correct | 194 ms | 99180 KB | Output is correct |
12 | Correct | 172 ms | 98332 KB | Output is correct |
13 | Correct | 178 ms | 98420 KB | Output is correct |
14 | Correct | 171 ms | 98540 KB | Output is correct |
15 | Correct | 163 ms | 98516 KB | Output is correct |
16 | Correct | 186 ms | 98668 KB | Output is correct |
17 | Correct | 175 ms | 98332 KB | Output is correct |
18 | Correct | 178 ms | 98348 KB | Output is correct |
19 | Correct | 167 ms | 98412 KB | Output is correct |
20 | Correct | 166 ms | 98592 KB | Output is correct |
21 | Correct | 160 ms | 98616 KB | Output is correct |
22 | Correct | 166 ms | 98468 KB | Output is correct |
23 | Correct | 168 ms | 98344 KB | Output is correct |
24 | Correct | 170 ms | 98212 KB | Output is correct |
25 | Correct | 195 ms | 98216 KB | Output is correct |
26 | Correct | 171 ms | 98136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 399 ms | 129084 KB | Output is correct |
2 | Correct | 388 ms | 127628 KB | Output is correct |
3 | Correct | 363 ms | 126920 KB | Output is correct |
4 | Correct | 376 ms | 127908 KB | Output is correct |
5 | Correct | 389 ms | 127784 KB | Output is correct |
6 | Correct | 331 ms | 125856 KB | Output is correct |
7 | Correct | 298 ms | 125916 KB | Output is correct |
8 | Correct | 294 ms | 126156 KB | Output is correct |
9 | Correct | 297 ms | 126160 KB | Output is correct |
10 | Correct | 296 ms | 126324 KB | Output is correct |
11 | Correct | 310 ms | 126240 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 94896 KB | Output is correct |
2 | Correct | 54 ms | 95016 KB | Output is correct |
3 | Correct | 57 ms | 95716 KB | Output is correct |
4 | Correct | 52 ms | 94820 KB | Output is correct |
5 | Correct | 59 ms | 94856 KB | Output is correct |
6 | Correct | 57 ms | 94864 KB | Output is correct |
7 | Correct | 53 ms | 94832 KB | Output is correct |
8 | Correct | 183 ms | 98256 KB | Output is correct |
9 | Correct | 202 ms | 98232 KB | Output is correct |
10 | Correct | 194 ms | 98624 KB | Output is correct |
11 | Correct | 194 ms | 99180 KB | Output is correct |
12 | Correct | 172 ms | 98332 KB | Output is correct |
13 | Correct | 178 ms | 98420 KB | Output is correct |
14 | Correct | 171 ms | 98540 KB | Output is correct |
15 | Correct | 163 ms | 98516 KB | Output is correct |
16 | Correct | 186 ms | 98668 KB | Output is correct |
17 | Correct | 175 ms | 98332 KB | Output is correct |
18 | Correct | 178 ms | 98348 KB | Output is correct |
19 | Correct | 167 ms | 98412 KB | Output is correct |
20 | Correct | 166 ms | 98592 KB | Output is correct |
21 | Correct | 160 ms | 98616 KB | Output is correct |
22 | Correct | 166 ms | 98468 KB | Output is correct |
23 | Correct | 168 ms | 98344 KB | Output is correct |
24 | Correct | 170 ms | 98212 KB | Output is correct |
25 | Correct | 195 ms | 98216 KB | Output is correct |
26 | Correct | 171 ms | 98136 KB | Output is correct |
27 | Correct | 399 ms | 129084 KB | Output is correct |
28 | Correct | 388 ms | 127628 KB | Output is correct |
29 | Correct | 363 ms | 126920 KB | Output is correct |
30 | Correct | 376 ms | 127908 KB | Output is correct |
31 | Correct | 389 ms | 127784 KB | Output is correct |
32 | Correct | 331 ms | 125856 KB | Output is correct |
33 | Correct | 298 ms | 125916 KB | Output is correct |
34 | Correct | 294 ms | 126156 KB | Output is correct |
35 | Correct | 297 ms | 126160 KB | Output is correct |
36 | Correct | 296 ms | 126324 KB | Output is correct |
37 | Correct | 310 ms | 126240 KB | Output is correct |
38 | Correct | 1302 ms | 218612 KB | Output is correct |
39 | Runtime error | 482 ms | 262144 KB | Execution killed with signal 11 |
40 | Halted | 0 ms | 0 KB | - |