This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 400005
using namespace std;
int n, m, M = 1e9, sz, b[N], ans[N];
struct str {
int r, h, z, num;
} a[N];
bool comp(str p, str q) {
if (p.h != q.h) return p.h < q.h;
else if (p.r != q.r) return p.r > q.r;
else return p.z < q.z;
}
int main() {
int i, j, x, t;
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> a[i].r >> a[i].h;
a[i].z = a[i].num = 0;
}
for (i = 0; i < m; i++) {
cin >> a[n + i].r >> a[n + i].h;
a[n + i].z = 1;
a[n + i].num = i;
}
sort(a, a + n + m, comp);
for (i = 0; i < n + m; i++) {
x = M - a[i].r;
t = upper_bound(b, b + sz, x) - b;
if (a[i].z == 1) {
ans[a[i].num] = t;
} else {
b[t] = x;
if (t == sz) sz++;
}
}
for (i = 0; i < m; i++) {
printf("%d\n", ans[i]);
}
return 0;
}
Compilation message (stderr)
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:19:12: warning: unused variable 'j' [-Wunused-variable]
19 | int i, j, x, t;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |