Submission #197683

# Submission time Handle Problem Language Result Execution time Memory
197683 2020-01-22T09:57:36 Z dennisstar Long Mansion (JOI17_long_mansion) C++17
10 / 100
3000 ms 31976 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 (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;
			}
			while (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: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);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 24056 KB Output is correct
2 Correct 43 ms 24056 KB Output is correct
3 Correct 85 ms 24184 KB Output is correct
4 Correct 125 ms 24056 KB Output is correct
5 Correct 27 ms 24056 KB Output is correct
6 Correct 28 ms 24056 KB Output is correct
7 Correct 27 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 24056 KB Output is correct
2 Correct 43 ms 24056 KB Output is correct
3 Correct 85 ms 24184 KB Output is correct
4 Correct 125 ms 24056 KB Output is correct
5 Correct 27 ms 24056 KB Output is correct
6 Correct 28 ms 24056 KB Output is correct
7 Correct 27 ms 24056 KB Output is correct
8 Correct 160 ms 26436 KB Output is correct
9 Correct 157 ms 26424 KB Output is correct
10 Correct 175 ms 26804 KB Output is correct
11 Correct 212 ms 26472 KB Output is correct
12 Correct 151 ms 27356 KB Output is correct
13 Correct 154 ms 26960 KB Output is correct
14 Correct 154 ms 26744 KB Output is correct
15 Correct 151 ms 27268 KB Output is correct
16 Correct 145 ms 27604 KB Output is correct
17 Correct 155 ms 27000 KB Output is correct
18 Correct 164 ms 26744 KB Output is correct
19 Correct 153 ms 26876 KB Output is correct
20 Correct 150 ms 27384 KB Output is correct
21 Correct 147 ms 27496 KB Output is correct
22 Correct 153 ms 27372 KB Output is correct
23 Correct 153 ms 27128 KB Output is correct
24 Correct 151 ms 27256 KB Output is correct
25 Correct 142 ms 27208 KB Output is correct
26 Correct 154 ms 27084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3064 ms 31976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 24056 KB Output is correct
2 Correct 43 ms 24056 KB Output is correct
3 Correct 85 ms 24184 KB Output is correct
4 Correct 125 ms 24056 KB Output is correct
5 Correct 27 ms 24056 KB Output is correct
6 Correct 28 ms 24056 KB Output is correct
7 Correct 27 ms 24056 KB Output is correct
8 Correct 160 ms 26436 KB Output is correct
9 Correct 157 ms 26424 KB Output is correct
10 Correct 175 ms 26804 KB Output is correct
11 Correct 212 ms 26472 KB Output is correct
12 Correct 151 ms 27356 KB Output is correct
13 Correct 154 ms 26960 KB Output is correct
14 Correct 154 ms 26744 KB Output is correct
15 Correct 151 ms 27268 KB Output is correct
16 Correct 145 ms 27604 KB Output is correct
17 Correct 155 ms 27000 KB Output is correct
18 Correct 164 ms 26744 KB Output is correct
19 Correct 153 ms 26876 KB Output is correct
20 Correct 150 ms 27384 KB Output is correct
21 Correct 147 ms 27496 KB Output is correct
22 Correct 153 ms 27372 KB Output is correct
23 Correct 153 ms 27128 KB Output is correct
24 Correct 151 ms 27256 KB Output is correct
25 Correct 142 ms 27208 KB Output is correct
26 Correct 154 ms 27084 KB Output is correct
27 Execution timed out 3064 ms 31976 KB Time limit exceeded
28 Halted 0 ms 0 KB -