Submission #926339

# Submission time Handle Problem Language Result Execution time Memory
926339 2024-02-12T19:52:29 Z amirhoseinfar1385 Long Mansion (JOI17_long_mansion) C++17
100 / 100
988 ms 181580 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=500000+10;
int n,c[maxn],last[maxn],l[maxn],r[maxn],dpl[maxn],dpr[maxn];
vector<int>all[maxn],insl[maxn],dell[maxn],insr[maxn],delr[maxn],ins[maxn],del[maxn];

void vorod(){
	cin>>n;
	for(int i=1;i<=n-1;i++){
		cin>>c[i];
	}
	for(int i=1;i<=n;i++){
		int d;
		cin>>d;
		all[i].resize(d);
		for(int j=0;j<d;j++){
			cin>>all[i][j];
		}
	}
}

void pre(){
	for(int i=1;i<n;i++){
		for(auto x:all[i]){
			last[x]=i;
		}
		l[i]=last[c[i]];
	}
	for(int i=1;i<=n;i++){
		last[i]=n+3;
	}
	r[1]=n+3;
	for(int i=n;i>=2;i--){
		for(auto x:all[i]){
			last[x]=i;
		}
		r[i]=last[c[i-1]];
	}
	set<int>st;
	st.insert(n+1);
	insl[1].push_back(1);
	for(int i=n;i>=2;i--){
		if(i==n||l[i]!=i)
			st.insert(i);
		for(auto x:del[i]){
			st.erase(x);
		}
		del[l[i]].push_back(i);
		if((*st.begin())>=r[i]){
			continue;
		}
		insl[i].push_back(i);
		auto y=st.lower_bound(r[i]);
		y--;
		auto x=*y;
		dell[x+1].push_back(i);
	//	st.insert(i);
	}
	st.clear();
	for(int i=0;i<=n;i++){
		del[i].clear();
	}
	st.insert(0);
	insr[n].push_back(n);
	for(int i=1;i<n;i++){
		if(i==1||r[i]!=i)
			st.insert(i);
		for(auto x:del[i]){
		//	cout<<"wtf: "<<i<<" "<<x<<endl;
			st.erase(x);
		}
		del[r[i]].push_back(i);
		if((*st.rbegin())<=l[i]){
			continue;
		}
		insr[i].push_back(i);
		auto y=st.upper_bound(l[i]);
		auto x=*y;
		delr[x-1].push_back(i);
	//	st.insert(i);
	}
	st.clear();
	for(int i=1;i<=n;i++){
		for(auto x:insl[i]){
			st.insert(x);
		}
		for(auto x:dell[i]){
			st.erase(x);
		}
		dpl[i]=(*st.rbegin());
	}
	st.clear();
	for(int i=n;i>=1;i--){
		for(auto x:insr[i]){
			st.insert(x);
		}
		for(auto x:delr[i]){
			st.erase(x);
		}
		dpr[i]=(*st.begin());
	}
}

void debug(){
	for(int i=1;i<=n;i++){
		cout<<i<<" "<<dpl[i]<<" "<<dpr[i]<<" "<<l[i]<<" "<<r[i]<<"\n";
	}
}

void solve(){
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int l,r;
		cin>>l>>r;
		if(r>=dpl[l]&&r<=dpr[l]){
			cout<<"YES\n";
		}
		else{
			cout<<"NO\n";
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	vorod();
	pre();
//	debug();
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 93276 KB Output is correct
2 Correct 21 ms 93276 KB Output is correct
3 Correct 25 ms 93524 KB Output is correct
4 Correct 21 ms 93016 KB Output is correct
5 Correct 21 ms 93020 KB Output is correct
6 Correct 20 ms 93020 KB Output is correct
7 Correct 21 ms 93348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 93276 KB Output is correct
2 Correct 21 ms 93276 KB Output is correct
3 Correct 25 ms 93524 KB Output is correct
4 Correct 21 ms 93016 KB Output is correct
5 Correct 21 ms 93020 KB Output is correct
6 Correct 20 ms 93020 KB Output is correct
7 Correct 21 ms 93348 KB Output is correct
8 Correct 87 ms 98896 KB Output is correct
9 Correct 91 ms 98896 KB Output is correct
10 Correct 85 ms 99412 KB Output is correct
11 Correct 85 ms 99920 KB Output is correct
12 Correct 81 ms 98540 KB Output is correct
13 Correct 81 ms 99108 KB Output is correct
14 Correct 80 ms 99112 KB Output is correct
15 Correct 81 ms 99164 KB Output is correct
16 Correct 83 ms 98928 KB Output is correct
17 Correct 81 ms 99156 KB Output is correct
18 Correct 96 ms 99096 KB Output is correct
19 Correct 80 ms 99068 KB Output is correct
20 Correct 81 ms 99156 KB Output is correct
21 Correct 80 ms 98900 KB Output is correct
22 Correct 81 ms 98972 KB Output is correct
23 Correct 85 ms 98900 KB Output is correct
24 Correct 83 ms 99092 KB Output is correct
25 Correct 83 ms 98900 KB Output is correct
26 Correct 89 ms 99068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 107348 KB Output is correct
2 Correct 165 ms 113904 KB Output is correct
3 Correct 159 ms 112472 KB Output is correct
4 Correct 190 ms 114500 KB Output is correct
5 Correct 174 ms 114508 KB Output is correct
6 Correct 124 ms 108624 KB Output is correct
7 Correct 118 ms 107348 KB Output is correct
8 Correct 120 ms 107300 KB Output is correct
9 Correct 113 ms 107348 KB Output is correct
10 Correct 110 ms 107248 KB Output is correct
11 Correct 125 ms 107164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 93276 KB Output is correct
2 Correct 21 ms 93276 KB Output is correct
3 Correct 25 ms 93524 KB Output is correct
4 Correct 21 ms 93016 KB Output is correct
5 Correct 21 ms 93020 KB Output is correct
6 Correct 20 ms 93020 KB Output is correct
7 Correct 21 ms 93348 KB Output is correct
8 Correct 87 ms 98896 KB Output is correct
9 Correct 91 ms 98896 KB Output is correct
10 Correct 85 ms 99412 KB Output is correct
11 Correct 85 ms 99920 KB Output is correct
12 Correct 81 ms 98540 KB Output is correct
13 Correct 81 ms 99108 KB Output is correct
14 Correct 80 ms 99112 KB Output is correct
15 Correct 81 ms 99164 KB Output is correct
16 Correct 83 ms 98928 KB Output is correct
17 Correct 81 ms 99156 KB Output is correct
18 Correct 96 ms 99096 KB Output is correct
19 Correct 80 ms 99068 KB Output is correct
20 Correct 81 ms 99156 KB Output is correct
21 Correct 80 ms 98900 KB Output is correct
22 Correct 81 ms 98972 KB Output is correct
23 Correct 85 ms 98900 KB Output is correct
24 Correct 83 ms 99092 KB Output is correct
25 Correct 83 ms 98900 KB Output is correct
26 Correct 89 ms 99068 KB Output is correct
27 Correct 170 ms 107348 KB Output is correct
28 Correct 165 ms 113904 KB Output is correct
29 Correct 159 ms 112472 KB Output is correct
30 Correct 190 ms 114500 KB Output is correct
31 Correct 174 ms 114508 KB Output is correct
32 Correct 124 ms 108624 KB Output is correct
33 Correct 118 ms 107348 KB Output is correct
34 Correct 120 ms 107300 KB Output is correct
35 Correct 113 ms 107348 KB Output is correct
36 Correct 110 ms 107248 KB Output is correct
37 Correct 125 ms 107164 KB Output is correct
38 Correct 988 ms 166840 KB Output is correct
39 Correct 878 ms 181580 KB Output is correct
40 Correct 613 ms 150016 KB Output is correct
41 Correct 293 ms 152656 KB Output is correct
42 Correct 154 ms 110580 KB Output is correct
43 Correct 134 ms 109084 KB Output is correct
44 Correct 171 ms 118452 KB Output is correct
45 Correct 180 ms 118432 KB Output is correct
46 Correct 158 ms 117980 KB Output is correct
47 Correct 138 ms 108308 KB Output is correct
48 Correct 133 ms 108064 KB Output is correct
49 Correct 159 ms 117332 KB Output is correct
50 Correct 168 ms 117580 KB Output is correct
51 Correct 163 ms 117860 KB Output is correct
52 Correct 302 ms 134836 KB Output is correct
53 Correct 430 ms 151556 KB Output is correct
54 Correct 606 ms 172176 KB Output is correct
55 Correct 467 ms 154212 KB Output is correct