#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
int st[4 * N];
void Add(int node, int l, int r, int x, int y) {
smax(st[node], y);
if (l == r) return;
int mid = l + r >> 1;
if (x <= mid) Add(2 * node, l, mid, x, y);
else Add(2 * node + 1, mid + 1, r, x, y);
}
int Get(int node, int l, int r, int ql, int qr) {
if (r < ql || qr < l) return 0;
if (ql <= l && r <= qr) return st[node];
int mid = l + r >> 1;
return max(Get(2 * node, l, mid, ql, qr), Get(2 * node + 1, mid + 1, r, ql, qr));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a.rbegin(), a.rend());
vector<int> b(m);
for (int i = 0; i < m; i++) {
cin >> b[i];
}
sort(b.rbegin(), b.rend());
vector<int> bound(n);
int j = 0;
for (int i = 0; i < n; i++) {
while (j < m && a[i].first <= b[j]) j++;
bound[i] = j;
}
vector<pair<int, int>> all;
for (int i = 0; i < n; i++) all.push_back({a[i].second, i});
sort(all.begin(), all.end());
int z = 0;
for (int i = 0; i < n; i++) {
if (i > 0 && all[i - 1].first != all[i].first) z++;
a[all[i].second].second = z;
}
int ans = 0;
for (int i = 0; i < n; i++) {
int x = min(Get(1, 0, z, a[i].second, z) + 1, bound[i]);
smax(ans, x);
Add(1, 0, z, a[i].second, x);
}
cout << ans << en;
return 0;
}
Compilation message
joi2019_ho_t2.cpp: In function 'void Add(int, int, int, int, int)':
joi2019_ho_t2.cpp:14:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
14 | int mid = l + r >> 1;
| ~~^~~
joi2019_ho_t2.cpp: In function 'int Get(int, int, int, int, int)':
joi2019_ho_t2.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |