Submission #972050

# Submission time Handle Problem Language Result Execution time Memory
972050 2024-04-30T01:15:12 Z LCJLY Long Mansion (JOI17_long_mansion) C++14
10 / 100
3000 ms 9012 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[5005];

bool f(int val, int l, int r){
	int index=lower_bound(storage[val].begin(),storage[val].end(),l)-storage[val].begin();
	//show3(val,val,l,l,r,r);
	//show(sz,storage[val].size());
	if(index==(int)storage[val].size()) return false;
	//show2(index,index,storage[val][index],storage[val][index]);
	if(storage[val][index]<=r) return true;
	return false;
}
 
void solve(){
	int n;
	cin >> n;
	int arr[n+1];
	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++){
		int l=x;
		int r=x;
		while(1){
			if(l!=1&&f(arr[l-1],l,r)){
				l--;
			}
			else if(r!=n&&f(arr[r],l,r)){
				r++;
			}
			else break;
		}
		ans[x]={l,r};
		//show2(l,l,r,r);
	}
	
	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 3 ms 604 KB Output is correct
2 Correct 69 ms 852 KB Output is correct
3 Correct 353 ms 820 KB Output is correct
4 Correct 3 ms 736 KB Output is correct
5 Correct 55 ms 732 KB Output is correct
6 Correct 7 ms 676 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 69 ms 852 KB Output is correct
3 Correct 353 ms 820 KB Output is correct
4 Correct 3 ms 736 KB Output is correct
5 Correct 55 ms 732 KB Output is correct
6 Correct 7 ms 676 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 86 ms 6456 KB Output is correct
9 Correct 82 ms 6400 KB Output is correct
10 Correct 139 ms 6700 KB Output is correct
11 Correct 443 ms 7020 KB Output is correct
12 Correct 75 ms 6048 KB Output is correct
13 Correct 87 ms 6556 KB Output is correct
14 Correct 71 ms 6692 KB Output is correct
15 Correct 91 ms 6648 KB Output is correct
16 Correct 123 ms 6424 KB Output is correct
17 Correct 70 ms 6728 KB Output is correct
18 Correct 80 ms 6740 KB Output is correct
19 Correct 73 ms 6732 KB Output is correct
20 Correct 114 ms 6716 KB Output is correct
21 Correct 117 ms 6480 KB Output is correct
22 Correct 82 ms 6516 KB Output is correct
23 Correct 77 ms 6488 KB Output is correct
24 Correct 77 ms 6512 KB Output is correct
25 Correct 76 ms 6480 KB Output is correct
26 Correct 76 ms 6384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3088 ms 9012 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 69 ms 852 KB Output is correct
3 Correct 353 ms 820 KB Output is correct
4 Correct 3 ms 736 KB Output is correct
5 Correct 55 ms 732 KB Output is correct
6 Correct 7 ms 676 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 86 ms 6456 KB Output is correct
9 Correct 82 ms 6400 KB Output is correct
10 Correct 139 ms 6700 KB Output is correct
11 Correct 443 ms 7020 KB Output is correct
12 Correct 75 ms 6048 KB Output is correct
13 Correct 87 ms 6556 KB Output is correct
14 Correct 71 ms 6692 KB Output is correct
15 Correct 91 ms 6648 KB Output is correct
16 Correct 123 ms 6424 KB Output is correct
17 Correct 70 ms 6728 KB Output is correct
18 Correct 80 ms 6740 KB Output is correct
19 Correct 73 ms 6732 KB Output is correct
20 Correct 114 ms 6716 KB Output is correct
21 Correct 117 ms 6480 KB Output is correct
22 Correct 82 ms 6516 KB Output is correct
23 Correct 77 ms 6488 KB Output is correct
24 Correct 77 ms 6512 KB Output is correct
25 Correct 76 ms 6480 KB Output is correct
26 Correct 76 ms 6384 KB Output is correct
27 Execution timed out 3088 ms 9012 KB Time limit exceeded
28 Halted 0 ms 0 KB -