답안 #671441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671441 2022-12-13T05:09:55 Z flappybird Long Mansion (JOI17_long_mansion) C++17
25 / 100
3000 ms 42236 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 505050
#define MAXS 17
#define INF 100000000000000
#define bb ' '
#define ln '\n'
#define Ln '\n'
vector<int> locs[MAX];
int C[MAX];
int minr[MAX];
int maxl[MAX];
pii intv[MAX];
struct segtree {
	int tree[MAX * 4];
	int inv;
	void init(int l, int r, int inverted = 0, int loc = 1) {
		if (l == r) {
			if (inverted) tree[loc] = minr[l];
			else tree[loc] = maxl[l];
			return;
		}
		int m = (l + r) / 2;
		init(l, m, inverted, loc * 2);
		init(m + 1, r, inverted, loc * 2 + 1);
		if (!inverted) tree[loc] = min(tree[loc * 2], tree[loc * 2 + 1]);
		else tree[loc] = max(tree[loc * 2], tree[loc * 2 + 1]);
	}
	segtree(int N, int inverted) {
		inv = inverted;
		init(1, N, inverted);
	}
	int find(int s, int e, int l, int r, int v, int loc = 1) {
		if (!inv) {
			if (e < l || r < s) return -1;
			if (tree[loc] >= v) return -1;
			if (s == e) return s;
			int m = (s + e) / 2;
			int ind = find(s, m, l, r, v, loc * 2);
			if (!~ind) return find(m + 1, e, l, r, v, loc * 2 + 1);
			else return ind;
		}
		else {
			if (e < l || r < s) return -1;
			if (tree[loc] <= v) return -1;
			if (s == e) return s;
			int m = (s + e) / 2;
			int ind = find(m + 1, e, l, r, v, loc * 2 + 1);
			if (!~ind) return find(s, m, l, r, v, loc * 2); 
			else return ind;
		}
	}
};
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	int i;
	for (i = 1; i < N; i++) cin >> C[i];
	for (i = 1; i <= N; i++) {
		int s, v;
		cin >> s;
		while (s--) cin >> v, locs[v].push_back(i);
	}
	maxl[N] = -1;
	for (i = 1; i < N; i++) {
		int c = C[i];
		int ind = upper_bound(locs[c].begin(), locs[c].end(), i) - locs[c].begin();
		ind--;
		if (ind < 0 || ind >= locs[c].size()) maxl[i] = -1;
		else maxl[i] = locs[c][ind];
	}
	minr[1] = N + 1;
	for (i = N; i > 1; i--) {
		int c = C[i - 1];
		int ind = lower_bound(locs[c].begin(), locs[c].end(), i) - locs[c].begin();
		if (ind >= locs[c].size()) minr[i] = N + 1;
		else minr[i] = locs[c][ind];
	}
	segtree segl(N, 0), segr(N, 1);
	for (i = 1; i <= N; i++) {
		int l, r;
		l = r = i;
		while (1) {
			int nr = segl.find(1, N, r, N, l);
			if (!~nr) nr = N;
			int nl = segr.find(1, N, 1, l, nr);
			if (!~nl) nl = 1;
			if (l == nl && r == nr) break;
			l = nl;
			r = nr;
		}
		intv[i] = { l, r };
	}
	int Q;
	cin >> Q;
	while (Q--) {
		int a, b;
		cin >> a >> b;
		if (intv[a].first <= b && b <= intv[a].second) cout << "YES" << ln;
		else cout << "NO" << ln;
	}
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:78:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   if (ind < 0 || ind >= locs[c].size()) maxl[i] = -1;
      |                  ~~~~^~~~~~~~~~~~~~~~~
long_mansion.cpp:85:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   if (ind >= locs[c].size()) minr[i] = N + 1;
      |       ~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28116 KB Output is correct
2 Correct 15 ms 28044 KB Output is correct
3 Correct 17 ms 28152 KB Output is correct
4 Correct 15 ms 28116 KB Output is correct
5 Correct 15 ms 28120 KB Output is correct
6 Correct 15 ms 28116 KB Output is correct
7 Correct 52 ms 28108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28116 KB Output is correct
2 Correct 15 ms 28044 KB Output is correct
3 Correct 17 ms 28152 KB Output is correct
4 Correct 15 ms 28116 KB Output is correct
5 Correct 15 ms 28120 KB Output is correct
6 Correct 15 ms 28116 KB Output is correct
7 Correct 52 ms 28108 KB Output is correct
8 Correct 98 ms 29608 KB Output is correct
9 Correct 99 ms 29576 KB Output is correct
10 Correct 101 ms 29708 KB Output is correct
11 Correct 101 ms 29956 KB Output is correct
12 Correct 92 ms 29692 KB Output is correct
13 Correct 97 ms 29780 KB Output is correct
14 Correct 107 ms 29756 KB Output is correct
15 Correct 96 ms 29840 KB Output is correct
16 Correct 100 ms 30028 KB Output is correct
17 Correct 98 ms 29808 KB Output is correct
18 Correct 100 ms 29864 KB Output is correct
19 Correct 114 ms 29844 KB Output is correct
20 Correct 97 ms 29944 KB Output is correct
21 Correct 97 ms 29988 KB Output is correct
22 Correct 117 ms 29768 KB Output is correct
23 Correct 128 ms 29704 KB Output is correct
24 Correct 135 ms 29720 KB Output is correct
25 Correct 170 ms 29632 KB Output is correct
26 Correct 126 ms 29644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 34160 KB Output is correct
2 Correct 195 ms 33464 KB Output is correct
3 Correct 186 ms 33628 KB Output is correct
4 Correct 187 ms 33868 KB Output is correct
5 Correct 186 ms 33944 KB Output is correct
6 Correct 207 ms 32924 KB Output is correct
7 Correct 190 ms 33108 KB Output is correct
8 Correct 183 ms 33064 KB Output is correct
9 Correct 195 ms 33100 KB Output is correct
10 Correct 180 ms 33100 KB Output is correct
11 Correct 181 ms 33108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28116 KB Output is correct
2 Correct 15 ms 28044 KB Output is correct
3 Correct 17 ms 28152 KB Output is correct
4 Correct 15 ms 28116 KB Output is correct
5 Correct 15 ms 28120 KB Output is correct
6 Correct 15 ms 28116 KB Output is correct
7 Correct 52 ms 28108 KB Output is correct
8 Correct 98 ms 29608 KB Output is correct
9 Correct 99 ms 29576 KB Output is correct
10 Correct 101 ms 29708 KB Output is correct
11 Correct 101 ms 29956 KB Output is correct
12 Correct 92 ms 29692 KB Output is correct
13 Correct 97 ms 29780 KB Output is correct
14 Correct 107 ms 29756 KB Output is correct
15 Correct 96 ms 29840 KB Output is correct
16 Correct 100 ms 30028 KB Output is correct
17 Correct 98 ms 29808 KB Output is correct
18 Correct 100 ms 29864 KB Output is correct
19 Correct 114 ms 29844 KB Output is correct
20 Correct 97 ms 29944 KB Output is correct
21 Correct 97 ms 29988 KB Output is correct
22 Correct 117 ms 29768 KB Output is correct
23 Correct 128 ms 29704 KB Output is correct
24 Correct 135 ms 29720 KB Output is correct
25 Correct 170 ms 29632 KB Output is correct
26 Correct 126 ms 29644 KB Output is correct
27 Correct 191 ms 34160 KB Output is correct
28 Correct 195 ms 33464 KB Output is correct
29 Correct 186 ms 33628 KB Output is correct
30 Correct 187 ms 33868 KB Output is correct
31 Correct 186 ms 33944 KB Output is correct
32 Correct 207 ms 32924 KB Output is correct
33 Correct 190 ms 33108 KB Output is correct
34 Correct 183 ms 33064 KB Output is correct
35 Correct 195 ms 33100 KB Output is correct
36 Correct 180 ms 33100 KB Output is correct
37 Correct 181 ms 33108 KB Output is correct
38 Correct 342 ms 40396 KB Output is correct
39 Correct 364 ms 42236 KB Output is correct
40 Correct 284 ms 38588 KB Output is correct
41 Correct 473 ms 41760 KB Output is correct
42 Correct 181 ms 33220 KB Output is correct
43 Correct 185 ms 33104 KB Output is correct
44 Correct 286 ms 37196 KB Output is correct
45 Correct 284 ms 37244 KB Output is correct
46 Correct 296 ms 37640 KB Output is correct
47 Correct 194 ms 33456 KB Output is correct
48 Correct 202 ms 33116 KB Output is correct
49 Correct 286 ms 36640 KB Output is correct
50 Correct 297 ms 37020 KB Output is correct
51 Correct 305 ms 37844 KB Output is correct
52 Execution timed out 3044 ms 36956 KB Time limit exceeded
53 Halted 0 ms 0 KB -