#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5 + 5;
struct Fenwick {
int s[2 * N];
void upd(int i) {
for (; i; i -= i & -i) {
++s[i];
}
}
int qry(int i) {
int res = 0;
for (; i < 2 * N; i += i & -i) {
res += s[i];
}
return res;
}
} ft[2];
int n, q;
int res[N];
array<int, 2> pt[N];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
cin >> pt[i][0] >> pt[i][1];
}
vector<array<int, 4>> Queries;
array<vector<int>, 2> comp;
for (int i = 1; i <= q; ++i) {
int x, y, z; cin >> x >> y >> z;
comp[0].push_back(y);
comp[1].push_back(z);
if (y < z - x) {
Queries.push_back({x, z, i, 1});
Queries.push_back({z - y, z, -i, 1});
Queries.push_back({z - y, y, i, 0});
} else {
Queries.push_back({x, y, i, 0});
}
}
sort(Queries.rbegin(), Queries.rend());
sort(pt + 1, pt + n + 1);
for (int i = 1; i <= n; ++i) {
comp[0].push_back(pt[i][1]);
comp[1].push_back(pt[i][0] + pt[i][1]);
}
for (auto it : {0, 1}) {
sort(comp[it].begin(), comp[it].end());
comp[it].erase(unique(comp[it].begin(), comp[it].end()), comp[it].end());
}
auto getID = [](vector<int> &comp, int val) {
return lower_bound(comp.begin(), comp.end(), val) - comp.begin() + 1;
};
int j = n;
for (auto [x, y, id, type] : Queries) {
while (j > 0 && pt[j][0] >= x) {
int p = getID(comp[0], pt[j][1]);
ft[0].upd(p);
p = getID(comp[1], pt[j][0] + pt[j][1]);
ft[1].upd(p);
--j;
}
y = getID(comp[type], y);
if (id > 0) {
res[id] += ft[type].qry(y);
} else {
res[-id] -= ft[type].qry(y);
}
}
for (int i = 1; i <= q; ++i) {
cout << res[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
600 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
672 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
7216 KB |
Output is correct |
2 |
Correct |
104 ms |
7168 KB |
Output is correct |
3 |
Correct |
104 ms |
7192 KB |
Output is correct |
4 |
Correct |
66 ms |
6932 KB |
Output is correct |
5 |
Correct |
71 ms |
7100 KB |
Output is correct |
6 |
Correct |
48 ms |
6588 KB |
Output is correct |
7 |
Correct |
90 ms |
7360 KB |
Output is correct |
8 |
Correct |
85 ms |
7072 KB |
Output is correct |
9 |
Correct |
92 ms |
7104 KB |
Output is correct |
10 |
Correct |
75 ms |
6928 KB |
Output is correct |
11 |
Correct |
58 ms |
6592 KB |
Output is correct |
12 |
Correct |
48 ms |
6340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
7216 KB |
Output is correct |
2 |
Correct |
104 ms |
7168 KB |
Output is correct |
3 |
Correct |
104 ms |
7192 KB |
Output is correct |
4 |
Correct |
66 ms |
6932 KB |
Output is correct |
5 |
Correct |
71 ms |
7100 KB |
Output is correct |
6 |
Correct |
48 ms |
6588 KB |
Output is correct |
7 |
Correct |
90 ms |
7360 KB |
Output is correct |
8 |
Correct |
85 ms |
7072 KB |
Output is correct |
9 |
Correct |
92 ms |
7104 KB |
Output is correct |
10 |
Correct |
75 ms |
6928 KB |
Output is correct |
11 |
Correct |
58 ms |
6592 KB |
Output is correct |
12 |
Correct |
48 ms |
6340 KB |
Output is correct |
13 |
Correct |
138 ms |
8484 KB |
Output is correct |
14 |
Correct |
127 ms |
10416 KB |
Output is correct |
15 |
Correct |
104 ms |
9840 KB |
Output is correct |
16 |
Correct |
103 ms |
10736 KB |
Output is correct |
17 |
Correct |
107 ms |
10472 KB |
Output is correct |
18 |
Correct |
71 ms |
7828 KB |
Output is correct |
19 |
Correct |
129 ms |
11808 KB |
Output is correct |
20 |
Correct |
124 ms |
11048 KB |
Output is correct |
21 |
Correct |
149 ms |
12784 KB |
Output is correct |
22 |
Correct |
75 ms |
8896 KB |
Output is correct |
23 |
Correct |
59 ms |
8404 KB |
Output is correct |
24 |
Correct |
53 ms |
7356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
4 ms |
600 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
672 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
109 ms |
7216 KB |
Output is correct |
20 |
Correct |
104 ms |
7168 KB |
Output is correct |
21 |
Correct |
104 ms |
7192 KB |
Output is correct |
22 |
Correct |
66 ms |
6932 KB |
Output is correct |
23 |
Correct |
71 ms |
7100 KB |
Output is correct |
24 |
Correct |
48 ms |
6588 KB |
Output is correct |
25 |
Correct |
90 ms |
7360 KB |
Output is correct |
26 |
Correct |
85 ms |
7072 KB |
Output is correct |
27 |
Correct |
92 ms |
7104 KB |
Output is correct |
28 |
Correct |
75 ms |
6928 KB |
Output is correct |
29 |
Correct |
58 ms |
6592 KB |
Output is correct |
30 |
Correct |
48 ms |
6340 KB |
Output is correct |
31 |
Correct |
138 ms |
8484 KB |
Output is correct |
32 |
Correct |
127 ms |
10416 KB |
Output is correct |
33 |
Correct |
104 ms |
9840 KB |
Output is correct |
34 |
Correct |
103 ms |
10736 KB |
Output is correct |
35 |
Correct |
107 ms |
10472 KB |
Output is correct |
36 |
Correct |
71 ms |
7828 KB |
Output is correct |
37 |
Correct |
129 ms |
11808 KB |
Output is correct |
38 |
Correct |
124 ms |
11048 KB |
Output is correct |
39 |
Correct |
149 ms |
12784 KB |
Output is correct |
40 |
Correct |
75 ms |
8896 KB |
Output is correct |
41 |
Correct |
59 ms |
8404 KB |
Output is correct |
42 |
Correct |
53 ms |
7356 KB |
Output is correct |
43 |
Correct |
150 ms |
14052 KB |
Output is correct |
44 |
Correct |
154 ms |
14644 KB |
Output is correct |
45 |
Correct |
129 ms |
13092 KB |
Output is correct |
46 |
Correct |
103 ms |
12264 KB |
Output is correct |
47 |
Correct |
124 ms |
13044 KB |
Output is correct |
48 |
Correct |
92 ms |
9812 KB |
Output is correct |
49 |
Correct |
161 ms |
13780 KB |
Output is correct |
50 |
Correct |
144 ms |
15088 KB |
Output is correct |
51 |
Correct |
170 ms |
15756 KB |
Output is correct |
52 |
Correct |
133 ms |
12784 KB |
Output is correct |
53 |
Correct |
58 ms |
9448 KB |
Output is correct |