Submission #125296

# Submission time Handle Problem Language Result Execution time Memory
125296 2019-07-05T04:55:43 Z gs14004 Long Mansion (JOI17_long_mansion) C++17
100 / 100
729 ms 105856 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
using lint = long long;
using pi = pair<int, int>;

int n, c[MAXN];
vector<int> key_loc[MAXN];

int L[20][MAXN], R[20][MAXN];
int up[MAXN], dn[MAXN];
pi rng[MAXN];

int main(){
	scanf("%d",&n);
	for(int i=1; i<n; i++) scanf("%d",&c[i]);
	for(int i=1; i<=n; i++){
		int x; scanf("%d",&x);
		for(int j=0; j<x; j++){
			int y; scanf("%d",&y);
			key_loc[y].push_back(i);
		}
	}
	for(int i=1; i<n; i++){
		auto p = lower_bound(key_loc[c[i]].begin(), key_loc[c[i]].end(), i + 1);
		if(p == key_loc[c[i]].end()) R[0][i] = n + 1;
		else R[0][i] = *p;
		if(p == key_loc[c[i]].begin()) L[0][i] = 0;
		else L[0][i] = *prev(p);
	}
	R[0][0] = n + 1;
	L[0][n + 1] = 0;
	for(int i=1; i<20; i++){
		for(int j=0; j<=n+1; j++){
			L[i][j] = L[i-1][j];
			R[i][j] = R[i-1][j];
			if(j >= (1 << (i - 1))){
				L[i][j] = min(L[i][j], L[i-1][j - (1 << (i-1))]);
				R[i][j] = max(R[i][j], R[i-1][j - (1 << (i-1))]);
			}
		}
	}
	memset(dn, 0x3f, sizeof(dn));
	for(int i=1; i<=n; i++){
		int pos = R[0][i - 1] - 1;
		for(int j=19; j>=0; j--){
			if(pos >= (1 << j) && L[j][pos] >= i){
				pos -= (1 << j);
			}
		}
		if(L[0][pos] >= i) pos--;
		if(pos >= i) up[i] = max(up[i], pos);
	}
	for(int i=1; i<=n; i++){
		int pos = L[0][i];
		for(int j=19; j>=0; j--){
			if(pos + (1 << j) <= n && R[j][pos + (1<<j) - 1] <= i){
				pos += (1 << j);
			}
		}
		if(R[0][pos] <= i) pos++;
		pos++;
		if(pos <= i) dn[i] = min(dn[i], pos);
	}
	vector<pi> stk;
	for(int i=1; i<=n; i++){
		while(!stk.empty() && stk.back().first <= max(i - 1, up[i])){
			stk.pop_back();
		}
		if(up[i] >= i) stk.emplace_back(up[i], i);
		if(stk.size()) rng[i].first = stk.back().second;
		else rng[i].first = 1;
	}
	stk.clear();
	for(int i=n; i; i--){
		while(!stk.empty() && stk.back().first >= min(i + 1, dn[i])){
			stk.pop_back();
		}
		if(dn[i] <= i) stk.emplace_back(dn[i], i);
		if(stk.size()) rng[i].second = stk.back().second;
		else rng[i].second = n;
	}
	int q; scanf("%d",&q);
	while(q--){
		int x, y; scanf("%d %d",&x,&y);
		puts(rng[x].first <= y && y <= rng[x].second ? "YES" : "NO");
	}
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
long_mansion.cpp:16:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<n; i++) scanf("%d",&c[i]);
                         ~~~~~^~~~~~~~~~~~
long_mansion.cpp:18:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d",&x);
          ~~~~~^~~~~~~~~
long_mansion.cpp:20:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int y; scanf("%d",&y);
           ~~~~~^~~~~~~~~
long_mansion.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int q; scanf("%d",&q);
         ~~~~~^~~~~~~~~
long_mansion.cpp:85:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d %d",&x,&y);
             ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 14836 KB Output is correct
2 Correct 18 ms 14968 KB Output is correct
3 Correct 19 ms 15356 KB Output is correct
4 Correct 18 ms 14840 KB Output is correct
5 Correct 18 ms 14840 KB Output is correct
6 Correct 18 ms 14840 KB Output is correct
7 Correct 18 ms 14840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 14836 KB Output is correct
2 Correct 18 ms 14968 KB Output is correct
3 Correct 19 ms 15356 KB Output is correct
4 Correct 18 ms 14840 KB Output is correct
5 Correct 18 ms 14840 KB Output is correct
6 Correct 18 ms 14840 KB Output is correct
7 Correct 18 ms 14840 KB Output is correct
8 Correct 145 ms 17396 KB Output is correct
9 Correct 148 ms 17400 KB Output is correct
10 Correct 146 ms 17752 KB Output is correct
11 Correct 145 ms 18200 KB Output is correct
12 Correct 134 ms 17528 KB Output is correct
13 Correct 140 ms 17792 KB Output is correct
14 Correct 141 ms 17684 KB Output is correct
15 Correct 139 ms 17784 KB Output is correct
16 Correct 132 ms 17916 KB Output is correct
17 Correct 142 ms 17672 KB Output is correct
18 Correct 143 ms 17784 KB Output is correct
19 Correct 140 ms 17796 KB Output is correct
20 Correct 135 ms 17912 KB Output is correct
21 Correct 131 ms 17912 KB Output is correct
22 Correct 138 ms 17756 KB Output is correct
23 Correct 142 ms 17684 KB Output is correct
24 Correct 140 ms 17528 KB Output is correct
25 Correct 140 ms 17528 KB Output is correct
26 Correct 140 ms 17592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 281 ms 38304 KB Output is correct
2 Correct 278 ms 36852 KB Output is correct
3 Correct 273 ms 36872 KB Output is correct
4 Correct 284 ms 36860 KB Output is correct
5 Correct 279 ms 36900 KB Output is correct
6 Correct 234 ms 35832 KB Output is correct
7 Correct 231 ms 36116 KB Output is correct
8 Correct 225 ms 36088 KB Output is correct
9 Correct 225 ms 36088 KB Output is correct
10 Correct 228 ms 36216 KB Output is correct
11 Correct 228 ms 35932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 14836 KB Output is correct
2 Correct 18 ms 14968 KB Output is correct
3 Correct 19 ms 15356 KB Output is correct
4 Correct 18 ms 14840 KB Output is correct
5 Correct 18 ms 14840 KB Output is correct
6 Correct 18 ms 14840 KB Output is correct
7 Correct 18 ms 14840 KB Output is correct
8 Correct 145 ms 17396 KB Output is correct
9 Correct 148 ms 17400 KB Output is correct
10 Correct 146 ms 17752 KB Output is correct
11 Correct 145 ms 18200 KB Output is correct
12 Correct 134 ms 17528 KB Output is correct
13 Correct 140 ms 17792 KB Output is correct
14 Correct 141 ms 17684 KB Output is correct
15 Correct 139 ms 17784 KB Output is correct
16 Correct 132 ms 17916 KB Output is correct
17 Correct 142 ms 17672 KB Output is correct
18 Correct 143 ms 17784 KB Output is correct
19 Correct 140 ms 17796 KB Output is correct
20 Correct 135 ms 17912 KB Output is correct
21 Correct 131 ms 17912 KB Output is correct
22 Correct 138 ms 17756 KB Output is correct
23 Correct 142 ms 17684 KB Output is correct
24 Correct 140 ms 17528 KB Output is correct
25 Correct 140 ms 17528 KB Output is correct
26 Correct 140 ms 17592 KB Output is correct
27 Correct 281 ms 38304 KB Output is correct
28 Correct 278 ms 36852 KB Output is correct
29 Correct 273 ms 36872 KB Output is correct
30 Correct 284 ms 36860 KB Output is correct
31 Correct 279 ms 36900 KB Output is correct
32 Correct 234 ms 35832 KB Output is correct
33 Correct 231 ms 36116 KB Output is correct
34 Correct 225 ms 36088 KB Output is correct
35 Correct 225 ms 36088 KB Output is correct
36 Correct 228 ms 36216 KB Output is correct
37 Correct 228 ms 35932 KB Output is correct
38 Correct 686 ms 88884 KB Output is correct
39 Correct 729 ms 105856 KB Output is correct
40 Correct 526 ms 71800 KB Output is correct
41 Correct 545 ms 105188 KB Output is correct
42 Correct 285 ms 36108 KB Output is correct
43 Correct 274 ms 35880 KB Output is correct
44 Correct 436 ms 55032 KB Output is correct
45 Correct 426 ms 55288 KB Output is correct
46 Correct 420 ms 55400 KB Output is correct
47 Correct 262 ms 36124 KB Output is correct
48 Correct 251 ms 35928 KB Output is correct
49 Correct 379 ms 53880 KB Output is correct
50 Correct 389 ms 54272 KB Output is correct
51 Correct 403 ms 54928 KB Output is correct
52 Correct 339 ms 57080 KB Output is correct
53 Correct 421 ms 76916 KB Output is correct
54 Correct 495 ms 97288 KB Output is correct
55 Correct 421 ms 76804 KB Output is correct