Submission #204739

# Submission time Handle Problem Language Result Execution time Memory
204739 2020-02-26T19:37:15 Z hanagasumi Long Mansion (JOI17_long_mansion) C++17
0 / 100
3000 ms 19652 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
 
#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll
 
using namespace std;
typedef long long ll;
typedef long double ld;


signed main() {
	#ifdef PC 
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;	
	cin >> n;
	vector<int> per(n);
	vector<vector<int>> keys(n);
	vector<vector<int>> types(n);
	vector<int> l(n, 0);
	for (int i = 1; i < n; i++) {
		cin >> per[i];
		per[i]--;
	}
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int x;
			cin >> x;
			x--;
			types[x].pb(i);
			keys[i].pb(x);
		}
	}

	//calc v<>l

	// for (int i = 0; i < n; i++) {
	// 	l[i] = 0;
	// 	map<int, bool> have;
	// 	for (int j = i; j > 0; j--) {
	// 		for (auto x : keys[j]) 
	// 			have[x] = 1;
	// 		if(!have[per[j]]) {
	// 			l[i] = j;
	// 			break;
	// 		}
	// 	}
	// }

	// calc ans
	vector<pair<int, int>> ans(n);
	ans[n - 1] = {l[n - 1], n - 1};
	for (int i = n - 2; i >= 0; i--) {
		int ln = i, rn = i + 1;
		while(1) {
			bool flag = 1;
			if(ln > 0) {
				auto uk = lower_bound(types[per[ln]].begin(), types[per[ln]].end(), ln);
				if(uk != types[per[ln]].end() && (*uk <= rn)) {
					ln--;
					flag = 0;
				}
			}
			if(rn < n) {
				auto uk = lower_bound(types[per[rn]].begin(), types[per[rn]].end(), rn);
				if(uk != types[per[rn]].begin()) {
					uk--;
					if(*uk >= ln) {
						rn++;
						flag = 0;
					}
				}
			}
			if(flag)
				break;
		}
		ans[i] = {ln, rn - 1};
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		if(ans[a].ft <= b && b <= ans[a].sc) 
			cout << "YES" << '\n';
		else
			cout << "NO" << '\n';
	}

}
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3063 ms 19652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -