Submission #257392

# Submission time Handle Problem Language Result Execution time Memory
257392 2020-08-04T08:14:55 Z YJU Long Mansion (JOI17_long_mansion) C++14
100 / 100
736 ms 64760 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=5e5+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<62);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n,c[N],t,x,y,goR[N],q;
pll range[N];
set<ll> exi[N];

bool in(ll L,ll R,ll ty){
	auto it=exi[ty].lwb(L);
	if(it!=exi[ty].end()&&(*it)<=R)return 1;
	return 0;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP1(i,n-1)cin>>c[i];
	REP1(i,n){
		cin>>t;
		while(t--)cin>>x,exi[x].insert(i);
	}
	for(ll i=n;i>=1;i--){
		goR[i]=i;
		while(goR[i]<n&&in(i,goR[i],c[goR[i]])){
			++goR[i];
			goR[i]=goR[goR[i]];
		}
		range[i]=mp(i,goR[i]);
	}
	for(ll i=1;i<=n;i++){
		while(1){
			if(range[i].X>1&&in(range[i].X,range[i].Y,c[range[i].X-1])){
				ll tt=range[i].X-1;
				range[i].X=min(range[i].X,range[tt].X);
				range[i].Y=max(range[i].Y,range[tt].Y);
			}else if(range[i].Y<n&&in(range[i].X,range[i].Y,c[range[i].Y])){
				++range[i].Y;
				range[i].Y=goR[range[i].Y];
			}else break;
		}
	}
	cin>>q;
	while(q--){
		cin>>x>>y;
		cout<<(range[x].X<=y&&range[x].Y>=y?"YES\n":"NO\n");
	}
	return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 16 ms 24192 KB Output is correct
2 Correct 16 ms 24192 KB Output is correct
3 Correct 20 ms 24296 KB Output is correct
4 Correct 16 ms 24064 KB Output is correct
5 Correct 15 ms 24064 KB Output is correct
6 Correct 15 ms 24064 KB Output is correct
7 Correct 15 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 24192 KB Output is correct
2 Correct 16 ms 24192 KB Output is correct
3 Correct 20 ms 24296 KB Output is correct
4 Correct 16 ms 24064 KB Output is correct
5 Correct 15 ms 24064 KB Output is correct
6 Correct 15 ms 24064 KB Output is correct
7 Correct 15 ms 24064 KB Output is correct
8 Correct 117 ms 25668 KB Output is correct
9 Correct 122 ms 25592 KB Output is correct
10 Correct 114 ms 25848 KB Output is correct
11 Correct 115 ms 25976 KB Output is correct
12 Correct 103 ms 25848 KB Output is correct
13 Correct 113 ms 25884 KB Output is correct
14 Correct 112 ms 25852 KB Output is correct
15 Correct 113 ms 25948 KB Output is correct
16 Correct 110 ms 26108 KB Output is correct
17 Correct 110 ms 25848 KB Output is correct
18 Correct 115 ms 25848 KB Output is correct
19 Correct 110 ms 25848 KB Output is correct
20 Correct 114 ms 26252 KB Output is correct
21 Correct 107 ms 26104 KB Output is correct
22 Correct 109 ms 25940 KB Output is correct
23 Correct 108 ms 25592 KB Output is correct
24 Correct 115 ms 25720 KB Output is correct
25 Correct 117 ms 25592 KB Output is correct
26 Correct 121 ms 25592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 415 ms 49428 KB Output is correct
2 Correct 399 ms 48760 KB Output is correct
3 Correct 312 ms 47296 KB Output is correct
4 Correct 378 ms 49272 KB Output is correct
5 Correct 381 ms 49144 KB Output is correct
6 Correct 241 ms 37624 KB Output is correct
7 Correct 222 ms 38008 KB Output is correct
8 Correct 225 ms 37940 KB Output is correct
9 Correct 238 ms 38136 KB Output is correct
10 Correct 239 ms 38136 KB Output is correct
11 Correct 232 ms 38136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 24192 KB Output is correct
2 Correct 16 ms 24192 KB Output is correct
3 Correct 20 ms 24296 KB Output is correct
4 Correct 16 ms 24064 KB Output is correct
5 Correct 15 ms 24064 KB Output is correct
6 Correct 15 ms 24064 KB Output is correct
7 Correct 15 ms 24064 KB Output is correct
8 Correct 117 ms 25668 KB Output is correct
9 Correct 122 ms 25592 KB Output is correct
10 Correct 114 ms 25848 KB Output is correct
11 Correct 115 ms 25976 KB Output is correct
12 Correct 103 ms 25848 KB Output is correct
13 Correct 113 ms 25884 KB Output is correct
14 Correct 112 ms 25852 KB Output is correct
15 Correct 113 ms 25948 KB Output is correct
16 Correct 110 ms 26108 KB Output is correct
17 Correct 110 ms 25848 KB Output is correct
18 Correct 115 ms 25848 KB Output is correct
19 Correct 110 ms 25848 KB Output is correct
20 Correct 114 ms 26252 KB Output is correct
21 Correct 107 ms 26104 KB Output is correct
22 Correct 109 ms 25940 KB Output is correct
23 Correct 108 ms 25592 KB Output is correct
24 Correct 115 ms 25720 KB Output is correct
25 Correct 117 ms 25592 KB Output is correct
26 Correct 121 ms 25592 KB Output is correct
27 Correct 415 ms 49428 KB Output is correct
28 Correct 399 ms 48760 KB Output is correct
29 Correct 312 ms 47296 KB Output is correct
30 Correct 378 ms 49272 KB Output is correct
31 Correct 381 ms 49144 KB Output is correct
32 Correct 241 ms 37624 KB Output is correct
33 Correct 222 ms 38008 KB Output is correct
34 Correct 225 ms 37940 KB Output is correct
35 Correct 238 ms 38136 KB Output is correct
36 Correct 239 ms 38136 KB Output is correct
37 Correct 232 ms 38136 KB Output is correct
38 Correct 736 ms 61432 KB Output is correct
39 Correct 696 ms 64504 KB Output is correct
40 Correct 634 ms 58220 KB Output is correct
41 Correct 483 ms 64760 KB Output is correct
42 Correct 266 ms 36472 KB Output is correct
43 Correct 274 ms 37496 KB Output is correct
44 Correct 359 ms 49960 KB Output is correct
45 Correct 369 ms 50172 KB Output is correct
46 Correct 403 ms 50552 KB Output is correct
47 Correct 258 ms 38188 KB Output is correct
48 Correct 271 ms 38392 KB Output is correct
49 Correct 417 ms 50740 KB Output is correct
50 Correct 388 ms 50600 KB Output is correct
51 Correct 340 ms 50680 KB Output is correct
52 Correct 226 ms 42872 KB Output is correct
53 Correct 293 ms 52600 KB Output is correct
54 Correct 341 ms 58488 KB Output is correct
55 Correct 267 ms 50680 KB Output is correct