#include <iostream>
#include <algorithm>
#include <vector>
#define fs first
#define se second
using namespace std;
typedef pair<int, int> pii;
const int inf = 1e9;
struct query {
int x, y, z, i;
void scan(int idx) {
i = idx;
cin >> x >> y >> z;
}
bool operator<(const query &p) const {
return z < p.z;
}
} qs[100000];
int ans[100000];
pii ps[100000];
struct fenwick1D {
vector<int> comp, seg;
void add(int x) {
comp.push_back(x);
}
void init() {
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
seg.resize(comp.size(), 0);
}
void update(int i) {
i = lower_bound(comp.begin(), comp.end(), i + 1) - comp.begin();
while (i <= comp.size()) {
++seg[i - 1];
i += i & -i;
}
}
int query(int i) {
i = lower_bound(comp.begin(), comp.end(), i + 1) - comp.begin();
int ret = 0;
while (i) {
ret += seg[i - 1];
i -= i & -i;
}
return ret;
}
};
struct fenwick2D {
vector<int> comp;
vector<fenwick1D> seg;
void add1(int x) {
comp.push_back(x);
}
void init1() {
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
seg.resize(comp.size());
}
void add2(int i, int x) {
i = lower_bound(comp.begin(), comp.end(), i) - comp.begin() + 1;
while (i <= comp.size()) {
seg[i - 1].add(x);
i += i & -i;
}
}
void init2() {
for (auto &i : seg) i.init();
}
void update(int i, int j) {
i = lower_bound(comp.begin(), comp.end(), i + 1) - comp.begin();
while (i <= comp.size()) {
seg[i - 1].update(j);
i += i & -i;
}
}
int query(int i, int j) {
i = lower_bound(comp.begin(), comp.end(), i + 1) - comp.begin();
int ret = 0;
while (i) {
ret += seg[i - 1].query(j);
i -= i & -i;
}
return ret;
}
} seg;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
ps[i] = pii(x, y);
seg.add1(inf - x);
}
seg.init1();
for (int i = 0; i < n; ++i) seg.add2(inf - ps[i].fs, inf - ps[i].se);
seg.init2();
sort(ps, ps + n, [&](pii x, pii y) {
return x.fs + x.se < y.fs + y.se;
});
for (int i = 0; i < q; ++i) qs[i].scan(i);
sort(qs, qs + q);
for (int i = q, j = n - 1; i--; ) {
while (0 <= j && qs[i].z <= ps[j].fs + ps[j].se)
seg.update(inf - ps[j].fs, inf - ps[j].se), --j;
ans[qs[i].i] = seg.query(inf - qs[i].x, inf - qs[i].y);
}
for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
return 0;
}
Compilation message
examination.cpp: In member function 'void fenwick1D::update(int)':
examination.cpp:36:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (i <= comp.size()) {
~~^~~~~~~~~~~~~~
examination.cpp: In member function 'void fenwick2D::add2(int, int)':
examination.cpp:65:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (i <= comp.size()) {
~~^~~~~~~~~~~~~~
examination.cpp: In member function 'void fenwick2D::update(int, int)':
examination.cpp:75:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (i <= comp.size()) {
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
10 ms |
1024 KB |
Output is correct |
8 |
Correct |
9 ms |
1024 KB |
Output is correct |
9 |
Correct |
27 ms |
1152 KB |
Output is correct |
10 |
Correct |
7 ms |
1024 KB |
Output is correct |
11 |
Correct |
8 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
11 ms |
1024 KB |
Output is correct |
14 |
Correct |
8 ms |
1024 KB |
Output is correct |
15 |
Correct |
8 ms |
1024 KB |
Output is correct |
16 |
Correct |
4 ms |
640 KB |
Output is correct |
17 |
Correct |
6 ms |
1024 KB |
Output is correct |
18 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
434 ms |
18984 KB |
Output is correct |
2 |
Correct |
416 ms |
19132 KB |
Output is correct |
3 |
Correct |
421 ms |
19188 KB |
Output is correct |
4 |
Correct |
220 ms |
15988 KB |
Output is correct |
5 |
Correct |
124 ms |
7692 KB |
Output is correct |
6 |
Correct |
67 ms |
6516 KB |
Output is correct |
7 |
Correct |
388 ms |
19076 KB |
Output is correct |
8 |
Correct |
377 ms |
19056 KB |
Output is correct |
9 |
Correct |
349 ms |
18804 KB |
Output is correct |
10 |
Correct |
80 ms |
6252 KB |
Output is correct |
11 |
Correct |
176 ms |
15732 KB |
Output is correct |
12 |
Correct |
45 ms |
5232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
434 ms |
18984 KB |
Output is correct |
2 |
Correct |
416 ms |
19132 KB |
Output is correct |
3 |
Correct |
421 ms |
19188 KB |
Output is correct |
4 |
Correct |
220 ms |
15988 KB |
Output is correct |
5 |
Correct |
124 ms |
7692 KB |
Output is correct |
6 |
Correct |
67 ms |
6516 KB |
Output is correct |
7 |
Correct |
388 ms |
19076 KB |
Output is correct |
8 |
Correct |
377 ms |
19056 KB |
Output is correct |
9 |
Correct |
349 ms |
18804 KB |
Output is correct |
10 |
Correct |
80 ms |
6252 KB |
Output is correct |
11 |
Correct |
176 ms |
15732 KB |
Output is correct |
12 |
Correct |
45 ms |
5232 KB |
Output is correct |
13 |
Correct |
461 ms |
19544 KB |
Output is correct |
14 |
Correct |
496 ms |
19696 KB |
Output is correct |
15 |
Correct |
481 ms |
19188 KB |
Output is correct |
16 |
Correct |
243 ms |
16500 KB |
Output is correct |
17 |
Correct |
130 ms |
8284 KB |
Output is correct |
18 |
Correct |
84 ms |
6516 KB |
Output is correct |
19 |
Correct |
441 ms |
19500 KB |
Output is correct |
20 |
Correct |
427 ms |
19572 KB |
Output is correct |
21 |
Correct |
417 ms |
19532 KB |
Output is correct |
22 |
Correct |
81 ms |
6260 KB |
Output is correct |
23 |
Correct |
213 ms |
15788 KB |
Output is correct |
24 |
Correct |
54 ms |
5236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
10 ms |
1024 KB |
Output is correct |
8 |
Correct |
9 ms |
1024 KB |
Output is correct |
9 |
Correct |
27 ms |
1152 KB |
Output is correct |
10 |
Correct |
7 ms |
1024 KB |
Output is correct |
11 |
Correct |
8 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
11 ms |
1024 KB |
Output is correct |
14 |
Correct |
8 ms |
1024 KB |
Output is correct |
15 |
Correct |
8 ms |
1024 KB |
Output is correct |
16 |
Correct |
4 ms |
640 KB |
Output is correct |
17 |
Correct |
6 ms |
1024 KB |
Output is correct |
18 |
Correct |
4 ms |
512 KB |
Output is correct |
19 |
Correct |
434 ms |
18984 KB |
Output is correct |
20 |
Correct |
416 ms |
19132 KB |
Output is correct |
21 |
Correct |
421 ms |
19188 KB |
Output is correct |
22 |
Correct |
220 ms |
15988 KB |
Output is correct |
23 |
Correct |
124 ms |
7692 KB |
Output is correct |
24 |
Correct |
67 ms |
6516 KB |
Output is correct |
25 |
Correct |
388 ms |
19076 KB |
Output is correct |
26 |
Correct |
377 ms |
19056 KB |
Output is correct |
27 |
Correct |
349 ms |
18804 KB |
Output is correct |
28 |
Correct |
80 ms |
6252 KB |
Output is correct |
29 |
Correct |
176 ms |
15732 KB |
Output is correct |
30 |
Correct |
45 ms |
5232 KB |
Output is correct |
31 |
Correct |
461 ms |
19544 KB |
Output is correct |
32 |
Correct |
496 ms |
19696 KB |
Output is correct |
33 |
Correct |
481 ms |
19188 KB |
Output is correct |
34 |
Correct |
243 ms |
16500 KB |
Output is correct |
35 |
Correct |
130 ms |
8284 KB |
Output is correct |
36 |
Correct |
84 ms |
6516 KB |
Output is correct |
37 |
Correct |
441 ms |
19500 KB |
Output is correct |
38 |
Correct |
427 ms |
19572 KB |
Output is correct |
39 |
Correct |
417 ms |
19532 KB |
Output is correct |
40 |
Correct |
81 ms |
6260 KB |
Output is correct |
41 |
Correct |
213 ms |
15788 KB |
Output is correct |
42 |
Correct |
54 ms |
5236 KB |
Output is correct |
43 |
Correct |
557 ms |
25652 KB |
Output is correct |
44 |
Correct |
569 ms |
25332 KB |
Output is correct |
45 |
Correct |
585 ms |
25264 KB |
Output is correct |
46 |
Correct |
272 ms |
21492 KB |
Output is correct |
47 |
Correct |
166 ms |
9588 KB |
Output is correct |
48 |
Correct |
69 ms |
6384 KB |
Output is correct |
49 |
Correct |
470 ms |
25292 KB |
Output is correct |
50 |
Correct |
475 ms |
25332 KB |
Output is correct |
51 |
Correct |
511 ms |
25204 KB |
Output is correct |
52 |
Correct |
96 ms |
8052 KB |
Output is correct |
53 |
Correct |
219 ms |
20340 KB |
Output is correct |