답안 #204741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204741 2020-02-26T19:43:50 Z hanagasumi Long Mansion (JOI17_long_mansion) C++17
10 / 100
3000 ms 17220 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);
	for (int i = 1; i < n; i++) {
		cin >> per[i];
		if(per[i] > n || per[i] == 0) 
			return -1;
		per[i]--;
	}
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int x;
			cin >> x;
			if(x > n || x == 0) 
				return -1;
			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);
	for (int i = n - 1; 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';
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 632 KB Output is correct
2 Correct 148 ms 888 KB Output is correct
3 Correct 720 ms 1008 KB Output is correct
4 Correct 9 ms 760 KB Output is correct
5 Correct 128 ms 632 KB Output is correct
6 Correct 18 ms 632 KB Output is correct
7 Correct 12 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 632 KB Output is correct
2 Correct 148 ms 888 KB Output is correct
3 Correct 720 ms 1008 KB Output is correct
4 Correct 9 ms 760 KB Output is correct
5 Correct 128 ms 632 KB Output is correct
6 Correct 18 ms 632 KB Output is correct
7 Correct 12 ms 632 KB Output is correct
8 Correct 141 ms 6480 KB Output is correct
9 Correct 127 ms 6520 KB Output is correct
10 Correct 266 ms 7032 KB Output is correct
11 Correct 833 ms 7416 KB Output is correct
12 Correct 136 ms 6008 KB Output is correct
13 Correct 127 ms 6648 KB Output is correct
14 Correct 122 ms 6752 KB Output is correct
15 Correct 167 ms 6648 KB Output is correct
16 Correct 235 ms 6520 KB Output is correct
17 Correct 121 ms 6648 KB Output is correct
18 Correct 125 ms 6776 KB Output is correct
19 Correct 124 ms 6648 KB Output is correct
20 Correct 206 ms 6668 KB Output is correct
21 Correct 240 ms 6520 KB Output is correct
22 Correct 158 ms 6648 KB Output is correct
23 Correct 122 ms 6476 KB Output is correct
24 Correct 130 ms 6520 KB Output is correct
25 Correct 125 ms 6520 KB Output is correct
26 Correct 119 ms 6520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3078 ms 17220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 632 KB Output is correct
2 Correct 148 ms 888 KB Output is correct
3 Correct 720 ms 1008 KB Output is correct
4 Correct 9 ms 760 KB Output is correct
5 Correct 128 ms 632 KB Output is correct
6 Correct 18 ms 632 KB Output is correct
7 Correct 12 ms 632 KB Output is correct
8 Correct 141 ms 6480 KB Output is correct
9 Correct 127 ms 6520 KB Output is correct
10 Correct 266 ms 7032 KB Output is correct
11 Correct 833 ms 7416 KB Output is correct
12 Correct 136 ms 6008 KB Output is correct
13 Correct 127 ms 6648 KB Output is correct
14 Correct 122 ms 6752 KB Output is correct
15 Correct 167 ms 6648 KB Output is correct
16 Correct 235 ms 6520 KB Output is correct
17 Correct 121 ms 6648 KB Output is correct
18 Correct 125 ms 6776 KB Output is correct
19 Correct 124 ms 6648 KB Output is correct
20 Correct 206 ms 6668 KB Output is correct
21 Correct 240 ms 6520 KB Output is correct
22 Correct 158 ms 6648 KB Output is correct
23 Correct 122 ms 6476 KB Output is correct
24 Correct 130 ms 6520 KB Output is correct
25 Correct 125 ms 6520 KB Output is correct
26 Correct 119 ms 6520 KB Output is correct
27 Execution timed out 3078 ms 17220 KB Time limit exceeded
28 Halted 0 ms 0 KB -