#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
const int N = 2e5+7;
struct Tree {
int length, index;
Tree() {
length = 0;
index = 1;
}
} tree[N*4];
Tree max(Tree a, Tree b) {
if (a.length == b.length) {
if (a.index > b.index) return a;
else return b;
}
else if (a.length > b.length) return a;
else return b;
}
void update(int v, int l, int r, int pos, Tree val) {
if (l == r) {
tree[v] = val;
return;
}
int mid = (l+r) >> 1;
if (pos <= mid) update(v*2, l, mid, pos, val);
else update(v*2+1, mid+1, r, pos, val);
tree[v] = max(tree[v*2], tree[v*2+1]);
}
Tree get(int v, int l, int r, int ql, int qr) {
if (ql > r || l > qr) return Tree();
if (ql <= l && r <= qr) return tree[v];
int mid = (l+r) >> 1;
return max(get(v*2, l, mid, ql, qr), get(v*2+1, mid+1, r, ql, qr));
}
void solve() {
for (int i = 0; i < N; i++) {
update(1, 0, N-1, i, Tree());
}
int n, m;
cin >> n >> m;
vector <int> S(n), V(n), C(m), indices(n);
for (int i = 0; i < n; i++) {
cin >> S[i] >> V[i];
}
for (int i = 0; i < m; i++) {
cin >> C[i];
}
sort(all(C));
iota(all(indices), 0);
sort(all(indices), [&](int a, int b) {
if (S[a] == S[b]) return V[a] < V[b];
return S[a] < S[b];
});
// Relative order
set <int> Sset, Vset;
map <int, int> Srel, Vrel;
for (int i = 0; i < n; i++) {
Sset.insert(S[i]);
Vset.insert(V[i]);
}
for (int i = 0; i < m; i++) {
Sset.insert(C[i]);
}
int j = 0;
for (auto to : Sset) {
Srel[to] = j++;
}
j = 0;
for (auto to : Vset) {
Vrel[to] = j++;
}
for (int i = 0; i < n; i++) {
S[i] = Srel[S[i]];
V[i] = Vrel[V[i]];
}
for (int i = 0; i < m; i++) {
C[i] = Srel[C[i]];
}
for (int i = 0; i < n; i++) {
int j = indices[i];
auto res = get(1, 0, N-1, 0, V[j]);
res.index = -res.index + 1;
int it = lb(all(C), S[j]) - C.begin();
if (res.index == m || it == m) {
continue;
}
res.index = max(res.index, it);
res.length++;
res.index = -res.index;
if (res.length != n) {
update(1, 0, N-1, V[j], res);
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
auto res = get(1, 0, N-1, i, i);
ans = max(ans, res.length);
}
cout << ans;
}
int main() {
do_not_disturb
int t = 1;
//~ cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
6572 KB |
Output is correct |
2 |
Incorrect |
24 ms |
6572 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
6572 KB |
Output is correct |
2 |
Incorrect |
24 ms |
6572 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
6572 KB |
Output is correct |
2 |
Incorrect |
24 ms |
6572 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |