답안 #330286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
330286 2020-11-24T12:48:03 Z dolphingarlic Matryoshka (JOI16_matryoshka) C++14
100 / 100
633 ms 131912 KB
#include <bits/stdc++.h>
using namespace std;

struct Node {
	int l, r, val;
	Node *lc, *rc;

	Node(int L, int R): l(L), r(R), val(0), lc(nullptr), rc(nullptr) {}

	void update(int p, int v) {
		val = max(val, v);
		if (l != r) {
			int mid = (l + r) / 2;
			if (p > mid) {
				if (!rc) rc = new Node(mid + 1, r);
				rc->update(p, v);
			} else {
				if (!lc) lc = new Node(l, mid);
				lc->update(p, v);	
			}
		}
	}

	int query(int a, int b) {
		if (r < a || l > b) return 0;
		if (r <= b && l >= a) return val;
		int ret = 0;
		if (lc) ret = max(ret, lc->query(a, b));
		if (rc) ret = max(ret, rc->query(a, b));
		return ret;
	}
};

pair<int, int> doll[200000];
pair<pair<int, int>, int> query[200000];
int ans[200000];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> doll[i].first >> doll[i].second;
		doll[i].second = -doll[i].second;
	}
	for (int i = 0; i < q; i++) {
		cin >> query[i].first.first >> query[i].first.second;
		query[i].second = i;
	}
	sort(doll, doll + n, greater<pair<int, int>>());
	sort(query, query + q, greater<pair<pair<int, int>, int>>());

	vector<int> dp;
	Node *segtree = new Node(1, 1000000000);
	for (int i = 0, j = 0; i < q; i++) {
		while (j < n && doll[j].first >= query[i].first.first) {
			int lis = upper_bound(dp.begin(), dp.end(), -doll[j].second) - dp.begin();
			if (lis == dp.size()) dp.push_back(-doll[j].second);
			else dp[lis] = -doll[j].second;
			segtree->update(-doll[j].second, lis + 1);
			j++;
		}
		ans[query[i].second] = segtree->query(1, query[i].first.second);
	}

	for (int i = 0; i < q; i++) cout << ans[i] << '\n';
	return 0;
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:59:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    if (lis == dp.size()) dp.push_back(-doll[j].second);
      |        ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 368 KB Output is correct
22 Correct 2 ms 876 KB Output is correct
23 Correct 5 ms 2284 KB Output is correct
24 Correct 5 ms 2284 KB Output is correct
25 Correct 10 ms 2284 KB Output is correct
26 Correct 4 ms 1260 KB Output is correct
27 Correct 5 ms 2412 KB Output is correct
28 Correct 3 ms 1004 KB Output is correct
29 Correct 5 ms 2284 KB Output is correct
30 Correct 4 ms 364 KB Output is correct
31 Correct 5 ms 2284 KB Output is correct
32 Correct 7 ms 2284 KB Output is correct
33 Correct 5 ms 2284 KB Output is correct
34 Correct 5 ms 2284 KB Output is correct
35 Correct 5 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 368 KB Output is correct
22 Correct 2 ms 876 KB Output is correct
23 Correct 5 ms 2284 KB Output is correct
24 Correct 5 ms 2284 KB Output is correct
25 Correct 10 ms 2284 KB Output is correct
26 Correct 4 ms 1260 KB Output is correct
27 Correct 5 ms 2412 KB Output is correct
28 Correct 3 ms 1004 KB Output is correct
29 Correct 5 ms 2284 KB Output is correct
30 Correct 4 ms 364 KB Output is correct
31 Correct 5 ms 2284 KB Output is correct
32 Correct 7 ms 2284 KB Output is correct
33 Correct 5 ms 2284 KB Output is correct
34 Correct 5 ms 2284 KB Output is correct
35 Correct 5 ms 2284 KB Output is correct
36 Correct 411 ms 19820 KB Output is correct
37 Correct 206 ms 6124 KB Output is correct
38 Correct 183 ms 64492 KB Output is correct
39 Correct 192 ms 5740 KB Output is correct
40 Correct 187 ms 6508 KB Output is correct
41 Correct 243 ms 6124 KB Output is correct
42 Correct 170 ms 6512 KB Output is correct
43 Correct 129 ms 7400 KB Output is correct
44 Correct 633 ms 131912 KB Output is correct
45 Correct 628 ms 131828 KB Output is correct
46 Correct 629 ms 131820 KB Output is correct
47 Correct 526 ms 130816 KB Output is correct
48 Correct 510 ms 131280 KB Output is correct
49 Correct 498 ms 130924 KB Output is correct
50 Correct 502 ms 131308 KB Output is correct