#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 2e5 + 5;
int N, Q;
struct Point {
int a, b, c, i;
} p[MN];
int b[MN], ans[MN];
void upd(int i, int v) {
for (; i < MN; i += i & -i) b[i] += v;
}
int get(int i) {
int r = 0;
for (; i; i -= i & -i) r += b[i];
return r;
}
void cdq(int l, int r) {
if (l == r) return;
int m = (l + r) / 2;
cdq(l, m), cdq(m + 1, r);
sort(p + l, p + r + 1, [](Point x, Point y) {
return x.a == y.a ? x.i < y.i : x.a > y.a;
});
for (int i = l; i <= r; i++) {
if (p[i].c <= m && !p[i].i) upd(p[i].b, 1);
if (p[i].c > m && p[i].i) ans[p[i].i] += get(2e5) - get(p[i].b - 1);
}
for (int i = l; i <= r; i++)
if (p[i].c <= m && !p[i].i) upd(p[i].b, -1);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> Q;
vector<int> ca, cb;
for (int i = 1; i <= N; i++) {
cin >> p[i].a >> p[i].b;
p[i].c = p[i].a + p[i].b;
ca.push_back(p[i].a);
cb.push_back(p[i].b);
}
for (int i = N + 1; i <= N + Q; i++) {
cin >> p[i].a >> p[i].b >> p[i].c;
p[i].i = i - N;
ca.push_back(p[i].a);
cb.push_back(p[i].b);
}
sort(p + 1, p + 1 + N + Q + 1, [](Point x, Point y) {
return x.c == y.c ? x.i < y.i : x.c > y.c;
});
sort(all(ca)), sort(all(cb));
ca.erase(unique(all(ca)), ca.end());
cb.erase(unique(all(cb)), cb.end());
for (int i = 1; i <= N + Q; i++) {
p[i].a = lower_bound(all(ca), p[i].a) - ca.begin() + 1;
p[i].b = lower_bound(all(cb), p[i].b) - cb.begin() + 1;
p[i].c = i;
}
cdq(1, N + Q);
for (int i = 1; i <= Q; i++) cout << ans[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
12 ms |
748 KB |
Output is correct |
8 |
Correct |
11 ms |
748 KB |
Output is correct |
9 |
Correct |
11 ms |
748 KB |
Output is correct |
10 |
Correct |
9 ms |
748 KB |
Output is correct |
11 |
Correct |
9 ms |
748 KB |
Output is correct |
12 |
Incorrect |
7 ms |
620 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
457 ms |
9176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
457 ms |
9176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
12 ms |
748 KB |
Output is correct |
8 |
Correct |
11 ms |
748 KB |
Output is correct |
9 |
Correct |
11 ms |
748 KB |
Output is correct |
10 |
Correct |
9 ms |
748 KB |
Output is correct |
11 |
Correct |
9 ms |
748 KB |
Output is correct |
12 |
Incorrect |
7 ms |
620 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |