#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) begin(a), end(a)
#define pb push_back
using namespace std;
using pii = pair<int, int>;
int const N = 100005;
int n, q;
vector<pii> v;
vector<array<int, 4>> qs;
void load() {
cin >> n >> q;
v.resize(n);
qs.resize(q);
for (auto &[a, b] : v) cin >> a >> b;
for (int i = 0; i < q; ++i) {
cin >> qs[i][0] >> qs[i][1] >> qs[i][2];
qs[i][2] = max(qs[i][2], qs[i][0] + qs[i][1]);
qs[i][3] = i;
}
}
struct BIT {
array<int, N> bit;
void add(int p, int k) {
for (++p; p < N; p += p & -p) {
bit[p] += k;
}
}
int sum(int r) {
int val = 0;
for (; r > 0; r -= r & -r) {
val += bit[r];
}
return val;
}
int sum(int l, int r) {
return sum(r) - sum(l);
}
};
vector<int> xs, ys;
void compress() {
for (auto [a, b] : v) {
xs.pb(a);
ys.pb(b);
}
sort(all(xs));
sort(all(ys));
xs.erase(unique(all(xs)), end(xs));
ys.erase(unique(all(ys)), end(ys));
}
void solve() {
sort(all(qs), [](auto const &a, auto const &b) {
return a[2] > b[2];
});
sort(all(v), [](auto const &a, auto const &b) {
return a.F + a.S > b.F + b.S;
});
compress();
int sz = 0;
vector<int> ans(q);
BIT valx, valy;
for (auto arr : qs) {
while (sz < n && v[sz].F + v[sz].S >= arr[2]) {
// cerr << v[sz].F << ' ' << v[sz].S << endl;
valx.add(lower_bound(all(xs), v[sz].F) - begin(xs), 1);
valy.add(lower_bound(all(ys), v[sz].S) - begin(ys), 1);
sz++;
}
ans[arr[3]] = sz - valx.sum(lower_bound(all(xs), arr[0]) - begin(xs)) - valy.sum(lower_bound(all(ys), arr[1]) - begin(ys));
}
for (auto a : ans) cout << a << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
load();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
1084 KB |
Output is correct |
3 |
Correct |
1 ms |
1088 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
5 ms |
1336 KB |
Output is correct |
8 |
Correct |
6 ms |
1308 KB |
Output is correct |
9 |
Correct |
5 ms |
1364 KB |
Output is correct |
10 |
Correct |
4 ms |
1256 KB |
Output is correct |
11 |
Correct |
4 ms |
1264 KB |
Output is correct |
12 |
Correct |
3 ms |
1236 KB |
Output is correct |
13 |
Correct |
4 ms |
1364 KB |
Output is correct |
14 |
Correct |
6 ms |
1284 KB |
Output is correct |
15 |
Correct |
5 ms |
1364 KB |
Output is correct |
16 |
Correct |
3 ms |
1244 KB |
Output is correct |
17 |
Correct |
5 ms |
1236 KB |
Output is correct |
18 |
Correct |
2 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
7796 KB |
Output is correct |
2 |
Correct |
141 ms |
7896 KB |
Output is correct |
3 |
Correct |
129 ms |
7908 KB |
Output is correct |
4 |
Correct |
80 ms |
7104 KB |
Output is correct |
5 |
Correct |
82 ms |
7104 KB |
Output is correct |
6 |
Correct |
53 ms |
6360 KB |
Output is correct |
7 |
Correct |
150 ms |
7764 KB |
Output is correct |
8 |
Correct |
127 ms |
7808 KB |
Output is correct |
9 |
Correct |
119 ms |
7664 KB |
Output is correct |
10 |
Correct |
79 ms |
6864 KB |
Output is correct |
11 |
Correct |
89 ms |
6884 KB |
Output is correct |
12 |
Correct |
46 ms |
5948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
7796 KB |
Output is correct |
2 |
Correct |
141 ms |
7896 KB |
Output is correct |
3 |
Correct |
129 ms |
7908 KB |
Output is correct |
4 |
Correct |
80 ms |
7104 KB |
Output is correct |
5 |
Correct |
82 ms |
7104 KB |
Output is correct |
6 |
Correct |
53 ms |
6360 KB |
Output is correct |
7 |
Correct |
150 ms |
7764 KB |
Output is correct |
8 |
Correct |
127 ms |
7808 KB |
Output is correct |
9 |
Correct |
119 ms |
7664 KB |
Output is correct |
10 |
Correct |
79 ms |
6864 KB |
Output is correct |
11 |
Correct |
89 ms |
6884 KB |
Output is correct |
12 |
Correct |
46 ms |
5948 KB |
Output is correct |
13 |
Correct |
151 ms |
8280 KB |
Output is correct |
14 |
Correct |
141 ms |
8236 KB |
Output is correct |
15 |
Correct |
128 ms |
7860 KB |
Output is correct |
16 |
Correct |
91 ms |
7492 KB |
Output is correct |
17 |
Correct |
92 ms |
7488 KB |
Output is correct |
18 |
Correct |
58 ms |
6384 KB |
Output is correct |
19 |
Correct |
160 ms |
8288 KB |
Output is correct |
20 |
Correct |
135 ms |
8276 KB |
Output is correct |
21 |
Correct |
132 ms |
8276 KB |
Output is correct |
22 |
Correct |
79 ms |
6992 KB |
Output is correct |
23 |
Correct |
76 ms |
6976 KB |
Output is correct |
24 |
Correct |
48 ms |
5984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
1084 KB |
Output is correct |
3 |
Correct |
1 ms |
1088 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
5 ms |
1336 KB |
Output is correct |
8 |
Correct |
6 ms |
1308 KB |
Output is correct |
9 |
Correct |
5 ms |
1364 KB |
Output is correct |
10 |
Correct |
4 ms |
1256 KB |
Output is correct |
11 |
Correct |
4 ms |
1264 KB |
Output is correct |
12 |
Correct |
3 ms |
1236 KB |
Output is correct |
13 |
Correct |
4 ms |
1364 KB |
Output is correct |
14 |
Correct |
6 ms |
1284 KB |
Output is correct |
15 |
Correct |
5 ms |
1364 KB |
Output is correct |
16 |
Correct |
3 ms |
1244 KB |
Output is correct |
17 |
Correct |
5 ms |
1236 KB |
Output is correct |
18 |
Correct |
2 ms |
1236 KB |
Output is correct |
19 |
Correct |
145 ms |
7796 KB |
Output is correct |
20 |
Correct |
141 ms |
7896 KB |
Output is correct |
21 |
Correct |
129 ms |
7908 KB |
Output is correct |
22 |
Correct |
80 ms |
7104 KB |
Output is correct |
23 |
Correct |
82 ms |
7104 KB |
Output is correct |
24 |
Correct |
53 ms |
6360 KB |
Output is correct |
25 |
Correct |
150 ms |
7764 KB |
Output is correct |
26 |
Correct |
127 ms |
7808 KB |
Output is correct |
27 |
Correct |
119 ms |
7664 KB |
Output is correct |
28 |
Correct |
79 ms |
6864 KB |
Output is correct |
29 |
Correct |
89 ms |
6884 KB |
Output is correct |
30 |
Correct |
46 ms |
5948 KB |
Output is correct |
31 |
Correct |
151 ms |
8280 KB |
Output is correct |
32 |
Correct |
141 ms |
8236 KB |
Output is correct |
33 |
Correct |
128 ms |
7860 KB |
Output is correct |
34 |
Correct |
91 ms |
7492 KB |
Output is correct |
35 |
Correct |
92 ms |
7488 KB |
Output is correct |
36 |
Correct |
58 ms |
6384 KB |
Output is correct |
37 |
Correct |
160 ms |
8288 KB |
Output is correct |
38 |
Correct |
135 ms |
8276 KB |
Output is correct |
39 |
Correct |
132 ms |
8276 KB |
Output is correct |
40 |
Correct |
79 ms |
6992 KB |
Output is correct |
41 |
Correct |
76 ms |
6976 KB |
Output is correct |
42 |
Correct |
48 ms |
5984 KB |
Output is correct |
43 |
Incorrect |
148 ms |
10248 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |