Submission #972058

# Submission time Handle Problem Language Result Execution time Memory
972058 2024-04-30T01:30:23 Z LCJLY Long Mansion (JOI17_long_mansion) C++14
0 / 100
507 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
	
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,long long>pii;
typedef pair<int,pii>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
 
vector<int>storage[10005];

bool f(int val, int l, int r){
	int index=lower_bound(storage[val].begin(),storage[val].end(),l)-storage[val].begin();
	if(index==(int)storage[val].size()) return false;
	if(storage[val][index]<=r) return true;
	return false;
}

unordered_map<int,pii>memo[5005];
int arr[10005];
int n;
pii dp(int l, int r){
	if(memo[l].find(r)!=memo[l].end()) return memo[l][r];
	pii ans={l,r};
	if(l!=1&&f(arr[l-1],l,r)){
		pii hold=dp(l-1,r);
		ans.first=min(ans.first,hold.first);
		ans.second=max(ans.second,hold.second);
	}
	if(r!=n&&f(arr[r],l,r)){
		pii hold=dp(l,r+1);
		ans.first=min(ans.first,hold.first);
		ans.second=max(ans.second,hold.second);
	}
	return memo[l][r]=ans;
}
 
void solve(){
	cin >> n;
	
	for(int x=1;x<n;x++){
		cin >> arr[x];
	}
	
	int temp,temp2;
	for(int x=1;x<=n;x++){
		cin >> temp;
		for(int y=0;y<temp;y++){
			cin >> temp2;
			storage[temp2].push_back(x);
		}
	}
	
	pii ans[n+5];
	for(int x=1;x<=n;x++){
		ans[x]=dp(x,x);
	}
	
	int q;
	cin >> q;
	for(int x=0;x<q;x++){
		cin >> temp >> temp2;
		if(ans[temp].first<=temp2&&ans[temp].second>=temp2){
			cout << "YES\n";
		}
		else cout << "NO\n";
	}
	
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//freopen("in.txt","r",stdin);
	//cin >> t;
	while(t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 214 ms 109864 KB Output is correct
2 Runtime error 507 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 214 ms 109864 KB Output is correct
2 Runtime error 507 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1884 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 214 ms 109864 KB Output is correct
2 Runtime error 507 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -