답안 #927235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927235 2024-02-14T13:38:55 Z Gromp15 Exhibition (JOI19_ho_t2) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
struct seg {
	int N; vector<int> tree;
	seg(int n) : N(1<<(__lg(n))), tree(2*N) {}
	void update(int pos, int x) {
		for (int i = pos+N; i; i >>= 1) {
			ckmax(tree[i], x);
		}
	}
	int query(int node, int nl, int nr, int ql, int qr) {
		if (ql > nr || qr < nl) return 0;
		if (ql <= nl && nr <= qr) return tree[node];
		int mid = (nl+nr)/2;
		return max(query(node*2, nl, mid, ql, qr), query(node*2+1, mid+1, nr, ql, qr));
	}
	int query(int l, int r) {
		return query(1, 0, N-1, l, r);
	}
};
void test_case() {
	int n, m;
	cin >> n >> m;
	vector<int> X, Y;
	vector<ar<int, 2>> a(n);
	for (auto &x : a) cin >> x[0] >> x[1], X.push_back(x[0]), Y.push_back(x[1]);
	vector<int> s(m);
	for (int &x : s) cin >> x, X.push_back(x);
	sort(all(X));
	sort(all(Y));
	X.erase(unique(all(X)), X.end());
	Y.erase(unique(all(Y)), Y.end());
	for (auto &x : a) {
		x[0] = lower_bound(all(X), x[0]) - X.begin();
		x[1] = lower_bound(all(Y), x[1]) - Y.begin();
	}
	for (int &x : s) {
		x = lower_bound(all(X), x) - X.begin();
	}
	sort(all(a));
	sort(all(s));
	const int N = sz(Y);
	seg dp(N);
	int on = m;
	for (int i = n-1; i >= 0; i--) {
		auto [x, y] = a[i];
		while (on-1 >= 0 && s[on-1] >= x) on--;
		// we have m - on usable frames
		int use = m - on;
		dp.update(y, min(use, dp.query(y, N-1) + 1));
	}
	cout << dp.query(0, N-1) << '\n';


}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
//    cin >> t;
    while (t--) test_case();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -