Submission #330285

# Submission time Handle Problem Language Result Execution time Memory
330285 2020-11-24T12:46:52 Z dolphingarlic None (JOI16_matryoshka) C++14
0 / 100
1 ms 364 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);
			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);
      |        ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -