#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define lb(x...) lower_bound(x)
#define all(x) begin(x), end(x)
using ll = int64_t;
const int N = 1 << 17;
int n, m;
int t[4 * N];
int query(int l, int r) {
int sum = 0;
for (l += m, r += m; l < r; l >>= 1, r >>= 1) {
if (l & 1) sum += t[l++];
if (r & 1) sum += t[--r];
}
return sum;
}
void update(int p, int x) {
for (t[p += m] += x; p >>= 1; ) t[p] = t[p << 1] + t[p << 1|1];
}
struct point {
int x, y, z, idx;
bool operator<(const point &p) {
return tuple<int, int, int, int>(-x, y, z, idx) < tuple<int, int, int, int>(-p.x, p.y, p.z, p.idx);
}
} a[2 * N], tmp[2 * N];
vector<int> cmp;
int ans[N];
void cdq(int l, int r) {
if (r - l == 1) return;
int m = (l + r) / 2;
cdq(l, m); cdq(m, r);
vector<int> op;
int i = l, j = m, k = l, cnt = 0;
while (i < m && j < r) {
if (a[j].y < a[i].y) {
if (!a[i].idx) ++cnt, update(a[i].z, 1), op.eb(a[i].z);
tmp[k++] = a[i++];
} else {
if (a[j].idx) ans[a[j].idx] += cnt - query(0, a[j].z + 1);
tmp[k++] = a[j++];
}
}
while (i < m) tmp[k++] = a[i++];
while (j < r) {
if (a[j].idx) ans[a[j].idx] += cnt - query(0, a[j].z + 1);
tmp[k++] = a[j++];
}
rep(i, l, r) a[i] = tmp[i];
for (int p : op) update(p, -1);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int q; cin >> n >> q;
rep(i, 0, n) {
int x, y; cin >> x >> y;
a[i] = {x, y, x + y, 0};
cmp.eb(x + y);
}
rep(i, 0, q) {
int x, y, z; cin >> x >> y >> z;
a[i + n] = {--x, --y, --z, i + 1};
cmp.eb(z);
}
sort(all(cmp)); cmp.resize(m = unique(all(cmp)) - begin(cmp));
rep(i, 0, n + q) a[i].z = lb(all(cmp), a[i].z) - begin(cmp);
sort(a, a + n + q); cdq(0, n + q);
rep(i, 0, q) cout << ans[i + 1] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
9 ms |
896 KB |
Output is correct |
8 |
Correct |
8 ms |
896 KB |
Output is correct |
9 |
Correct |
8 ms |
896 KB |
Output is correct |
10 |
Correct |
7 ms |
768 KB |
Output is correct |
11 |
Correct |
7 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
6 ms |
768 KB |
Output is correct |
14 |
Correct |
6 ms |
768 KB |
Output is correct |
15 |
Correct |
6 ms |
768 KB |
Output is correct |
16 |
Correct |
4 ms |
768 KB |
Output is correct |
17 |
Correct |
7 ms |
768 KB |
Output is correct |
18 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
10736 KB |
Output is correct |
2 |
Correct |
251 ms |
10484 KB |
Output is correct |
3 |
Correct |
242 ms |
10480 KB |
Output is correct |
4 |
Correct |
197 ms |
10352 KB |
Output is correct |
5 |
Correct |
146 ms |
10320 KB |
Output is correct |
6 |
Correct |
104 ms |
9840 KB |
Output is correct |
7 |
Correct |
206 ms |
10220 KB |
Output is correct |
8 |
Correct |
217 ms |
10480 KB |
Output is correct |
9 |
Correct |
233 ms |
10272 KB |
Output is correct |
10 |
Correct |
138 ms |
10096 KB |
Output is correct |
11 |
Correct |
197 ms |
10224 KB |
Output is correct |
12 |
Correct |
73 ms |
9452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
10736 KB |
Output is correct |
2 |
Correct |
251 ms |
10484 KB |
Output is correct |
3 |
Correct |
242 ms |
10480 KB |
Output is correct |
4 |
Correct |
197 ms |
10352 KB |
Output is correct |
5 |
Correct |
146 ms |
10320 KB |
Output is correct |
6 |
Correct |
104 ms |
9840 KB |
Output is correct |
7 |
Correct |
206 ms |
10220 KB |
Output is correct |
8 |
Correct |
217 ms |
10480 KB |
Output is correct |
9 |
Correct |
233 ms |
10272 KB |
Output is correct |
10 |
Correct |
138 ms |
10096 KB |
Output is correct |
11 |
Correct |
197 ms |
10224 KB |
Output is correct |
12 |
Correct |
73 ms |
9452 KB |
Output is correct |
13 |
Correct |
339 ms |
10864 KB |
Output is correct |
14 |
Correct |
342 ms |
12780 KB |
Output is correct |
15 |
Correct |
224 ms |
11916 KB |
Output is correct |
16 |
Correct |
310 ms |
11756 KB |
Output is correct |
17 |
Correct |
277 ms |
11632 KB |
Output is correct |
18 |
Correct |
98 ms |
9980 KB |
Output is correct |
19 |
Correct |
348 ms |
12908 KB |
Output is correct |
20 |
Correct |
352 ms |
12644 KB |
Output is correct |
21 |
Correct |
357 ms |
12436 KB |
Output is correct |
22 |
Correct |
124 ms |
10864 KB |
Output is correct |
23 |
Correct |
189 ms |
10992 KB |
Output is correct |
24 |
Correct |
73 ms |
9584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
9 ms |
896 KB |
Output is correct |
8 |
Correct |
8 ms |
896 KB |
Output is correct |
9 |
Correct |
8 ms |
896 KB |
Output is correct |
10 |
Correct |
7 ms |
768 KB |
Output is correct |
11 |
Correct |
7 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
6 ms |
768 KB |
Output is correct |
14 |
Correct |
6 ms |
768 KB |
Output is correct |
15 |
Correct |
6 ms |
768 KB |
Output is correct |
16 |
Correct |
4 ms |
768 KB |
Output is correct |
17 |
Correct |
7 ms |
768 KB |
Output is correct |
18 |
Correct |
2 ms |
640 KB |
Output is correct |
19 |
Correct |
236 ms |
10736 KB |
Output is correct |
20 |
Correct |
251 ms |
10484 KB |
Output is correct |
21 |
Correct |
242 ms |
10480 KB |
Output is correct |
22 |
Correct |
197 ms |
10352 KB |
Output is correct |
23 |
Correct |
146 ms |
10320 KB |
Output is correct |
24 |
Correct |
104 ms |
9840 KB |
Output is correct |
25 |
Correct |
206 ms |
10220 KB |
Output is correct |
26 |
Correct |
217 ms |
10480 KB |
Output is correct |
27 |
Correct |
233 ms |
10272 KB |
Output is correct |
28 |
Correct |
138 ms |
10096 KB |
Output is correct |
29 |
Correct |
197 ms |
10224 KB |
Output is correct |
30 |
Correct |
73 ms |
9452 KB |
Output is correct |
31 |
Correct |
339 ms |
10864 KB |
Output is correct |
32 |
Correct |
342 ms |
12780 KB |
Output is correct |
33 |
Correct |
224 ms |
11916 KB |
Output is correct |
34 |
Correct |
310 ms |
11756 KB |
Output is correct |
35 |
Correct |
277 ms |
11632 KB |
Output is correct |
36 |
Correct |
98 ms |
9980 KB |
Output is correct |
37 |
Correct |
348 ms |
12908 KB |
Output is correct |
38 |
Correct |
352 ms |
12644 KB |
Output is correct |
39 |
Correct |
357 ms |
12436 KB |
Output is correct |
40 |
Correct |
124 ms |
10864 KB |
Output is correct |
41 |
Correct |
189 ms |
10992 KB |
Output is correct |
42 |
Correct |
73 ms |
9584 KB |
Output is correct |
43 |
Correct |
387 ms |
15544 KB |
Output is correct |
44 |
Correct |
381 ms |
15392 KB |
Output is correct |
45 |
Correct |
388 ms |
15340 KB |
Output is correct |
46 |
Correct |
338 ms |
13664 KB |
Output is correct |
47 |
Correct |
278 ms |
13804 KB |
Output is correct |
48 |
Correct |
123 ms |
9780 KB |
Output is correct |
49 |
Correct |
366 ms |
14940 KB |
Output is correct |
50 |
Correct |
380 ms |
15316 KB |
Output is correct |
51 |
Correct |
366 ms |
14960 KB |
Output is correct |
52 |
Correct |
270 ms |
13552 KB |
Output is correct |
53 |
Correct |
190 ms |
12012 KB |
Output is correct |