답안 #505491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
505491 2022-01-11T05:25:41 Z Koosha_mv Long Mansion (JOI17_long_mansion) C++14
100 / 100
386 ms 32124 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=5e5+99;

int n,t,q,a[N],L[N],R[N],col[N];
vector<int> v[N];

void solve(int x){
	L[x]=R[x]=x;
	while(1){
		int b=0;
		if(1<L[x] && lower_bound(all(v[col[L[x]-1]]),L[x])!=upper_bound(all(v[col[L[x]-1]]),R[x])){
			int u=L[x]-1;
			L[x]=u;
			if(L[u]>0){
				minm(L[x],L[u]);
			}
			if(R[u]>0){
				maxm(R[x],R[u]);
			}
			b=1;
		}	
		if(R[x]<n && lower_bound(all(v[col[R[x]]]),L[x])!=upper_bound(all(v[col[R[x]]]),R[x])){
			int u=R[x]+1;
			R[x]=u;
			if(L[u]>0){
				minm(L[x],L[u]);
			}
			if(R[u]>0){
				maxm(R[x],R[u]);
			}
			b=1;
		}
		if(!b) break;
	}
	//cout<<x<<" "<<L[x]<<" "<<R[x]<<endl;
}

int main(){
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	srand(time(NULL));
	cin>>n;
	f(i,1,n) cin>>col[i];
	f(i,1,n+1){
		int k,x;
		cin>>k;
		f(j,0,k){
			cin>>x;
			v[x].pb(i);
		}
	}
	vector<int> vec(n);
	iota(all(vec),1);
	for(auto x : vec){
		solve(x);
	}
	cin>>q;
	f(i,0,q){
		int u,v;
		cin>>u>>v;
		if(L[u]<=v && v<=R[u]){
			cout<<"YES"<<'\n';
		}
		else{
			cout<<"NO"<<'\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12096 KB Output is correct
2 Correct 8 ms 12108 KB Output is correct
3 Correct 9 ms 12108 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 11 ms 12108 KB Output is correct
6 Correct 8 ms 12172 KB Output is correct
7 Correct 8 ms 12064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12096 KB Output is correct
2 Correct 8 ms 12108 KB Output is correct
3 Correct 9 ms 12108 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 11 ms 12108 KB Output is correct
6 Correct 8 ms 12172 KB Output is correct
7 Correct 8 ms 12064 KB Output is correct
8 Correct 102 ms 13668 KB Output is correct
9 Correct 98 ms 13564 KB Output is correct
10 Correct 97 ms 13732 KB Output is correct
11 Correct 121 ms 13956 KB Output is correct
12 Correct 123 ms 13796 KB Output is correct
13 Correct 99 ms 13852 KB Output is correct
14 Correct 92 ms 13824 KB Output is correct
15 Correct 96 ms 13904 KB Output is correct
16 Correct 92 ms 14152 KB Output is correct
17 Correct 104 ms 13808 KB Output is correct
18 Correct 99 ms 13816 KB Output is correct
19 Correct 92 ms 13780 KB Output is correct
20 Correct 93 ms 13984 KB Output is correct
21 Correct 95 ms 14144 KB Output is correct
22 Correct 92 ms 13840 KB Output is correct
23 Correct 95 ms 13728 KB Output is correct
24 Correct 109 ms 13664 KB Output is correct
25 Correct 96 ms 13632 KB Output is correct
26 Correct 94 ms 13616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 17576 KB Output is correct
2 Correct 187 ms 17204 KB Output is correct
3 Correct 191 ms 17280 KB Output is correct
4 Correct 189 ms 17528 KB Output is correct
5 Correct 180 ms 17552 KB Output is correct
6 Correct 207 ms 16604 KB Output is correct
7 Correct 163 ms 16684 KB Output is correct
8 Correct 149 ms 16772 KB Output is correct
9 Correct 159 ms 16732 KB Output is correct
10 Correct 152 ms 16836 KB Output is correct
11 Correct 138 ms 16764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12096 KB Output is correct
2 Correct 8 ms 12108 KB Output is correct
3 Correct 9 ms 12108 KB Output is correct
4 Correct 8 ms 12108 KB Output is correct
5 Correct 11 ms 12108 KB Output is correct
6 Correct 8 ms 12172 KB Output is correct
7 Correct 8 ms 12064 KB Output is correct
8 Correct 102 ms 13668 KB Output is correct
9 Correct 98 ms 13564 KB Output is correct
10 Correct 97 ms 13732 KB Output is correct
11 Correct 121 ms 13956 KB Output is correct
12 Correct 123 ms 13796 KB Output is correct
13 Correct 99 ms 13852 KB Output is correct
14 Correct 92 ms 13824 KB Output is correct
15 Correct 96 ms 13904 KB Output is correct
16 Correct 92 ms 14152 KB Output is correct
17 Correct 104 ms 13808 KB Output is correct
18 Correct 99 ms 13816 KB Output is correct
19 Correct 92 ms 13780 KB Output is correct
20 Correct 93 ms 13984 KB Output is correct
21 Correct 95 ms 14144 KB Output is correct
22 Correct 92 ms 13840 KB Output is correct
23 Correct 95 ms 13728 KB Output is correct
24 Correct 109 ms 13664 KB Output is correct
25 Correct 96 ms 13632 KB Output is correct
26 Correct 94 ms 13616 KB Output is correct
27 Correct 202 ms 17576 KB Output is correct
28 Correct 187 ms 17204 KB Output is correct
29 Correct 191 ms 17280 KB Output is correct
30 Correct 189 ms 17528 KB Output is correct
31 Correct 180 ms 17552 KB Output is correct
32 Correct 207 ms 16604 KB Output is correct
33 Correct 163 ms 16684 KB Output is correct
34 Correct 149 ms 16772 KB Output is correct
35 Correct 159 ms 16732 KB Output is correct
36 Correct 152 ms 16836 KB Output is correct
37 Correct 138 ms 16764 KB Output is correct
38 Correct 295 ms 22880 KB Output is correct
39 Correct 319 ms 24340 KB Output is correct
40 Correct 210 ms 21472 KB Output is correct
41 Correct 386 ms 23820 KB Output is correct
42 Correct 151 ms 16964 KB Output is correct
43 Correct 156 ms 16768 KB Output is correct
44 Correct 231 ms 20456 KB Output is correct
45 Correct 221 ms 20560 KB Output is correct
46 Correct 219 ms 20772 KB Output is correct
47 Correct 166 ms 17132 KB Output is correct
48 Correct 169 ms 16784 KB Output is correct
49 Correct 225 ms 19936 KB Output is correct
50 Correct 292 ms 20364 KB Output is correct
51 Correct 263 ms 21124 KB Output is correct
52 Correct 172 ms 22692 KB Output is correct
53 Correct 245 ms 27112 KB Output is correct
54 Correct 251 ms 32124 KB Output is correct
55 Correct 222 ms 27348 KB Output is correct