# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
582066 | 2022-06-23T10:53:08 Z | urd05 | Long Mansion (JOI17_long_mansion) | C++17 | 1101 ms | 219668 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<P> vl; vector<P> erl; vector<P> vr; vector<P> err; 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.push_back(P(pos,i)); err.push_back(P(i,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.push_back(P(i+1,i+1)); erl.push_back(P(pos,i+1)); } } pql.push(1); pqr.push(n); int indl=0; int indr=0; int indle=0; int indre=0; sort(vl.begin(),vl.end()); sort(vr.begin(),vr.end()); sort(erl.begin(),erl.end()); sort(err.begin(),err.end()); for(int i=1;i<=n;i++) { while(indl<vl.size()&&vl[indl].first==i) { pql.push(vl[indl++].second); } while (indr<vr.size()&&vr[indr].first==i) { pqr.push(vr[indr++].second); } 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()); while(indle<erl.size()&&erl[indle].first==i) { ple.push(erl[indle++].second); } while (indre<err.size()&&err[indre].first==i) { pre.push(err[indre++].second); } //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 | 29 ms | 47692 KB | Output is correct |
2 | Correct | 28 ms | 47952 KB | Output is correct |
3 | Correct | 35 ms | 48204 KB | Output is correct |
4 | Correct | 28 ms | 47700 KB | Output is correct |
5 | Correct | 26 ms | 47676 KB | Output is correct |
6 | Correct | 28 ms | 47680 KB | Output is correct |
7 | Correct | 28 ms | 47628 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 47692 KB | Output is correct |
2 | Correct | 28 ms | 47952 KB | Output is correct |
3 | Correct | 35 ms | 48204 KB | Output is correct |
4 | Correct | 28 ms | 47700 KB | Output is correct |
5 | Correct | 26 ms | 47676 KB | Output is correct |
6 | Correct | 28 ms | 47680 KB | Output is correct |
7 | Correct | 28 ms | 47628 KB | Output is correct |
8 | Correct | 161 ms | 49164 KB | Output is correct |
9 | Correct | 163 ms | 49152 KB | Output is correct |
10 | Correct | 147 ms | 49528 KB | Output is correct |
11 | Correct | 142 ms | 50060 KB | Output is correct |
12 | Correct | 151 ms | 49172 KB | Output is correct |
13 | Correct | 138 ms | 49464 KB | Output is correct |
14 | Correct | 140 ms | 49388 KB | Output is correct |
15 | Correct | 134 ms | 49476 KB | Output is correct |
16 | Correct | 146 ms | 49628 KB | Output is correct |
17 | Correct | 136 ms | 49488 KB | Output is correct |
18 | Correct | 135 ms | 49456 KB | Output is correct |
19 | Correct | 137 ms | 49484 KB | Output is correct |
20 | Correct | 134 ms | 49612 KB | Output is correct |
21 | Correct | 124 ms | 49688 KB | Output is correct |
22 | Correct | 138 ms | 49460 KB | Output is correct |
23 | Correct | 141 ms | 49304 KB | Output is correct |
24 | Correct | 139 ms | 49220 KB | Output is correct |
25 | Correct | 140 ms | 49204 KB | Output is correct |
26 | Correct | 142 ms | 49240 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 305 ms | 71696 KB | Output is correct |
2 | Correct | 351 ms | 70476 KB | Output is correct |
3 | Correct | 293 ms | 70576 KB | Output is correct |
4 | Correct | 330 ms | 71588 KB | Output is correct |
5 | Correct | 310 ms | 71580 KB | Output is correct |
6 | Correct | 324 ms | 70628 KB | Output is correct |
7 | Correct | 252 ms | 71316 KB | Output is correct |
8 | Correct | 264 ms | 71440 KB | Output is correct |
9 | Correct | 273 ms | 71552 KB | Output is correct |
10 | Correct | 255 ms | 71596 KB | Output is correct |
11 | Correct | 253 ms | 71504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 47692 KB | Output is correct |
2 | Correct | 28 ms | 47952 KB | Output is correct |
3 | Correct | 35 ms | 48204 KB | Output is correct |
4 | Correct | 28 ms | 47700 KB | Output is correct |
5 | Correct | 26 ms | 47676 KB | Output is correct |
6 | Correct | 28 ms | 47680 KB | Output is correct |
7 | Correct | 28 ms | 47628 KB | Output is correct |
8 | Correct | 161 ms | 49164 KB | Output is correct |
9 | Correct | 163 ms | 49152 KB | Output is correct |
10 | Correct | 147 ms | 49528 KB | Output is correct |
11 | Correct | 142 ms | 50060 KB | Output is correct |
12 | Correct | 151 ms | 49172 KB | Output is correct |
13 | Correct | 138 ms | 49464 KB | Output is correct |
14 | Correct | 140 ms | 49388 KB | Output is correct |
15 | Correct | 134 ms | 49476 KB | Output is correct |
16 | Correct | 146 ms | 49628 KB | Output is correct |
17 | Correct | 136 ms | 49488 KB | Output is correct |
18 | Correct | 135 ms | 49456 KB | Output is correct |
19 | Correct | 137 ms | 49484 KB | Output is correct |
20 | Correct | 134 ms | 49612 KB | Output is correct |
21 | Correct | 124 ms | 49688 KB | Output is correct |
22 | Correct | 138 ms | 49460 KB | Output is correct |
23 | Correct | 141 ms | 49304 KB | Output is correct |
24 | Correct | 139 ms | 49220 KB | Output is correct |
25 | Correct | 140 ms | 49204 KB | Output is correct |
26 | Correct | 142 ms | 49240 KB | Output is correct |
27 | Correct | 305 ms | 71696 KB | Output is correct |
28 | Correct | 351 ms | 70476 KB | Output is correct |
29 | Correct | 293 ms | 70576 KB | Output is correct |
30 | Correct | 330 ms | 71588 KB | Output is correct |
31 | Correct | 310 ms | 71580 KB | Output is correct |
32 | Correct | 324 ms | 70628 KB | Output is correct |
33 | Correct | 252 ms | 71316 KB | Output is correct |
34 | Correct | 264 ms | 71440 KB | Output is correct |
35 | Correct | 273 ms | 71552 KB | Output is correct |
36 | Correct | 255 ms | 71596 KB | Output is correct |
37 | Correct | 253 ms | 71504 KB | Output is correct |
38 | Correct | 1101 ms | 136776 KB | Output is correct |
39 | Runtime error | 415 ms | 219668 KB | Execution killed with signal 11 |
40 | Halted | 0 ms | 0 KB | - |