Submission #208446

# Submission time Handle Problem Language Result Execution time Memory
208446 2020-03-11T08:15:49 Z Siberian Exhibition (JOI19_ho_t2) C++14
0 / 100
5 ms 376 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

struct event{
	int s, v;
	event () {}
	event(int _s, int _v) {
		s = _s, v = _v;
	}
};

bool operator<(const event & a, const event & b) {
	return tie(a.v, a.s) < tie(b.v, b.s);
}

int n, m;
vector<event> a;
vector<int> c;

void read() {
	cin >> n >> m;
	a.resize(n);
	for (auto &i : a) {
		cin >> i.s >> i.v;
	}
	sort(all(a));
	c.resize(m);
	for (auto &i : c) {
		cin >> i;
	}
	sort(all(c));
	reverse(all(c));
}

struct segment_tree{
	vector<int> tree;
	int n;
	segment_tree() {}
	segment_tree(int sz) {
		n = sz;
		tree.assign(n, 0);
	}
	int get(int r) {
		int ans = 0;
		for (int i = 0; i <= r; i++)
			chkmax(ans, tree[i]);
		return ans;
	}

	void upd(int pos, int val) {
		tree[pos] = val;
	}
};

bool check(int cnt) {
	vector<int> fc;
	for (int i = 0; i < cnt; i++)
		fc.push_back(c[i]);
	reverse(all(fc));

	segment_tree tree(n);
	for (auto i : a) {
		int have = tree.get(i.v);
		int min_pos = lower_bound(all(fc), i.s) - fc.begin();
		if (min_pos > have) continue;
		tree.upd(i.v, have + 1);
	}
	return tree.get(n) >= cnt;
}

int ans;

void build() {
	vector<int> have;
	for (auto i : a) {
		have.push_back(i.v);
	}
	sort(all(have));
	have.resize(unique(all(have)) - have.begin());
	for (auto &i : a) {
		i.v = lower_bound(all(have), i.v) - have.begin();
	}
}

void run() {
	build();
	int l = 0, r = min(n, m) + 1;
	while (l < r - 1) {
		int mid = (l + r) / 2;
		if (check(mid))
			l = mid;
		else
			r = mid;
	}
	ans = l;
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -