답안 #197682

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197682 2020-01-22T09:52:26 Z dennisstar Long Mansion (JOI17_long_mansion) C++17
100 / 100
448 ms 54436 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ryan bear
#define sq(X) ((X)*(X))
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
#define unq(V) (V).erase(unique(all(V)), (V).end())
using namespace std;
typedef long long ll;
typedef vector<ll> vlm;
typedef vector<int> vim;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

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

inline bool Find(int L, int R, int X) {
	return ((pr[X]&&L<=pr[X]&&pr[X]<=R) || (nx[X]&&L<=nx[X]&&nx[X]<=R));
}

void init() {
	C.resize(N); B.resize(N+1);
	l.resize(N+1); r.resize(N+1);
	pr.resize(N+1); nx.resize(N+1);
	im.resize(N+1);
}

int main() {
	scanf("%d", &N);
	init();
	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);
	}

	fill(all(im), 0);
	for (int i=1; i<N; i++) {
		for (auto &j:A[i]) im[j]=i;
		pr[i]=im[C[i]];
	}
	fill(all(im), 0);
	for (int i=N; i>1; i--) {
		for (auto &j:A[i]) im[j]=i;
		nx[i-1]=im[C[i-1]];
	}

	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], 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], 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 'int main()':
long_mansion.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:37: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:39: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:41: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:69:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:71:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &Xk, &Yk);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12152 KB Output is correct
2 Correct 16 ms 12280 KB Output is correct
3 Correct 17 ms 12412 KB Output is correct
4 Correct 16 ms 12152 KB Output is correct
5 Correct 16 ms 12152 KB Output is correct
6 Correct 16 ms 12152 KB Output is correct
7 Correct 15 ms 12152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12152 KB Output is correct
2 Correct 16 ms 12280 KB Output is correct
3 Correct 17 ms 12412 KB Output is correct
4 Correct 16 ms 12152 KB Output is correct
5 Correct 16 ms 12152 KB Output is correct
6 Correct 16 ms 12152 KB Output is correct
7 Correct 15 ms 12152 KB Output is correct
8 Correct 142 ms 13700 KB Output is correct
9 Correct 147 ms 13728 KB Output is correct
10 Correct 149 ms 13956 KB Output is correct
11 Correct 149 ms 14136 KB Output is correct
12 Correct 137 ms 13944 KB Output is correct
13 Correct 141 ms 13944 KB Output is correct
14 Correct 142 ms 13944 KB Output is correct
15 Correct 140 ms 13944 KB Output is correct
16 Correct 136 ms 14300 KB Output is correct
17 Correct 143 ms 13944 KB Output is correct
18 Correct 143 ms 13944 KB Output is correct
19 Correct 148 ms 13944 KB Output is correct
20 Correct 144 ms 14176 KB Output is correct
21 Correct 123 ms 14148 KB Output is correct
22 Correct 145 ms 13992 KB Output is correct
23 Correct 143 ms 13816 KB Output is correct
24 Correct 143 ms 13816 KB Output is correct
25 Correct 143 ms 14000 KB Output is correct
26 Correct 144 ms 13796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 263 ms 25180 KB Output is correct
2 Correct 256 ms 27128 KB Output is correct
3 Correct 238 ms 26772 KB Output is correct
4 Correct 259 ms 27000 KB Output is correct
5 Correct 256 ms 27000 KB Output is correct
6 Correct 224 ms 26356 KB Output is correct
7 Correct 201 ms 25972 KB Output is correct
8 Correct 211 ms 26004 KB Output is correct
9 Correct 207 ms 25976 KB Output is correct
10 Correct 206 ms 26104 KB Output is correct
11 Correct 206 ms 25908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12152 KB Output is correct
2 Correct 16 ms 12280 KB Output is correct
3 Correct 17 ms 12412 KB Output is correct
4 Correct 16 ms 12152 KB Output is correct
5 Correct 16 ms 12152 KB Output is correct
6 Correct 16 ms 12152 KB Output is correct
7 Correct 15 ms 12152 KB Output is correct
8 Correct 142 ms 13700 KB Output is correct
9 Correct 147 ms 13728 KB Output is correct
10 Correct 149 ms 13956 KB Output is correct
11 Correct 149 ms 14136 KB Output is correct
12 Correct 137 ms 13944 KB Output is correct
13 Correct 141 ms 13944 KB Output is correct
14 Correct 142 ms 13944 KB Output is correct
15 Correct 140 ms 13944 KB Output is correct
16 Correct 136 ms 14300 KB Output is correct
17 Correct 143 ms 13944 KB Output is correct
18 Correct 143 ms 13944 KB Output is correct
19 Correct 148 ms 13944 KB Output is correct
20 Correct 144 ms 14176 KB Output is correct
21 Correct 123 ms 14148 KB Output is correct
22 Correct 145 ms 13992 KB Output is correct
23 Correct 143 ms 13816 KB Output is correct
24 Correct 143 ms 13816 KB Output is correct
25 Correct 143 ms 14000 KB Output is correct
26 Correct 144 ms 13796 KB Output is correct
27 Correct 263 ms 25180 KB Output is correct
28 Correct 256 ms 27128 KB Output is correct
29 Correct 238 ms 26772 KB Output is correct
30 Correct 259 ms 27000 KB Output is correct
31 Correct 256 ms 27000 KB Output is correct
32 Correct 224 ms 26356 KB Output is correct
33 Correct 201 ms 25972 KB Output is correct
34 Correct 211 ms 26004 KB Output is correct
35 Correct 207 ms 25976 KB Output is correct
36 Correct 206 ms 26104 KB Output is correct
37 Correct 206 ms 25908 KB Output is correct
38 Correct 424 ms 48932 KB Output is correct
39 Correct 448 ms 54436 KB Output is correct
40 Correct 385 ms 41928 KB Output is correct
41 Correct 421 ms 52984 KB Output is correct
42 Correct 232 ms 27100 KB Output is correct
43 Correct 233 ms 27216 KB Output is correct
44 Correct 309 ms 35704 KB Output is correct
45 Correct 312 ms 35832 KB Output is correct
46 Correct 315 ms 35948 KB Output is correct
47 Correct 233 ms 27212 KB Output is correct
48 Correct 229 ms 26996 KB Output is correct
49 Correct 304 ms 35576 KB Output is correct
50 Correct 307 ms 35816 KB Output is correct
51 Correct 316 ms 36072 KB Output is correct
52 Correct 306 ms 34644 KB Output is correct
53 Correct 366 ms 42236 KB Output is correct
54 Correct 412 ms 49920 KB Output is correct
55 Correct 366 ms 42520 KB Output is correct