# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21040 | 2017-04-01T06:39:41 Z | ainta | Long Mansion (JOI17_long_mansion) | C++14 | 1363 ms | 65844 KB |
#include<cstdio> #include<algorithm> #include<vector> #include<set> #define SZ 524288 using namespace std; vector<int>E[501000]; int C[501000], L[501000], R[501000], LL[501000], RR[501000]; int n, Q; set<int>Set; struct point{ int x, num; bool operator<(const point &p)const{ return x<p.x; } }ord[501000]; struct Tree{ int Mn, Mx; }IT[SZ+SZ]; Tree Get(int b, int e){ b += SZ, e += SZ; Tree r = {n+1,0}; while(b<=e){ r.Mn = min(r.Mn,min(IT[b].Mn,IT[e].Mn)); r.Mx = max(r.Mx,max(IT[b].Mx,IT[e].Mx)); b=(b+1)>>1,e=(e-1)>>1; } return r; } int main(){ int i, a, b; scanf("%d",&n); for(i=1;i<n;i++)scanf("%d",&C[i]); for(i=1;i<=n;i++){ scanf("%d",&a); while(a--){ scanf("%d",&b); E[b].push_back(i); } } for(i=1;i<=n;i++){ a = C[i-1]; if(E[a].empty()) L[i] = n+1; else{ int t = lower_bound(E[a].begin(),E[a].end(),i)-E[a].begin(); if(t == E[a].size())L[i] = n+1; else L[i] = E[a][t]; } } for(i=n;i>=1;i--){ a = C[i]; if(E[a].empty()) R[i] = 0; else{ int t = lower_bound(E[a].begin(),E[a].end(),i+1)-E[a].begin(); if(t == 0)R[i] = 0; else R[i] = E[a][t-1]; } } for(i=1;i<=n;i++){ ord[i].x=L[i],ord[i].num = i; Set.insert(i); } sort(ord+1,ord+n+1); int pv = 1; for(i=1;i<=n;i++){ LL[i] = n+1; while(pv<=n && ord[pv].x <= i){ Set.erase(ord[pv].num); pv++; } if(Set.empty())continue; auto it = Set.lower_bound(R[i]+1); if(it!=Set.end() && (*it) <= i){ LL[i] = *it; } } Set.clear(); for(i=1;i<=n;i++){ ord[i].x=R[i],ord[i].num = i; Set.insert(i); } sort(ord+1,ord+n+1); pv = n; for(i=n;i>=1;i--){ RR[i] = 0; while(pv>=1 && ord[pv].x >= i){ Set.erase(ord[pv].num); pv--; } if(Set.empty())continue; auto it = Set.lower_bound(L[i]); if(it!=Set.begin()){ it--; if((*it) >= i)RR[i] = *it; } } scanf("%d",&Q); for(i=1;i<=n;i++){ a = SZ+i; IT[a].Mn = LL[i], IT[a].Mx = RR[i]; while(a!=1){ a>>=1; IT[a].Mn = min(IT[a+a].Mn,IT[a+a+1].Mn); IT[a].Mx = max(IT[a+a].Mx,IT[a+a+1].Mx); } } while(Q--){ scanf("%d%d",&a,&b); if(a<b){ if(Get(a,b-1).Mn <= a)puts("NO"); else puts("YES"); } else{ if(Get(b+1,a).Mx >= a)puts("NO"); else puts("YES"); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 34944 KB | Output is correct |
2 | Correct | 9 ms | 34944 KB | Output is correct |
3 | Correct | 6 ms | 35076 KB | Output is correct |
4 | Correct | 9 ms | 34944 KB | Output is correct |
5 | Correct | 3 ms | 34944 KB | Output is correct |
6 | Correct | 6 ms | 34944 KB | Output is correct |
7 | Correct | 3 ms | 34944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 34944 KB | Output is correct |
2 | Correct | 9 ms | 34944 KB | Output is correct |
3 | Correct | 6 ms | 35076 KB | Output is correct |
4 | Correct | 9 ms | 34944 KB | Output is correct |
5 | Correct | 3 ms | 34944 KB | Output is correct |
6 | Correct | 6 ms | 34944 KB | Output is correct |
7 | Correct | 3 ms | 34944 KB | Output is correct |
8 | Correct | 169 ms | 34944 KB | Output is correct |
9 | Correct | 173 ms | 34944 KB | Output is correct |
10 | Correct | 163 ms | 34944 KB | Output is correct |
11 | Correct | 186 ms | 35076 KB | Output is correct |
12 | Correct | 153 ms | 34944 KB | Output is correct |
13 | Correct | 156 ms | 34944 KB | Output is correct |
14 | Correct | 146 ms | 34944 KB | Output is correct |
15 | Correct | 163 ms | 34944 KB | Output is correct |
16 | Correct | 143 ms | 34944 KB | Output is correct |
17 | Correct | 166 ms | 34944 KB | Output is correct |
18 | Correct | 159 ms | 34944 KB | Output is correct |
19 | Correct | 156 ms | 34944 KB | Output is correct |
20 | Correct | 159 ms | 34944 KB | Output is correct |
21 | Correct | 156 ms | 34944 KB | Output is correct |
22 | Correct | 146 ms | 34944 KB | Output is correct |
23 | Correct | 163 ms | 34944 KB | Output is correct |
24 | Correct | 153 ms | 34944 KB | Output is correct |
25 | Correct | 129 ms | 34944 KB | Output is correct |
26 | Correct | 149 ms | 34944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 406 ms | 42084 KB | Output is correct |
2 | Correct | 459 ms | 41480 KB | Output is correct |
3 | Correct | 379 ms | 42096 KB | Output is correct |
4 | Correct | 413 ms | 41916 KB | Output is correct |
5 | Correct | 379 ms | 41748 KB | Output is correct |
6 | Correct | 349 ms | 40744 KB | Output is correct |
7 | Correct | 329 ms | 40760 KB | Output is correct |
8 | Correct | 313 ms | 40800 KB | Output is correct |
9 | Correct | 329 ms | 40752 KB | Output is correct |
10 | Correct | 326 ms | 40788 KB | Output is correct |
11 | Correct | 339 ms | 40748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 34944 KB | Output is correct |
2 | Correct | 9 ms | 34944 KB | Output is correct |
3 | Correct | 6 ms | 35076 KB | Output is correct |
4 | Correct | 9 ms | 34944 KB | Output is correct |
5 | Correct | 3 ms | 34944 KB | Output is correct |
6 | Correct | 6 ms | 34944 KB | Output is correct |
7 | Correct | 3 ms | 34944 KB | Output is correct |
8 | Correct | 169 ms | 34944 KB | Output is correct |
9 | Correct | 173 ms | 34944 KB | Output is correct |
10 | Correct | 163 ms | 34944 KB | Output is correct |
11 | Correct | 186 ms | 35076 KB | Output is correct |
12 | Correct | 153 ms | 34944 KB | Output is correct |
13 | Correct | 156 ms | 34944 KB | Output is correct |
14 | Correct | 146 ms | 34944 KB | Output is correct |
15 | Correct | 163 ms | 34944 KB | Output is correct |
16 | Correct | 143 ms | 34944 KB | Output is correct |
17 | Correct | 166 ms | 34944 KB | Output is correct |
18 | Correct | 159 ms | 34944 KB | Output is correct |
19 | Correct | 156 ms | 34944 KB | Output is correct |
20 | Correct | 159 ms | 34944 KB | Output is correct |
21 | Correct | 156 ms | 34944 KB | Output is correct |
22 | Correct | 146 ms | 34944 KB | Output is correct |
23 | Correct | 163 ms | 34944 KB | Output is correct |
24 | Correct | 153 ms | 34944 KB | Output is correct |
25 | Correct | 129 ms | 34944 KB | Output is correct |
26 | Correct | 149 ms | 34944 KB | Output is correct |
27 | Correct | 406 ms | 42084 KB | Output is correct |
28 | Correct | 459 ms | 41480 KB | Output is correct |
29 | Correct | 379 ms | 42096 KB | Output is correct |
30 | Correct | 413 ms | 41916 KB | Output is correct |
31 | Correct | 379 ms | 41748 KB | Output is correct |
32 | Correct | 349 ms | 40744 KB | Output is correct |
33 | Correct | 329 ms | 40760 KB | Output is correct |
34 | Correct | 313 ms | 40800 KB | Output is correct |
35 | Correct | 329 ms | 40752 KB | Output is correct |
36 | Correct | 326 ms | 40788 KB | Output is correct |
37 | Correct | 339 ms | 40748 KB | Output is correct |
38 | Correct | 1349 ms | 56328 KB | Output is correct |
39 | Correct | 1363 ms | 60816 KB | Output is correct |
40 | Correct | 919 ms | 51576 KB | Output is correct |
41 | Correct | 1153 ms | 60372 KB | Output is correct |
42 | Correct | 386 ms | 41148 KB | Output is correct |
43 | Correct | 359 ms | 40884 KB | Output is correct |
44 | Correct | 566 ms | 47616 KB | Output is correct |
45 | Correct | 569 ms | 47880 KB | Output is correct |
46 | Correct | 596 ms | 48012 KB | Output is correct |
47 | Correct | 363 ms | 41280 KB | Output is correct |
48 | Correct | 356 ms | 40752 KB | Output is correct |
49 | Correct | 586 ms | 46956 KB | Output is correct |
50 | Correct | 629 ms | 47616 KB | Output is correct |
51 | Correct | 676 ms | 48408 KB | Output is correct |
52 | Correct | 463 ms | 50184 KB | Output is correct |
53 | Correct | 669 ms | 57804 KB | Output is correct |
54 | Correct | 836 ms | 65844 KB | Output is correct |
55 | Correct | 649 ms | 57828 KB | Output is correct |