답안 #257391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257391 2020-08-04T08:14:08 Z YJU Long Mansion (JOI17_long_mansion) C++14
100 / 100
773 ms 75896 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;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 24192 KB Output is correct
2 Correct 26 ms 24192 KB Output is correct
3 Correct 18 ms 24320 KB Output is correct
4 Correct 16 ms 24192 KB Output is correct
5 Correct 21 ms 24224 KB Output is correct
6 Correct 18 ms 24192 KB Output is correct
7 Correct 22 ms 24192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 24192 KB Output is correct
2 Correct 26 ms 24192 KB Output is correct
3 Correct 18 ms 24320 KB Output is correct
4 Correct 16 ms 24192 KB Output is correct
5 Correct 21 ms 24224 KB Output is correct
6 Correct 18 ms 24192 KB Output is correct
7 Correct 22 ms 24192 KB Output is correct
8 Correct 116 ms 30072 KB Output is correct
9 Correct 118 ms 30020 KB Output is correct
10 Correct 118 ms 30328 KB Output is correct
11 Correct 129 ms 30840 KB Output is correct
12 Correct 114 ms 29688 KB Output is correct
13 Correct 122 ms 30200 KB Output is correct
14 Correct 124 ms 30200 KB Output is correct
15 Correct 120 ms 30200 KB Output is correct
16 Correct 115 ms 29944 KB Output is correct
17 Correct 113 ms 30200 KB Output is correct
18 Correct 112 ms 30200 KB Output is correct
19 Correct 114 ms 30200 KB Output is correct
20 Correct 116 ms 30200 KB Output is correct
21 Correct 112 ms 29944 KB Output is correct
22 Correct 112 ms 30072 KB Output is correct
23 Correct 114 ms 29944 KB Output is correct
24 Correct 113 ms 29944 KB Output is correct
25 Correct 112 ms 29944 KB Output is correct
26 Correct 113 ms 29944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 374 ms 49500 KB Output is correct
2 Correct 394 ms 55800 KB Output is correct
3 Correct 357 ms 54264 KB Output is correct
4 Correct 542 ms 56440 KB Output is correct
5 Correct 385 ms 56184 KB Output is correct
6 Correct 249 ms 43900 KB Output is correct
7 Correct 234 ms 44024 KB Output is correct
8 Correct 232 ms 44024 KB Output is correct
9 Correct 232 ms 44024 KB Output is correct
10 Correct 222 ms 44152 KB Output is correct
11 Correct 223 ms 44152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 24192 KB Output is correct
2 Correct 26 ms 24192 KB Output is correct
3 Correct 18 ms 24320 KB Output is correct
4 Correct 16 ms 24192 KB Output is correct
5 Correct 21 ms 24224 KB Output is correct
6 Correct 18 ms 24192 KB Output is correct
7 Correct 22 ms 24192 KB Output is correct
8 Correct 116 ms 30072 KB Output is correct
9 Correct 118 ms 30020 KB Output is correct
10 Correct 118 ms 30328 KB Output is correct
11 Correct 129 ms 30840 KB Output is correct
12 Correct 114 ms 29688 KB Output is correct
13 Correct 122 ms 30200 KB Output is correct
14 Correct 124 ms 30200 KB Output is correct
15 Correct 120 ms 30200 KB Output is correct
16 Correct 115 ms 29944 KB Output is correct
17 Correct 113 ms 30200 KB Output is correct
18 Correct 112 ms 30200 KB Output is correct
19 Correct 114 ms 30200 KB Output is correct
20 Correct 116 ms 30200 KB Output is correct
21 Correct 112 ms 29944 KB Output is correct
22 Correct 112 ms 30072 KB Output is correct
23 Correct 114 ms 29944 KB Output is correct
24 Correct 113 ms 29944 KB Output is correct
25 Correct 112 ms 29944 KB Output is correct
26 Correct 113 ms 29944 KB Output is correct
27 Correct 374 ms 49500 KB Output is correct
28 Correct 394 ms 55800 KB Output is correct
29 Correct 357 ms 54264 KB Output is correct
30 Correct 542 ms 56440 KB Output is correct
31 Correct 385 ms 56184 KB Output is correct
32 Correct 249 ms 43900 KB Output is correct
33 Correct 234 ms 44024 KB Output is correct
34 Correct 232 ms 44024 KB Output is correct
35 Correct 232 ms 44024 KB Output is correct
36 Correct 222 ms 44152 KB Output is correct
37 Correct 223 ms 44152 KB Output is correct
38 Correct 773 ms 73080 KB Output is correct
39 Correct 762 ms 75896 KB Output is correct
40 Correct 610 ms 68728 KB Output is correct
41 Correct 468 ms 74292 KB Output is correct
42 Correct 231 ms 43896 KB Output is correct
43 Correct 253 ms 45024 KB Output is correct
44 Correct 381 ms 59896 KB Output is correct
45 Correct 397 ms 60280 KB Output is correct
46 Correct 435 ms 60920 KB Output is correct
47 Correct 268 ms 45688 KB Output is correct
48 Correct 282 ms 45432 KB Output is correct
49 Correct 420 ms 60664 KB Output is correct
50 Correct 384 ms 60920 KB Output is correct
51 Correct 375 ms 61048 KB Output is correct
52 Correct 239 ms 52344 KB Output is correct
53 Correct 310 ms 63612 KB Output is correct
54 Correct 339 ms 71160 KB Output is correct
55 Correct 299 ms 61944 KB Output is correct