Submission #330284

# Submission time Handle Problem Language Result Execution time Memory
330284 2020-11-24T12:44:39 Z dolphingarlic None (JOI16_matryoshka) C++14
100 / 100
643 ms 133484 KB
#include <bits/stdc++.h>
typedef long long ll;
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 lis[200000], 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;
	for (int i = 0; i < n; i++) {
		lis[i] = upper_bound(dp.begin(), dp.end(), -doll[i].second) - dp.begin();
		if (lis[i] == dp.size()) dp.push_back(-doll[i].second);
		else dp[lis[i]] = -doll[i].second;
		lis[i]++;
	}

	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) {
			segtree->update(-doll[j].second, lis[j]);
			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:58:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   if (lis[i] == dp.size()) dp.push_back(-doll[i].second);
      |       ~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 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 364 KB Output is correct
22 Correct 2 ms 876 KB Output is correct
23 Correct 5 ms 2432 KB Output is correct
24 Correct 5 ms 2560 KB Output is correct
25 Correct 5 ms 2412 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 2412 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 5 ms 2412 KB Output is correct
32 Correct 5 ms 2412 KB Output is correct
33 Correct 6 ms 2412 KB Output is correct
34 Correct 5 ms 2412 KB Output is correct
35 Correct 5 ms 2412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 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 364 KB Output is correct
22 Correct 2 ms 876 KB Output is correct
23 Correct 5 ms 2432 KB Output is correct
24 Correct 5 ms 2560 KB Output is correct
25 Correct 5 ms 2412 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 2412 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 5 ms 2412 KB Output is correct
32 Correct 5 ms 2412 KB Output is correct
33 Correct 6 ms 2412 KB Output is correct
34 Correct 5 ms 2412 KB Output is correct
35 Correct 5 ms 2412 KB Output is correct
36 Correct 478 ms 21236 KB Output is correct
37 Correct 203 ms 7404 KB Output is correct
38 Correct 183 ms 65644 KB Output is correct
39 Correct 202 ms 7276 KB Output is correct
40 Correct 221 ms 7788 KB Output is correct
41 Correct 243 ms 7532 KB Output is correct
42 Correct 167 ms 8048 KB Output is correct
43 Correct 128 ms 8808 KB Output is correct
44 Correct 631 ms 133484 KB Output is correct
45 Correct 643 ms 133100 KB Output is correct
46 Correct 640 ms 133228 KB Output is correct
47 Correct 507 ms 131948 KB Output is correct
48 Correct 514 ms 132460 KB Output is correct
49 Correct 499 ms 132056 KB Output is correct
50 Correct 512 ms 132676 KB Output is correct