Submission #505490

# Submission time Handle Problem Language Result Execution time Memory
505490 2022-01-11T05:24:36 Z Koosha_mv Long Mansion (JOI17_long_mansion) C++14
100 / 100
1161 ms 44596 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);
	random_shuffle(all(vec));
	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';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12236 KB Output is correct
2 Correct 11 ms 12204 KB Output is correct
3 Correct 17 ms 12200 KB Output is correct
4 Correct 9 ms 12236 KB Output is correct
5 Correct 9 ms 12200 KB Output is correct
6 Correct 9 ms 12236 KB Output is correct
7 Correct 11 ms 12288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12236 KB Output is correct
2 Correct 11 ms 12204 KB Output is correct
3 Correct 17 ms 12200 KB Output is correct
4 Correct 9 ms 12236 KB Output is correct
5 Correct 9 ms 12200 KB Output is correct
6 Correct 9 ms 12236 KB Output is correct
7 Correct 11 ms 12288 KB Output is correct
8 Correct 134 ms 17956 KB Output is correct
9 Correct 123 ms 17980 KB Output is correct
10 Correct 125 ms 18372 KB Output is correct
11 Correct 142 ms 18552 KB Output is correct
12 Correct 120 ms 17692 KB Output is correct
13 Correct 108 ms 18268 KB Output is correct
14 Correct 120 ms 18236 KB Output is correct
15 Correct 131 ms 18212 KB Output is correct
16 Correct 115 ms 18060 KB Output is correct
17 Correct 111 ms 18144 KB Output is correct
18 Correct 110 ms 18256 KB Output is correct
19 Correct 115 ms 18216 KB Output is correct
20 Correct 96 ms 18116 KB Output is correct
21 Correct 101 ms 17988 KB Output is correct
22 Correct 119 ms 18032 KB Output is correct
23 Correct 104 ms 17988 KB Output is correct
24 Correct 112 ms 18072 KB Output is correct
25 Correct 115 ms 18032 KB Output is correct
26 Correct 103 ms 17936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 24916 KB Output is correct
2 Correct 327 ms 24416 KB Output is correct
3 Correct 328 ms 24192 KB Output is correct
4 Correct 357 ms 24824 KB Output is correct
5 Correct 333 ms 24884 KB Output is correct
6 Correct 315 ms 23016 KB Output is correct
7 Correct 311 ms 22788 KB Output is correct
8 Correct 346 ms 22868 KB Output is correct
9 Correct 329 ms 22804 KB Output is correct
10 Correct 281 ms 22796 KB Output is correct
11 Correct 300 ms 22752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12236 KB Output is correct
2 Correct 11 ms 12204 KB Output is correct
3 Correct 17 ms 12200 KB Output is correct
4 Correct 9 ms 12236 KB Output is correct
5 Correct 9 ms 12200 KB Output is correct
6 Correct 9 ms 12236 KB Output is correct
7 Correct 11 ms 12288 KB Output is correct
8 Correct 134 ms 17956 KB Output is correct
9 Correct 123 ms 17980 KB Output is correct
10 Correct 125 ms 18372 KB Output is correct
11 Correct 142 ms 18552 KB Output is correct
12 Correct 120 ms 17692 KB Output is correct
13 Correct 108 ms 18268 KB Output is correct
14 Correct 120 ms 18236 KB Output is correct
15 Correct 131 ms 18212 KB Output is correct
16 Correct 115 ms 18060 KB Output is correct
17 Correct 111 ms 18144 KB Output is correct
18 Correct 110 ms 18256 KB Output is correct
19 Correct 115 ms 18216 KB Output is correct
20 Correct 96 ms 18116 KB Output is correct
21 Correct 101 ms 17988 KB Output is correct
22 Correct 119 ms 18032 KB Output is correct
23 Correct 104 ms 17988 KB Output is correct
24 Correct 112 ms 18072 KB Output is correct
25 Correct 115 ms 18032 KB Output is correct
26 Correct 103 ms 17936 KB Output is correct
27 Correct 321 ms 24916 KB Output is correct
28 Correct 327 ms 24416 KB Output is correct
29 Correct 328 ms 24192 KB Output is correct
30 Correct 357 ms 24824 KB Output is correct
31 Correct 333 ms 24884 KB Output is correct
32 Correct 315 ms 23016 KB Output is correct
33 Correct 311 ms 22788 KB Output is correct
34 Correct 346 ms 22868 KB Output is correct
35 Correct 329 ms 22804 KB Output is correct
36 Correct 281 ms 22796 KB Output is correct
37 Correct 300 ms 22752 KB Output is correct
38 Correct 375 ms 34560 KB Output is correct
39 Correct 412 ms 35876 KB Output is correct
40 Correct 272 ms 31944 KB Output is correct
41 Correct 1161 ms 33304 KB Output is correct
42 Correct 176 ms 24424 KB Output is correct
43 Correct 206 ms 24352 KB Output is correct
44 Correct 338 ms 30468 KB Output is correct
45 Correct 367 ms 30740 KB Output is correct
46 Correct 312 ms 31144 KB Output is correct
47 Correct 205 ms 24652 KB Output is correct
48 Correct 243 ms 23968 KB Output is correct
49 Correct 337 ms 29956 KB Output is correct
50 Correct 402 ms 30496 KB Output is correct
51 Correct 431 ms 31652 KB Output is correct
52 Correct 226 ms 31808 KB Output is correct
53 Correct 316 ms 38032 KB Output is correct
54 Correct 331 ms 44596 KB Output is correct
55 Correct 343 ms 38324 KB Output is correct