답안 #448308

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448308 2021-07-29T14:37:53 Z dutch Long Mansion (JOI17_long_mansion) C++17
100 / 100
560 ms 48812 KB
#include <bits/stdc++.h>
using namespace std;
#define f(z) z = n + 1 - z
 
const int LIM = 5e5+1, INF = 1e9, S = 1<<19;
 
struct SegmentTree{
	vector<int> a; int j, z;
	SegmentTree(int N, int* v) : a(S+S) {
		for(int i=N; --i>=0; ) a[i+S] = v[i];
		for(int i=S; --i; ){
			a[i] = max(a[2*i], a[2*i+1]);
		}
	}
	int rangeMax(int l, int r){
		int x = -INF;
		for(l+=S, r+=S+1; l<r; l/=2, r/=2){
			if(l & 1) x = max(x, a[l++]);
			if(r & 1) x = max(x, a[--r]);
		}
		return x;
	}
	int query(int x, int lx, int rx){
		if(a[x] <= z || rx <= j) return 0;
		if(rx - lx < 2) return lx;
		int mx = (lx + rx) / 2;
		return query(2*x, lx, mx) ? : query(2*x+1, mx, rx);
	}
	int operator()(int L, int V){ //first v[i] s.t. i>=l && v[i]>v
		j = L, z = V; return query(1, 0, S);
	}
};
 
int n, q, c[LIM], l[LIM], r[LIM], block[LIM];
array<int, 2> b[LIM];
bool ans[LIM];
vector<int> a[LIM];
 
void flip(){
	for(int i=1; i<n; ++i){
		f(l[i]), f(r[i]);
	}
	swap(l, r);
	reverse(l+1, l+n);
	reverse(r+1, r+n);
	for(int i=0; i<q; ++i){
		for(int &j : b[i]) f(j);
	}
}
 
void solve(){
	SegmentTree x(n, r);
	block[0] = 0;
	for(int i=1; i<n; ++i){
		block[i] = l[i] ? -min(n, x(l[i], i)) : 0;
	}
	SegmentTree y(n, block);
	
	for(int i=0; i<q; ++i){
		auto [u, v] = b[i];
		if(u < v) ans[i] = -y.rangeMax(u, v-1) >= u;
	}
}
 
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i=1; i<n; ++i) cin >> c[i];
	for(int i=1, j; i<=n; ++i){
		cin >> j;
		a[i].resize(j);
		for(int &k : a[i]) cin >> k;
	}
 
	cin >> q;
	for(int i=0; i<q; ++i){
		cin >> b[i][0] >> b[i][1];
	}
 
	for(int i=1; i<n; ++i){
		for(int &j : a[i]) block[j] = i;
		l[i] = block[c[i]];
	}
	fill(block, block+n+1, n+1);
	for(int i=n; i>1; --i){
		for(int &j : a[i]) block[j] = i;
		r[i-1] = block[c[i-1]];
	}
	solve();
	flip();
	solve();

	for(int i=0; i<q; ++i){
		cout << (ans[i] ? "YES" : "NO") << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 24260 KB Output is correct
2 Correct 25 ms 24408 KB Output is correct
3 Correct 23 ms 24484 KB Output is correct
4 Correct 21 ms 24396 KB Output is correct
5 Correct 21 ms 24340 KB Output is correct
6 Correct 22 ms 24380 KB Output is correct
7 Correct 21 ms 24388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 24260 KB Output is correct
2 Correct 25 ms 24408 KB Output is correct
3 Correct 23 ms 24484 KB Output is correct
4 Correct 21 ms 24396 KB Output is correct
5 Correct 21 ms 24340 KB Output is correct
6 Correct 22 ms 24380 KB Output is correct
7 Correct 21 ms 24388 KB Output is correct
8 Correct 202 ms 29272 KB Output is correct
9 Correct 199 ms 29316 KB Output is correct
10 Correct 198 ms 29344 KB Output is correct
11 Correct 204 ms 29528 KB Output is correct
12 Correct 184 ms 29172 KB Output is correct
13 Correct 162 ms 29372 KB Output is correct
14 Correct 165 ms 29252 KB Output is correct
15 Correct 169 ms 29244 KB Output is correct
16 Correct 174 ms 29236 KB Output is correct
17 Correct 157 ms 29336 KB Output is correct
18 Correct 165 ms 29292 KB Output is correct
19 Correct 176 ms 29344 KB Output is correct
20 Correct 171 ms 29216 KB Output is correct
21 Correct 179 ms 29244 KB Output is correct
22 Correct 180 ms 29320 KB Output is correct
23 Correct 166 ms 29244 KB Output is correct
24 Correct 159 ms 29372 KB Output is correct
25 Correct 158 ms 29244 KB Output is correct
26 Correct 157 ms 29244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 306 ms 32796 KB Output is correct
2 Correct 314 ms 33328 KB Output is correct
3 Correct 313 ms 33212 KB Output is correct
4 Correct 307 ms 33184 KB Output is correct
5 Correct 306 ms 33276 KB Output is correct
6 Correct 245 ms 33164 KB Output is correct
7 Correct 262 ms 33084 KB Output is correct
8 Correct 267 ms 33108 KB Output is correct
9 Correct 263 ms 33056 KB Output is correct
10 Correct 262 ms 33064 KB Output is correct
11 Correct 265 ms 33216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 24260 KB Output is correct
2 Correct 25 ms 24408 KB Output is correct
3 Correct 23 ms 24484 KB Output is correct
4 Correct 21 ms 24396 KB Output is correct
5 Correct 21 ms 24340 KB Output is correct
6 Correct 22 ms 24380 KB Output is correct
7 Correct 21 ms 24388 KB Output is correct
8 Correct 202 ms 29272 KB Output is correct
9 Correct 199 ms 29316 KB Output is correct
10 Correct 198 ms 29344 KB Output is correct
11 Correct 204 ms 29528 KB Output is correct
12 Correct 184 ms 29172 KB Output is correct
13 Correct 162 ms 29372 KB Output is correct
14 Correct 165 ms 29252 KB Output is correct
15 Correct 169 ms 29244 KB Output is correct
16 Correct 174 ms 29236 KB Output is correct
17 Correct 157 ms 29336 KB Output is correct
18 Correct 165 ms 29292 KB Output is correct
19 Correct 176 ms 29344 KB Output is correct
20 Correct 171 ms 29216 KB Output is correct
21 Correct 179 ms 29244 KB Output is correct
22 Correct 180 ms 29320 KB Output is correct
23 Correct 166 ms 29244 KB Output is correct
24 Correct 159 ms 29372 KB Output is correct
25 Correct 158 ms 29244 KB Output is correct
26 Correct 157 ms 29244 KB Output is correct
27 Correct 306 ms 32796 KB Output is correct
28 Correct 314 ms 33328 KB Output is correct
29 Correct 313 ms 33212 KB Output is correct
30 Correct 307 ms 33184 KB Output is correct
31 Correct 306 ms 33276 KB Output is correct
32 Correct 245 ms 33164 KB Output is correct
33 Correct 262 ms 33084 KB Output is correct
34 Correct 267 ms 33108 KB Output is correct
35 Correct 263 ms 33056 KB Output is correct
36 Correct 262 ms 33064 KB Output is correct
37 Correct 265 ms 33216 KB Output is correct
38 Correct 536 ms 44928 KB Output is correct
39 Correct 560 ms 48780 KB Output is correct
40 Correct 484 ms 40932 KB Output is correct
41 Correct 499 ms 48812 KB Output is correct
42 Correct 232 ms 33092 KB Output is correct
43 Correct 237 ms 33212 KB Output is correct
44 Correct 304 ms 36924 KB Output is correct
45 Correct 318 ms 36896 KB Output is correct
46 Correct 321 ms 36896 KB Output is correct
47 Correct 272 ms 32996 KB Output is correct
48 Correct 267 ms 33084 KB Output is correct
49 Correct 340 ms 36968 KB Output is correct
50 Correct 344 ms 36768 KB Output is correct
51 Correct 354 ms 36768 KB Output is correct
52 Correct 274 ms 36832 KB Output is correct
53 Correct 338 ms 40744 KB Output is correct
54 Correct 379 ms 44680 KB Output is correct
55 Correct 320 ms 40700 KB Output is correct