Submission #671439

# Submission time Handle Problem Language Result Execution time Memory
671439 2022-12-13T05:04:43 Z flappybird Long Mansion (JOI17_long_mansion) C++17
100 / 100
628 ms 98032 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];
map<pii, pii> mp;
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;
		vector<pii> ilst;
		while (1) {
			int nr = segl.find(1, N, r, N, l);
			if (!~nr) nr = N;
			if (mp.find(pii(l, nr)) != mp.end()) {
				tie(l, r) = mp[pii(l, nr)];
				break;
			}
			int nl = segr.find(1, N, 1, l, nr);
			if (!~nl) nl = 1;
			ilst.emplace_back(nl, nr);
			if (l == nl && r == nr) break;
			if (mp.find(pii(nl, nr)) != mp.end()) {
				tie(l, r) = mp[pii(nl, nr)];
				break;
			}
			l = nl;
			r = nr;
		}
		intv[i] = { l, r };
		for (auto l : ilst) mp[l] = intv[i];
	}
	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:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   if (ind < 0 || ind >= locs[c].size()) maxl[i] = -1;
      |                  ~~~~^~~~~~~~~~~~~~~~~
long_mansion.cpp:86:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   if (ind >= locs[c].size()) minr[i] = N + 1;
      |       ~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 28244 KB Output is correct
2 Correct 17 ms 28268 KB Output is correct
3 Correct 17 ms 28348 KB Output is correct
4 Correct 15 ms 28116 KB Output is correct
5 Correct 16 ms 28144 KB Output is correct
6 Correct 15 ms 28092 KB Output is correct
7 Correct 15 ms 28244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 28244 KB Output is correct
2 Correct 17 ms 28268 KB Output is correct
3 Correct 17 ms 28348 KB Output is correct
4 Correct 15 ms 28116 KB Output is correct
5 Correct 16 ms 28144 KB Output is correct
6 Correct 15 ms 28092 KB Output is correct
7 Correct 15 ms 28244 KB Output is correct
8 Correct 108 ms 33992 KB Output is correct
9 Correct 101 ms 34088 KB Output is correct
10 Correct 106 ms 34368 KB Output is correct
11 Correct 103 ms 34668 KB Output is correct
12 Correct 97 ms 33604 KB Output is correct
13 Correct 101 ms 34208 KB Output is correct
14 Correct 100 ms 34128 KB Output is correct
15 Correct 99 ms 34148 KB Output is correct
16 Correct 97 ms 33984 KB Output is correct
17 Correct 102 ms 34140 KB Output is correct
18 Correct 112 ms 34244 KB Output is correct
19 Correct 99 ms 34152 KB Output is correct
20 Correct 97 ms 34084 KB Output is correct
21 Correct 102 ms 33892 KB Output is correct
22 Correct 103 ms 34028 KB Output is correct
23 Correct 104 ms 34092 KB Output is correct
24 Correct 106 ms 34124 KB Output is correct
25 Correct 106 ms 34060 KB Output is correct
26 Correct 102 ms 34072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 223 ms 47080 KB Output is correct
2 Correct 218 ms 46156 KB Output is correct
3 Correct 222 ms 44876 KB Output is correct
4 Correct 220 ms 46668 KB Output is correct
5 Correct 218 ms 46436 KB Output is correct
6 Correct 202 ms 41244 KB Output is correct
7 Correct 191 ms 39524 KB Output is correct
8 Correct 198 ms 39224 KB Output is correct
9 Correct 182 ms 39220 KB Output is correct
10 Correct 179 ms 39212 KB Output is correct
11 Correct 179 ms 39116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 28244 KB Output is correct
2 Correct 17 ms 28268 KB Output is correct
3 Correct 17 ms 28348 KB Output is correct
4 Correct 15 ms 28116 KB Output is correct
5 Correct 16 ms 28144 KB Output is correct
6 Correct 15 ms 28092 KB Output is correct
7 Correct 15 ms 28244 KB Output is correct
8 Correct 108 ms 33992 KB Output is correct
9 Correct 101 ms 34088 KB Output is correct
10 Correct 106 ms 34368 KB Output is correct
11 Correct 103 ms 34668 KB Output is correct
12 Correct 97 ms 33604 KB Output is correct
13 Correct 101 ms 34208 KB Output is correct
14 Correct 100 ms 34128 KB Output is correct
15 Correct 99 ms 34148 KB Output is correct
16 Correct 97 ms 33984 KB Output is correct
17 Correct 102 ms 34140 KB Output is correct
18 Correct 112 ms 34244 KB Output is correct
19 Correct 99 ms 34152 KB Output is correct
20 Correct 97 ms 34084 KB Output is correct
21 Correct 102 ms 33892 KB Output is correct
22 Correct 103 ms 34028 KB Output is correct
23 Correct 104 ms 34092 KB Output is correct
24 Correct 106 ms 34124 KB Output is correct
25 Correct 106 ms 34060 KB Output is correct
26 Correct 102 ms 34072 KB Output is correct
27 Correct 223 ms 47080 KB Output is correct
28 Correct 218 ms 46156 KB Output is correct
29 Correct 222 ms 44876 KB Output is correct
30 Correct 220 ms 46668 KB Output is correct
31 Correct 218 ms 46436 KB Output is correct
32 Correct 202 ms 41244 KB Output is correct
33 Correct 191 ms 39524 KB Output is correct
34 Correct 198 ms 39224 KB Output is correct
35 Correct 182 ms 39220 KB Output is correct
36 Correct 179 ms 39212 KB Output is correct
37 Correct 179 ms 39116 KB Output is correct
38 Correct 471 ms 76820 KB Output is correct
39 Correct 551 ms 84532 KB Output is correct
40 Correct 383 ms 67520 KB Output is correct
41 Correct 628 ms 66712 KB Output is correct
42 Correct 229 ms 42948 KB Output is correct
43 Correct 215 ms 41312 KB Output is correct
44 Correct 321 ms 48204 KB Output is correct
45 Correct 322 ms 48208 KB Output is correct
46 Correct 305 ms 48024 KB Output is correct
47 Correct 184 ms 40904 KB Output is correct
48 Correct 185 ms 40300 KB Output is correct
49 Correct 282 ms 46696 KB Output is correct
50 Correct 278 ms 47196 KB Output is correct
51 Correct 296 ms 48352 KB Output is correct
52 Correct 340 ms 65504 KB Output is correct
53 Correct 472 ms 79500 KB Output is correct
54 Correct 590 ms 98032 KB Output is correct
55 Correct 467 ms 81036 KB Output is correct