#include<cstdio>
#include<vector>
#include <algorithm>
#include<utility>
constexpr int maxn = 1e5+10, B = 1000, maxB = 110; // block sz
struct BIT
{
int bit[maxB][maxn], n; // x, y
void upd(int x, int y) {
// puts("A");
for(int i = x+1; i < maxB; i += i&-i)
for(int j = y; j < maxn; j += j&-j)
bit[i][j]++;
// puts("B");
}
int query(int x, int y) {
int ans = 0;
for(int i = x+1; i > 0; i -= i&-i)
for(int j = y; j > 0; j -= j&-j)
ans += bit[i][j];
return ans;
}
} bit;
struct Query
{
int x, y, z, id;
Query(int a, int b, int c, int sla) : x(a), y(b), z(c), id(sla) {}
Query() {}
} queries[maxn];
struct Pt
{
int x, y, sum;
Pt(int a, int b) : x(a), y(b), sum(a+b) {}
Pt() {}
} a[maxn];
std::vector<std::pair<int,int>> comp[2]; // comprimir x e y
std::vector<Pt> bloco[maxB];
int ans[maxn];
int main() {
int n, q; scanf("%d %d", &n, &q);
for(int i = 0, x, y; i < n; i++) {
scanf("%d %d", &x, &y);
a[i] = Pt(x, y);
comp[0].push_back({x, i});
comp[1].push_back({y, i});
}
std::sort(comp[0].begin(), comp[0].end());
std::sort(comp[1].begin(), comp[1].end());
for(int i = 0; i < q; i++) {
int x, y, z; scanf("%d %d %d", &x, &y, &z);
auto l = lower_bound(comp[0].begin(), comp[0].end(), std::pair<int,int>(x, -1));
x = (int)(l - comp[0].begin() + 1);
l = lower_bound(comp[1].begin(), comp[1].end(), std::pair<int,int>(y, -1));
y = (int)(l - comp[1].begin() + 1);
queries[i] = Query(x, y, z, i);
// printf("%d %d %d\n", x, y, z);
}
for(int i = 0; i < (int)comp[0].size(); i++)
a[comp[0][i].second].x = i+1;
for(int i = 0; i < (int)comp[1].size(); i++)
a[comp[1][i].second].y = i+1;
std::sort(a, a+n, [](Pt x, Pt y){ return x.sum > y.sum; });
std::sort(queries, queries+q, [](Query x, Query y){ return x.z > y.z; });
for(int i = 0, ptr = 0; i < q; i++) {
for(; ptr < n && a[ptr].sum >= queries[i].z; ptr++)
bit.upd(a[ptr].x / B, a[ptr].y), bloco[a[ptr].x / B].push_back(a[ptr]);
// query na bit
ans[queries[i].id] = ptr + bit.query((queries[i].x / B), queries[i].y-1)
- bit.query(maxB - 2, queries[i].y-1) - bit.query((queries[i].x / B), maxn-1);
// // brute no meu block (tem <= 100 elementos)
for(Pt x : bloco[queries[i].x / B])
if(x.x >= queries[i].x && x.y >= queries[i].y) ++ans[queries[i].id];
}
for(int i = 0; i < q; i++)
printf("%d\n", ans[i]);
// debug
// for(int i = 0; i < n; i++)
// printf("%d %d %d\n", a[i].x, a[i].y, a[i].sum);
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:47:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
47 | int n, q; scanf("%d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
49 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:57:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
57 | int x, y, z; scanf("%d %d %d", &x, &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
10 ms |
1004 KB |
Output is correct |
8 |
Correct |
10 ms |
1004 KB |
Output is correct |
9 |
Correct |
10 ms |
1004 KB |
Output is correct |
10 |
Correct |
10 ms |
1004 KB |
Output is correct |
11 |
Correct |
8 ms |
1004 KB |
Output is correct |
12 |
Correct |
8 ms |
876 KB |
Output is correct |
13 |
Correct |
14 ms |
1004 KB |
Output is correct |
14 |
Correct |
14 ms |
1004 KB |
Output is correct |
15 |
Correct |
14 ms |
1004 KB |
Output is correct |
16 |
Correct |
7 ms |
1004 KB |
Output is correct |
17 |
Correct |
7 ms |
1004 KB |
Output is correct |
18 |
Correct |
4 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
474 ms |
49028 KB |
Output is correct |
2 |
Correct |
474 ms |
49112 KB |
Output is correct |
3 |
Correct |
471 ms |
49112 KB |
Output is correct |
4 |
Correct |
574 ms |
48216 KB |
Output is correct |
5 |
Correct |
373 ms |
48344 KB |
Output is correct |
6 |
Correct |
337 ms |
30492 KB |
Output is correct |
7 |
Correct |
435 ms |
48872 KB |
Output is correct |
8 |
Correct |
580 ms |
48984 KB |
Output is correct |
9 |
Correct |
540 ms |
48852 KB |
Output is correct |
10 |
Correct |
243 ms |
48092 KB |
Output is correct |
11 |
Correct |
285 ms |
48088 KB |
Output is correct |
12 |
Correct |
129 ms |
10712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
474 ms |
49028 KB |
Output is correct |
2 |
Correct |
474 ms |
49112 KB |
Output is correct |
3 |
Correct |
471 ms |
49112 KB |
Output is correct |
4 |
Correct |
574 ms |
48216 KB |
Output is correct |
5 |
Correct |
373 ms |
48344 KB |
Output is correct |
6 |
Correct |
337 ms |
30492 KB |
Output is correct |
7 |
Correct |
435 ms |
48872 KB |
Output is correct |
8 |
Correct |
580 ms |
48984 KB |
Output is correct |
9 |
Correct |
540 ms |
48852 KB |
Output is correct |
10 |
Correct |
243 ms |
48092 KB |
Output is correct |
11 |
Correct |
285 ms |
48088 KB |
Output is correct |
12 |
Correct |
129 ms |
10712 KB |
Output is correct |
13 |
Correct |
377 ms |
49608 KB |
Output is correct |
14 |
Correct |
458 ms |
49312 KB |
Output is correct |
15 |
Correct |
492 ms |
49112 KB |
Output is correct |
16 |
Correct |
392 ms |
48600 KB |
Output is correct |
17 |
Correct |
311 ms |
48764 KB |
Output is correct |
18 |
Correct |
330 ms |
30296 KB |
Output is correct |
19 |
Correct |
376 ms |
49496 KB |
Output is correct |
20 |
Correct |
422 ms |
49496 KB |
Output is correct |
21 |
Correct |
337 ms |
49368 KB |
Output is correct |
22 |
Correct |
239 ms |
48088 KB |
Output is correct |
23 |
Correct |
293 ms |
47976 KB |
Output is correct |
24 |
Correct |
127 ms |
10712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
10 ms |
1004 KB |
Output is correct |
8 |
Correct |
10 ms |
1004 KB |
Output is correct |
9 |
Correct |
10 ms |
1004 KB |
Output is correct |
10 |
Correct |
10 ms |
1004 KB |
Output is correct |
11 |
Correct |
8 ms |
1004 KB |
Output is correct |
12 |
Correct |
8 ms |
876 KB |
Output is correct |
13 |
Correct |
14 ms |
1004 KB |
Output is correct |
14 |
Correct |
14 ms |
1004 KB |
Output is correct |
15 |
Correct |
14 ms |
1004 KB |
Output is correct |
16 |
Correct |
7 ms |
1004 KB |
Output is correct |
17 |
Correct |
7 ms |
1004 KB |
Output is correct |
18 |
Correct |
4 ms |
876 KB |
Output is correct |
19 |
Correct |
474 ms |
49028 KB |
Output is correct |
20 |
Correct |
474 ms |
49112 KB |
Output is correct |
21 |
Correct |
471 ms |
49112 KB |
Output is correct |
22 |
Correct |
574 ms |
48216 KB |
Output is correct |
23 |
Correct |
373 ms |
48344 KB |
Output is correct |
24 |
Correct |
337 ms |
30492 KB |
Output is correct |
25 |
Correct |
435 ms |
48872 KB |
Output is correct |
26 |
Correct |
580 ms |
48984 KB |
Output is correct |
27 |
Correct |
540 ms |
48852 KB |
Output is correct |
28 |
Correct |
243 ms |
48092 KB |
Output is correct |
29 |
Correct |
285 ms |
48088 KB |
Output is correct |
30 |
Correct |
129 ms |
10712 KB |
Output is correct |
31 |
Correct |
377 ms |
49608 KB |
Output is correct |
32 |
Correct |
458 ms |
49312 KB |
Output is correct |
33 |
Correct |
492 ms |
49112 KB |
Output is correct |
34 |
Correct |
392 ms |
48600 KB |
Output is correct |
35 |
Correct |
311 ms |
48764 KB |
Output is correct |
36 |
Correct |
330 ms |
30296 KB |
Output is correct |
37 |
Correct |
376 ms |
49496 KB |
Output is correct |
38 |
Correct |
422 ms |
49496 KB |
Output is correct |
39 |
Correct |
337 ms |
49368 KB |
Output is correct |
40 |
Correct |
239 ms |
48088 KB |
Output is correct |
41 |
Correct |
293 ms |
47976 KB |
Output is correct |
42 |
Correct |
127 ms |
10712 KB |
Output is correct |
43 |
Correct |
388 ms |
51420 KB |
Output is correct |
44 |
Correct |
381 ms |
51288 KB |
Output is correct |
45 |
Correct |
502 ms |
51288 KB |
Output is correct |
46 |
Correct |
399 ms |
49752 KB |
Output is correct |
47 |
Correct |
323 ms |
50044 KB |
Output is correct |
48 |
Correct |
178 ms |
30168 KB |
Output is correct |
49 |
Correct |
363 ms |
51416 KB |
Output is correct |
50 |
Correct |
408 ms |
51160 KB |
Output is correct |
51 |
Correct |
390 ms |
51160 KB |
Output is correct |
52 |
Correct |
226 ms |
49752 KB |
Output is correct |
53 |
Correct |
296 ms |
48728 KB |
Output is correct |