Submission #197686

# Submission time Handle Problem Language Result Execution time Memory
197686 2020-01-22T10:02:40 Z dennisstar Long Mansion (JOI17_long_mansion) C++17
100 / 100
557 ms 56440 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef vector<int> vim;

int N, Q;
vim C, B, A[500010], pos[500010];
vim l, r;
int Xk, Yk, lb;

inline bool Find(int L, int R, int X) {
	lb=lower_bound(all(pos[X]), L)-pos[X].begin();
	return (lb<pos[X].size()&&pos[X][lb]<=R);
}

int main() {
	scanf("%d", &N);
	C.resize(N); B.resize(N+1); l.resize(N+1); r.resize(N+1);
	for (int i=1; i<N; i++) scanf("%d", &C[i]);
	for (int i=1; i<=N; i++) {
		scanf("%d", &B[i]);
		A[i].resize(B[i]);
		for (auto &j:A[i]) scanf("%d", &j);
		for (auto &j:A[i]) pos[j].eb(i);
	}
	for (int i=1; i<=N; i++) {
		l[i]=r[i]=i;
		for (int fl; ; ) {
			fl=0;
			if (l[i]>1 && Find(l[i], r[i], C[l[i]-1])) {
				r[i]=max(r[i], r[l[i]-1]);
				l[i]=l[l[i]-1];
				fl=1;
			}
			else if (r[i]<N && Find(l[i], r[i], C[r[i]])) { r[i]++; fl=1; }
			if (!fl) break;
		}
	}
	scanf("%d", &Q);
	while (Q--) {
		scanf("%d %d", &Xk, &Yk);
		if (l[Xk]<=Yk&&Yk<=r[Xk]) puts("YES");
		else puts("NO");
	}
	return 0;
}

Compilation message

long_mansion.cpp: In function 'bool Find(int, int, int)':
long_mansion.cpp:14:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  return (lb<pos[X].size()&&pos[X][lb]<=R);
          ~~^~~~~~~~~~~~~~
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:20:31: 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:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &B[i]);
   ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:24:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (auto &j:A[i]) scanf("%d", &j);
                      ~~~~~^~~~~~~~~~
long_mansion.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &Xk, &Yk);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 23900 KB Output is correct
2 Correct 32 ms 23928 KB Output is correct
3 Correct 31 ms 24156 KB Output is correct
4 Correct 31 ms 23928 KB Output is correct
5 Correct 31 ms 23928 KB Output is correct
6 Correct 27 ms 23928 KB Output is correct
7 Correct 27 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 23900 KB Output is correct
2 Correct 32 ms 23928 KB Output is correct
3 Correct 31 ms 24156 KB Output is correct
4 Correct 31 ms 23928 KB Output is correct
5 Correct 31 ms 23928 KB Output is correct
6 Correct 27 ms 23928 KB Output is correct
7 Correct 27 ms 23928 KB Output is correct
8 Correct 163 ms 25468 KB Output is correct
9 Correct 162 ms 25516 KB Output is correct
10 Correct 157 ms 25720 KB Output is correct
11 Correct 157 ms 25920 KB Output is correct
12 Correct 147 ms 25716 KB Output is correct
13 Correct 151 ms 25724 KB Output is correct
14 Correct 152 ms 25848 KB Output is correct
15 Correct 156 ms 25832 KB Output is correct
16 Correct 144 ms 26020 KB Output is correct
17 Correct 152 ms 25888 KB Output is correct
18 Correct 151 ms 25720 KB Output is correct
19 Correct 150 ms 25720 KB Output is correct
20 Correct 148 ms 25848 KB Output is correct
21 Correct 145 ms 25976 KB Output is correct
22 Correct 150 ms 25848 KB Output is correct
23 Correct 152 ms 25668 KB Output is correct
24 Correct 151 ms 25612 KB Output is correct
25 Correct 153 ms 25564 KB Output is correct
26 Correct 157 ms 25464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 32248 KB Output is correct
2 Correct 286 ms 31992 KB Output is correct
3 Correct 277 ms 31980 KB Output is correct
4 Correct 291 ms 32120 KB Output is correct
5 Correct 288 ms 32152 KB Output is correct
6 Correct 271 ms 31380 KB Output is correct
7 Correct 230 ms 31480 KB Output is correct
8 Correct 228 ms 31572 KB Output is correct
9 Correct 224 ms 31484 KB Output is correct
10 Correct 224 ms 31532 KB Output is correct
11 Correct 222 ms 31480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 23900 KB Output is correct
2 Correct 32 ms 23928 KB Output is correct
3 Correct 31 ms 24156 KB Output is correct
4 Correct 31 ms 23928 KB Output is correct
5 Correct 31 ms 23928 KB Output is correct
6 Correct 27 ms 23928 KB Output is correct
7 Correct 27 ms 23928 KB Output is correct
8 Correct 163 ms 25468 KB Output is correct
9 Correct 162 ms 25516 KB Output is correct
10 Correct 157 ms 25720 KB Output is correct
11 Correct 157 ms 25920 KB Output is correct
12 Correct 147 ms 25716 KB Output is correct
13 Correct 151 ms 25724 KB Output is correct
14 Correct 152 ms 25848 KB Output is correct
15 Correct 156 ms 25832 KB Output is correct
16 Correct 144 ms 26020 KB Output is correct
17 Correct 152 ms 25888 KB Output is correct
18 Correct 151 ms 25720 KB Output is correct
19 Correct 150 ms 25720 KB Output is correct
20 Correct 148 ms 25848 KB Output is correct
21 Correct 145 ms 25976 KB Output is correct
22 Correct 150 ms 25848 KB Output is correct
23 Correct 152 ms 25668 KB Output is correct
24 Correct 151 ms 25612 KB Output is correct
25 Correct 153 ms 25564 KB Output is correct
26 Correct 157 ms 25464 KB Output is correct
27 Correct 298 ms 32248 KB Output is correct
28 Correct 286 ms 31992 KB Output is correct
29 Correct 277 ms 31980 KB Output is correct
30 Correct 291 ms 32120 KB Output is correct
31 Correct 288 ms 32152 KB Output is correct
32 Correct 271 ms 31380 KB Output is correct
33 Correct 230 ms 31480 KB Output is correct
34 Correct 228 ms 31572 KB Output is correct
35 Correct 224 ms 31484 KB Output is correct
36 Correct 224 ms 31532 KB Output is correct
37 Correct 222 ms 31480 KB Output is correct
38 Correct 550 ms 47396 KB Output is correct
39 Correct 487 ms 51580 KB Output is correct
40 Correct 416 ms 42400 KB Output is correct
41 Correct 557 ms 51216 KB Output is correct
42 Correct 275 ms 31992 KB Output is correct
43 Correct 273 ms 31608 KB Output is correct
44 Correct 408 ms 38392 KB Output is correct
45 Correct 413 ms 38728 KB Output is correct
46 Correct 419 ms 38800 KB Output is correct
47 Correct 274 ms 32012 KB Output is correct
48 Correct 272 ms 31864 KB Output is correct
49 Correct 427 ms 37832 KB Output is correct
50 Correct 479 ms 38216 KB Output is correct
51 Correct 429 ms 39160 KB Output is correct
52 Correct 318 ms 40824 KB Output is correct
53 Correct 380 ms 48372 KB Output is correct
54 Correct 459 ms 56440 KB Output is correct
55 Correct 393 ms 48532 KB Output is correct