답안 #197674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197674 2020-01-22T09:21:58 Z dennisstar Long Mansion (JOI17_long_mansion) C++17
10 / 100
3000 ms 32548 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], 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;
			while (r[i]<N && Find(l[i], r[i], C[r[i]])) { r[i]++; fl=1; }
			while (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;
			}
			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:25: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:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:31: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:33: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:35: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:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:53: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 27 ms 24184 KB Output is correct
2 Correct 49 ms 24088 KB Output is correct
3 Correct 156 ms 24128 KB Output is correct
4 Correct 28 ms 24056 KB Output is correct
5 Correct 78 ms 24056 KB Output is correct
6 Correct 29 ms 24056 KB Output is correct
7 Correct 27 ms 24056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 24184 KB Output is correct
2 Correct 49 ms 24088 KB Output is correct
3 Correct 156 ms 24128 KB Output is correct
4 Correct 28 ms 24056 KB Output is correct
5 Correct 78 ms 24056 KB Output is correct
6 Correct 29 ms 24056 KB Output is correct
7 Correct 27 ms 24056 KB Output is correct
8 Correct 155 ms 30044 KB Output is correct
9 Correct 169 ms 30052 KB Output is correct
10 Correct 181 ms 30204 KB Output is correct
11 Correct 259 ms 30720 KB Output is correct
12 Correct 146 ms 29508 KB Output is correct
13 Correct 155 ms 30072 KB Output is correct
14 Correct 154 ms 30072 KB Output is correct
15 Correct 154 ms 30200 KB Output is correct
16 Correct 189 ms 29816 KB Output is correct
17 Correct 153 ms 30084 KB Output is correct
18 Correct 159 ms 30072 KB Output is correct
19 Correct 149 ms 30124 KB Output is correct
20 Correct 168 ms 30072 KB Output is correct
21 Correct 190 ms 29944 KB Output is correct
22 Correct 158 ms 30072 KB Output is correct
23 Correct 158 ms 29944 KB Output is correct
24 Correct 153 ms 29944 KB Output is correct
25 Correct 156 ms 29980 KB Output is correct
26 Correct 155 ms 29816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3019 ms 32548 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 24184 KB Output is correct
2 Correct 49 ms 24088 KB Output is correct
3 Correct 156 ms 24128 KB Output is correct
4 Correct 28 ms 24056 KB Output is correct
5 Correct 78 ms 24056 KB Output is correct
6 Correct 29 ms 24056 KB Output is correct
7 Correct 27 ms 24056 KB Output is correct
8 Correct 155 ms 30044 KB Output is correct
9 Correct 169 ms 30052 KB Output is correct
10 Correct 181 ms 30204 KB Output is correct
11 Correct 259 ms 30720 KB Output is correct
12 Correct 146 ms 29508 KB Output is correct
13 Correct 155 ms 30072 KB Output is correct
14 Correct 154 ms 30072 KB Output is correct
15 Correct 154 ms 30200 KB Output is correct
16 Correct 189 ms 29816 KB Output is correct
17 Correct 153 ms 30084 KB Output is correct
18 Correct 159 ms 30072 KB Output is correct
19 Correct 149 ms 30124 KB Output is correct
20 Correct 168 ms 30072 KB Output is correct
21 Correct 190 ms 29944 KB Output is correct
22 Correct 158 ms 30072 KB Output is correct
23 Correct 158 ms 29944 KB Output is correct
24 Correct 153 ms 29944 KB Output is correct
25 Correct 156 ms 29980 KB Output is correct
26 Correct 155 ms 29816 KB Output is correct
27 Execution timed out 3019 ms 32548 KB Time limit exceeded
28 Halted 0 ms 0 KB -