Submission #125377

# Submission time Handle Problem Language Result Execution time Memory
125377 2019-07-05T07:11:19 Z 김현수(#3338) Long Mansion (JOI17_long_mansion) C++14
100 / 100
456 ms 50044 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 500005, L = 524288;

int n, q, req[N], lst[N], rb[N], l[N], r[N];

vector<int> key[N];

struct segtree {
	int v[2*L];
	void upd (int P, int V) {
		P += L;
		v[P] = V;
		P /= 2;
		while(P) {
			v[P] = min(v[2*P], v[2*P+1]);
			P /= 2;
		}
	}
	int bound (int P, int V) {
		P += L;
		while(P & (P+1)) {
			if(v[P] < V) break;
			P = (P+1)/2;
		}
		while(P < L) {
			if(v[2*P] < V) P = 2*P;
			else P = 2*P+1;
		}
		return P - L;
	}
} seg;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++) {
		scanf("%d",&req[i]);
	}
	for(int i=1;i<=n;i++) {
		int M, T;
		scanf("%d",&M);
		while(M--) {
			scanf("%d",&T);
			key[i].push_back(T);
		}
	}
	for(int i=1;i<=n;i++) {
		seg.upd(i, lst[req[i-1]]);
		for(auto &T : key[i]) lst[T] = i;
	}
	fill(lst, lst+1+n, n+1);
	for(int i=n;i>=1;i--) {
		rb[i] = lst[req[i]];
		for(auto &T : key[i]) lst[T] = i;
	}
	vector<int> S;
	for(int i=1;i<=n;i++) {
		int L = i, R = seg.bound(i+1, L) - 1;
		while(!S.empty()) {
			int C = S.back();
			if(rb[L-1] > R) break;
			S.pop_back();
			L = C;
			R = seg.bound(i+1, L) - 1;
		}
		l[i] = L, r[i] = R;
		S.push_back(L);
	}
	scanf("%d",&q);
	while(q--) {
		int S, E;
		scanf("%d%d",&S,&E);
		puts(l[S] <= E && E <= r[S] ? "YES" : "NO");
	}
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
long_mansion.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&req[i]);
   ~~~~~^~~~~~~~~~~~~~
long_mansion.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&M);
   ~~~~~^~~~~~~~~
long_mansion.cpp:45:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&T);
    ~~~~~^~~~~~~~~
long_mansion.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&q);
  ~~~~~^~~~~~~~~
long_mansion.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&S,&E);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12408 KB Output is correct
2 Correct 16 ms 12412 KB Output is correct
3 Correct 17 ms 12536 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 19 ms 12408 KB Output is correct
6 Correct 16 ms 12408 KB Output is correct
7 Correct 20 ms 12408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12408 KB Output is correct
2 Correct 16 ms 12412 KB Output is correct
3 Correct 17 ms 12536 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 19 ms 12408 KB Output is correct
6 Correct 16 ms 12408 KB Output is correct
7 Correct 20 ms 12408 KB Output is correct
8 Correct 144 ms 17192 KB Output is correct
9 Correct 143 ms 17016 KB Output is correct
10 Correct 147 ms 17364 KB Output is correct
11 Correct 148 ms 17528 KB Output is correct
12 Correct 139 ms 17500 KB Output is correct
13 Correct 139 ms 17372 KB Output is correct
14 Correct 141 ms 17320 KB Output is correct
15 Correct 139 ms 17432 KB Output is correct
16 Correct 133 ms 17784 KB Output is correct
17 Correct 139 ms 17272 KB Output is correct
18 Correct 142 ms 17400 KB Output is correct
19 Correct 142 ms 17356 KB Output is correct
20 Correct 142 ms 17656 KB Output is correct
21 Correct 132 ms 17868 KB Output is correct
22 Correct 140 ms 17404 KB Output is correct
23 Correct 141 ms 17132 KB Output is correct
24 Correct 144 ms 17272 KB Output is correct
25 Correct 140 ms 17272 KB Output is correct
26 Correct 141 ms 17316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 275 ms 24348 KB Output is correct
2 Correct 271 ms 24540 KB Output is correct
3 Correct 266 ms 24120 KB Output is correct
4 Correct 277 ms 24316 KB Output is correct
5 Correct 277 ms 24440 KB Output is correct
6 Correct 225 ms 22776 KB Output is correct
7 Correct 221 ms 22640 KB Output is correct
8 Correct 220 ms 22644 KB Output is correct
9 Correct 218 ms 22648 KB Output is correct
10 Correct 216 ms 22776 KB Output is correct
11 Correct 217 ms 22776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12408 KB Output is correct
2 Correct 16 ms 12412 KB Output is correct
3 Correct 17 ms 12536 KB Output is correct
4 Correct 16 ms 12408 KB Output is correct
5 Correct 19 ms 12408 KB Output is correct
6 Correct 16 ms 12408 KB Output is correct
7 Correct 20 ms 12408 KB Output is correct
8 Correct 144 ms 17192 KB Output is correct
9 Correct 143 ms 17016 KB Output is correct
10 Correct 147 ms 17364 KB Output is correct
11 Correct 148 ms 17528 KB Output is correct
12 Correct 139 ms 17500 KB Output is correct
13 Correct 139 ms 17372 KB Output is correct
14 Correct 141 ms 17320 KB Output is correct
15 Correct 139 ms 17432 KB Output is correct
16 Correct 133 ms 17784 KB Output is correct
17 Correct 139 ms 17272 KB Output is correct
18 Correct 142 ms 17400 KB Output is correct
19 Correct 142 ms 17356 KB Output is correct
20 Correct 142 ms 17656 KB Output is correct
21 Correct 132 ms 17868 KB Output is correct
22 Correct 140 ms 17404 KB Output is correct
23 Correct 141 ms 17132 KB Output is correct
24 Correct 144 ms 17272 KB Output is correct
25 Correct 140 ms 17272 KB Output is correct
26 Correct 141 ms 17316 KB Output is correct
27 Correct 275 ms 24348 KB Output is correct
28 Correct 271 ms 24540 KB Output is correct
29 Correct 266 ms 24120 KB Output is correct
30 Correct 277 ms 24316 KB Output is correct
31 Correct 277 ms 24440 KB Output is correct
32 Correct 225 ms 22776 KB Output is correct
33 Correct 221 ms 22640 KB Output is correct
34 Correct 220 ms 22644 KB Output is correct
35 Correct 218 ms 22648 KB Output is correct
36 Correct 216 ms 22776 KB Output is correct
37 Correct 217 ms 22776 KB Output is correct
38 Correct 433 ms 44012 KB Output is correct
39 Correct 450 ms 50044 KB Output is correct
40 Correct 403 ms 37572 KB Output is correct
41 Correct 456 ms 47808 KB Output is correct
42 Correct 263 ms 22744 KB Output is correct
43 Correct 236 ms 22136 KB Output is correct
44 Correct 331 ms 28676 KB Output is correct
45 Correct 333 ms 28596 KB Output is correct
46 Correct 346 ms 28568 KB Output is correct
47 Correct 241 ms 21236 KB Output is correct
48 Correct 236 ms 21288 KB Output is correct
49 Correct 336 ms 28516 KB Output is correct
50 Correct 354 ms 28496 KB Output is correct
51 Correct 351 ms 28344 KB Output is correct
52 Correct 295 ms 28984 KB Output is correct
53 Correct 372 ms 34648 KB Output is correct
54 Correct 438 ms 40508 KB Output is correct
55 Correct 377 ms 34820 KB Output is correct