#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e5+5;
vector<int> coord[N], t[N];
void update(vector<int> &t, int x, int k) {
for(int i = x; i; i -= i & -i)
t[i] += k;
}
int query(vector<int> &t, int x) {
int ret = 0;
for(int i = x; i < t.size(); i += i & -i) ret += t[i];
return ret;
}
void update_2d(int x, int y, int k) {
for(int i = x; i; i -= i & -i) {
int idx = lower_bound(coord[i].begin(), coord[i].end(), y) - coord[i].begin() + 1;
update(t[i], idx, k);
}
}
int query_2d(int x, int y) {
int ret = 0;
for(int i = x; i < N; i += i & -i) {
int idx = lower_bound(coord[i].begin(), coord[i].end(), y) - coord[i].begin() + 1;
ret += query(t[i], idx);
}
return ret;
}
struct Query {
int a, b, c, i;
Query(int a, int b, int c, int i) : a(a), b(b), c(c), i(i) {}
friend bool operator<(const Query &a, const Query &b) {
return a.c > b.c;
}
};
int n, q, ans[N];
vector<pii> st;
vector<Query> Q;
int main() {
scanf("%d %d", &n, &q);
vector<int> vec;
function<int(int)> get = [&](int x) { return lower_bound(vec.begin(), vec.end(), x) - vec.begin() + 1; };
for(int i = 1, a, b; i <= n; i++) {
scanf("%d %d", &a, &b);
st.emplace_back(a, b);
vec.emplace_back(a);
}
sort(vec.begin(), vec.end());
vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
for(pii p : st) for(int i = get(p.x); i; i -= i & -i) coord[i].emplace_back(p.y);
for(int i = 1; i < N; i++) {
sort(coord[i].begin(), coord[i].end());
coord[i].resize(unique(coord[i].begin(), coord[i].end()) - coord[i].begin());
t[i].resize(coord[i].size() + 5);
}
sort(st.begin(), st.end(), [&](pii &a, pii &b) {
return a.x + a.y > b.x + b.y;
});
for(int i = 1, a, b, c; i <= q; i++) {
scanf("%d %d %d", &a, &b, &c);
Q.emplace_back(a, b, c, i);
}
sort(Q.begin(), Q.end());
int ptr = 0;
for(Query &ask : Q) {
while(ptr < st.size() && st[ptr].x + st[ptr].y >= ask.c) {
update_2d(get(st[ptr].x), st[ptr].y, 1);
ptr++;
}
ans[ask.i] = query_2d(get(ask.a), ask.b);
}
for(int i = 1; i <= q; i++) printf("%d\n", ans[i]);
return 0;
}
Compilation message
examination.cpp: In function 'int query(std::vector<int>&, int)':
examination.cpp:20:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = x; i < t.size(); i += i & -i) ret += t[i];
~~^~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:83:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ptr < st.size() && st[ptr].x + st[ptr].y >= ask.c) {
~~~~^~~~~~~~~~~
examination.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &a, &b, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
8184 KB |
Output is correct |
2 |
Correct |
14 ms |
8184 KB |
Output is correct |
3 |
Correct |
14 ms |
8184 KB |
Output is correct |
4 |
Correct |
13 ms |
8184 KB |
Output is correct |
5 |
Correct |
15 ms |
8216 KB |
Output is correct |
6 |
Correct |
14 ms |
8184 KB |
Output is correct |
7 |
Correct |
22 ms |
8696 KB |
Output is correct |
8 |
Correct |
22 ms |
8696 KB |
Output is correct |
9 |
Correct |
22 ms |
8696 KB |
Output is correct |
10 |
Correct |
20 ms |
8568 KB |
Output is correct |
11 |
Correct |
19 ms |
8440 KB |
Output is correct |
12 |
Correct |
17 ms |
8440 KB |
Output is correct |
13 |
Correct |
22 ms |
8696 KB |
Output is correct |
14 |
Correct |
21 ms |
8696 KB |
Output is correct |
15 |
Correct |
21 ms |
8696 KB |
Output is correct |
16 |
Correct |
18 ms |
8440 KB |
Output is correct |
17 |
Correct |
19 ms |
8564 KB |
Output is correct |
18 |
Correct |
17 ms |
8440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
448 ms |
22676 KB |
Output is correct |
2 |
Correct |
452 ms |
22760 KB |
Output is correct |
3 |
Correct |
443 ms |
22676 KB |
Output is correct |
4 |
Correct |
239 ms |
19692 KB |
Output is correct |
5 |
Correct |
181 ms |
15460 KB |
Output is correct |
6 |
Correct |
110 ms |
14044 KB |
Output is correct |
7 |
Correct |
404 ms |
22624 KB |
Output is correct |
8 |
Correct |
415 ms |
22740 KB |
Output is correct |
9 |
Correct |
389 ms |
22624 KB |
Output is correct |
10 |
Correct |
128 ms |
14184 KB |
Output is correct |
11 |
Correct |
205 ms |
18660 KB |
Output is correct |
12 |
Correct |
91 ms |
13028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
448 ms |
22676 KB |
Output is correct |
2 |
Correct |
452 ms |
22760 KB |
Output is correct |
3 |
Correct |
443 ms |
22676 KB |
Output is correct |
4 |
Correct |
239 ms |
19692 KB |
Output is correct |
5 |
Correct |
181 ms |
15460 KB |
Output is correct |
6 |
Correct |
110 ms |
14044 KB |
Output is correct |
7 |
Correct |
404 ms |
22624 KB |
Output is correct |
8 |
Correct |
415 ms |
22740 KB |
Output is correct |
9 |
Correct |
389 ms |
22624 KB |
Output is correct |
10 |
Correct |
128 ms |
14184 KB |
Output is correct |
11 |
Correct |
205 ms |
18660 KB |
Output is correct |
12 |
Correct |
91 ms |
13028 KB |
Output is correct |
13 |
Correct |
481 ms |
23144 KB |
Output is correct |
14 |
Correct |
463 ms |
23144 KB |
Output is correct |
15 |
Correct |
445 ms |
22756 KB |
Output is correct |
16 |
Correct |
259 ms |
20200 KB |
Output is correct |
17 |
Correct |
194 ms |
15716 KB |
Output is correct |
18 |
Correct |
122 ms |
13968 KB |
Output is correct |
19 |
Correct |
464 ms |
23140 KB |
Output is correct |
20 |
Correct |
464 ms |
23096 KB |
Output is correct |
21 |
Correct |
462 ms |
23140 KB |
Output is correct |
22 |
Correct |
129 ms |
14180 KB |
Output is correct |
23 |
Correct |
211 ms |
18656 KB |
Output is correct |
24 |
Correct |
92 ms |
13032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
8184 KB |
Output is correct |
2 |
Correct |
14 ms |
8184 KB |
Output is correct |
3 |
Correct |
14 ms |
8184 KB |
Output is correct |
4 |
Correct |
13 ms |
8184 KB |
Output is correct |
5 |
Correct |
15 ms |
8216 KB |
Output is correct |
6 |
Correct |
14 ms |
8184 KB |
Output is correct |
7 |
Correct |
22 ms |
8696 KB |
Output is correct |
8 |
Correct |
22 ms |
8696 KB |
Output is correct |
9 |
Correct |
22 ms |
8696 KB |
Output is correct |
10 |
Correct |
20 ms |
8568 KB |
Output is correct |
11 |
Correct |
19 ms |
8440 KB |
Output is correct |
12 |
Correct |
17 ms |
8440 KB |
Output is correct |
13 |
Correct |
22 ms |
8696 KB |
Output is correct |
14 |
Correct |
21 ms |
8696 KB |
Output is correct |
15 |
Correct |
21 ms |
8696 KB |
Output is correct |
16 |
Correct |
18 ms |
8440 KB |
Output is correct |
17 |
Correct |
19 ms |
8564 KB |
Output is correct |
18 |
Correct |
17 ms |
8440 KB |
Output is correct |
19 |
Correct |
448 ms |
22676 KB |
Output is correct |
20 |
Correct |
452 ms |
22760 KB |
Output is correct |
21 |
Correct |
443 ms |
22676 KB |
Output is correct |
22 |
Correct |
239 ms |
19692 KB |
Output is correct |
23 |
Correct |
181 ms |
15460 KB |
Output is correct |
24 |
Correct |
110 ms |
14044 KB |
Output is correct |
25 |
Correct |
404 ms |
22624 KB |
Output is correct |
26 |
Correct |
415 ms |
22740 KB |
Output is correct |
27 |
Correct |
389 ms |
22624 KB |
Output is correct |
28 |
Correct |
128 ms |
14184 KB |
Output is correct |
29 |
Correct |
205 ms |
18660 KB |
Output is correct |
30 |
Correct |
91 ms |
13028 KB |
Output is correct |
31 |
Correct |
481 ms |
23144 KB |
Output is correct |
32 |
Correct |
463 ms |
23144 KB |
Output is correct |
33 |
Correct |
445 ms |
22756 KB |
Output is correct |
34 |
Correct |
259 ms |
20200 KB |
Output is correct |
35 |
Correct |
194 ms |
15716 KB |
Output is correct |
36 |
Correct |
122 ms |
13968 KB |
Output is correct |
37 |
Correct |
464 ms |
23140 KB |
Output is correct |
38 |
Correct |
464 ms |
23096 KB |
Output is correct |
39 |
Correct |
462 ms |
23140 KB |
Output is correct |
40 |
Correct |
129 ms |
14180 KB |
Output is correct |
41 |
Correct |
211 ms |
18656 KB |
Output is correct |
42 |
Correct |
92 ms |
13032 KB |
Output is correct |
43 |
Correct |
523 ms |
24680 KB |
Output is correct |
44 |
Correct |
525 ms |
24804 KB |
Output is correct |
45 |
Correct |
516 ms |
24552 KB |
Output is correct |
46 |
Correct |
293 ms |
21912 KB |
Output is correct |
47 |
Correct |
203 ms |
16996 KB |
Output is correct |
48 |
Correct |
117 ms |
13796 KB |
Output is correct |
49 |
Correct |
498 ms |
24548 KB |
Output is correct |
50 |
Correct |
485 ms |
24548 KB |
Output is correct |
51 |
Correct |
461 ms |
24536 KB |
Output is correct |
52 |
Correct |
156 ms |
15848 KB |
Output is correct |
53 |
Correct |
235 ms |
20072 KB |
Output is correct |