#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[N];
void upd(int i) {
for (; i; i -= i & -i) {
++s[i];
}
}
int qry(int i) {
int res = 0;
for (; i < 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 |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
868 KB |
Output is correct |
8 |
Correct |
4 ms |
736 KB |
Output is correct |
9 |
Correct |
4 ms |
856 KB |
Output is correct |
10 |
Correct |
4 ms |
860 KB |
Output is correct |
11 |
Correct |
3 ms |
860 KB |
Output is correct |
12 |
Correct |
4 ms |
792 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
3 ms |
820 KB |
Output is correct |
15 |
Correct |
3 ms |
732 KB |
Output is correct |
16 |
Correct |
2 ms |
552 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
9624 KB |
Output is correct |
2 |
Correct |
114 ms |
9664 KB |
Output is correct |
3 |
Correct |
104 ms |
9660 KB |
Output is correct |
4 |
Correct |
64 ms |
8636 KB |
Output is correct |
5 |
Correct |
80 ms |
9028 KB |
Output is correct |
6 |
Correct |
55 ms |
7624 KB |
Output is correct |
7 |
Correct |
103 ms |
9740 KB |
Output is correct |
8 |
Correct |
100 ms |
9684 KB |
Output is correct |
9 |
Correct |
97 ms |
9408 KB |
Output is correct |
10 |
Correct |
80 ms |
8828 KB |
Output is correct |
11 |
Correct |
58 ms |
8384 KB |
Output is correct |
12 |
Correct |
47 ms |
7356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
9624 KB |
Output is correct |
2 |
Correct |
114 ms |
9664 KB |
Output is correct |
3 |
Correct |
104 ms |
9660 KB |
Output is correct |
4 |
Correct |
64 ms |
8636 KB |
Output is correct |
5 |
Correct |
80 ms |
9028 KB |
Output is correct |
6 |
Correct |
55 ms |
7624 KB |
Output is correct |
7 |
Correct |
103 ms |
9740 KB |
Output is correct |
8 |
Correct |
100 ms |
9684 KB |
Output is correct |
9 |
Correct |
97 ms |
9408 KB |
Output is correct |
10 |
Correct |
80 ms |
8828 KB |
Output is correct |
11 |
Correct |
58 ms |
8384 KB |
Output is correct |
12 |
Correct |
47 ms |
7356 KB |
Output is correct |
13 |
Runtime error |
93 ms |
17260 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
868 KB |
Output is correct |
8 |
Correct |
4 ms |
736 KB |
Output is correct |
9 |
Correct |
4 ms |
856 KB |
Output is correct |
10 |
Correct |
4 ms |
860 KB |
Output is correct |
11 |
Correct |
3 ms |
860 KB |
Output is correct |
12 |
Correct |
4 ms |
792 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
3 ms |
820 KB |
Output is correct |
15 |
Correct |
3 ms |
732 KB |
Output is correct |
16 |
Correct |
2 ms |
552 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
108 ms |
9624 KB |
Output is correct |
20 |
Correct |
114 ms |
9664 KB |
Output is correct |
21 |
Correct |
104 ms |
9660 KB |
Output is correct |
22 |
Correct |
64 ms |
8636 KB |
Output is correct |
23 |
Correct |
80 ms |
9028 KB |
Output is correct |
24 |
Correct |
55 ms |
7624 KB |
Output is correct |
25 |
Correct |
103 ms |
9740 KB |
Output is correct |
26 |
Correct |
100 ms |
9684 KB |
Output is correct |
27 |
Correct |
97 ms |
9408 KB |
Output is correct |
28 |
Correct |
80 ms |
8828 KB |
Output is correct |
29 |
Correct |
58 ms |
8384 KB |
Output is correct |
30 |
Correct |
47 ms |
7356 KB |
Output is correct |
31 |
Runtime error |
93 ms |
17260 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |