#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int S = 320;
struct BIT
{
int bit[S][N];
void update(int x, int y) {
for (int i = x; i > 0; i -= i & -i) {
for (int j = y; j > 0; j -= j & -j) {
bit[i][j]++;
}
}
}
int query(int x, int y) {
int ret = 0;
for (int i = x; i < S; i += i & -i) {
for (int j = y; j < N; j += j & -j) {
ret += bit[i][j];
}
}
return ret;
}
} bit;
struct Query
{
int x, y, z, id;
Query() {}
Query(int _x, int _y, int _z, int _id): x(_x), y(_y), z(_z), id(_id) {}
bool operator<(Query other) {
return z > other.z;
}
} q[N];
struct Aluno
{
int a, b, soma;
Aluno() {}
Aluno(int _a, int _b): a(_a), b(_b), soma(_a + _b) {}
bool operator<(Aluno other) {
return soma > other.soma;
}
} a[N];
vector<pair<int, int>> cmp[2];
vector<Aluno> bloco[S];
int ans[N];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
int s, t;
scanf("%d %d", &s, &t);
a[i] = Aluno(s, t);
cmp[0].emplace_back(s, i);
cmp[1].emplace_back(t, i);
}
// comprime s e t
for (int i : {0, 1}) {
sort(cmp[i].begin(), cmp[i].end());
}
// conserta os ranges das queries
for (int i = 0; i < m; i++) {
int x, y, z;
cin >> x >> y >> z;
auto it = lower_bound(cmp[0].begin(), cmp[0].end(), make_pair(x, -1));
x = (int) (it - cmp[0].begin()) + 1;
it = lower_bound(cmp[1].begin(), cmp[1].end(), make_pair(y, -1));
y = (int) (it - cmp[1].begin()) + 1;
q[i] = Query(x, y, z, i);
}
// comprime de verdade
for (int i = 0; i < (int) cmp[0].size(); i++) {
a[cmp[0][i].second].a = i + 1;
}
for (int i = 0; i < (int) cmp[1].size(); i++) {
a[cmp[1][i].second].b = i + 1;
}
// ordeno os alunos pela soma pra sempre pegar um prefixo do array
sort(a, a + n);
sort(q, q + n);
int ptr = 0;
for (int i = 0; i < m; i++) {
for (; ptr < n && a[ptr].soma >= q[i].z; ptr++) {
bit.update(a[ptr].a / S, a[ptr].b); // bloco do a, valor do b
bloco[a[ptr].a / S].push_back(a[ptr]);
}
// com certeza todos os "eventos" com soma >= q[i].z ja foram processados
// faz uma query de sufixo nos blocos de A > q[i].x e nos valores de B >= q[i].y
ans[q[i].id] = bit.query(q[i].x / S + 1, q[i].y);
for (auto cara : bloco[q[i].x / S]) {
ans[q[i].id] += (cara.a >= q[i].x && cara.b >= q[i].y);
}
}
for (int i = 0; i < m; i++) {
printf("%d\n", ans[i]);
}
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
56 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
59 | scanf("%d %d", &s, &t);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
8 ms |
748 KB |
Output is correct |
8 |
Correct |
9 ms |
876 KB |
Output is correct |
9 |
Correct |
9 ms |
876 KB |
Output is correct |
10 |
Correct |
7 ms |
876 KB |
Output is correct |
11 |
Correct |
7 ms |
876 KB |
Output is correct |
12 |
Correct |
6 ms |
940 KB |
Output is correct |
13 |
Correct |
8 ms |
920 KB |
Output is correct |
14 |
Correct |
11 ms |
876 KB |
Output is correct |
15 |
Correct |
9 ms |
924 KB |
Output is correct |
16 |
Correct |
7 ms |
876 KB |
Output is correct |
17 |
Correct |
9 ms |
992 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
365 ms |
129388 KB |
Output is correct |
2 |
Correct |
367 ms |
132032 KB |
Output is correct |
3 |
Correct |
366 ms |
131956 KB |
Output is correct |
4 |
Correct |
314 ms |
131096 KB |
Output is correct |
5 |
Correct |
337 ms |
131288 KB |
Output is correct |
6 |
Correct |
218 ms |
60888 KB |
Output is correct |
7 |
Correct |
337 ms |
131800 KB |
Output is correct |
8 |
Correct |
349 ms |
131800 KB |
Output is correct |
9 |
Correct |
302 ms |
131812 KB |
Output is correct |
10 |
Correct |
288 ms |
131288 KB |
Output is correct |
11 |
Correct |
319 ms |
130808 KB |
Output is correct |
12 |
Correct |
138 ms |
14424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
365 ms |
129388 KB |
Output is correct |
2 |
Correct |
367 ms |
132032 KB |
Output is correct |
3 |
Correct |
366 ms |
131956 KB |
Output is correct |
4 |
Correct |
314 ms |
131096 KB |
Output is correct |
5 |
Correct |
337 ms |
131288 KB |
Output is correct |
6 |
Correct |
218 ms |
60888 KB |
Output is correct |
7 |
Correct |
337 ms |
131800 KB |
Output is correct |
8 |
Correct |
349 ms |
131800 KB |
Output is correct |
9 |
Correct |
302 ms |
131812 KB |
Output is correct |
10 |
Correct |
288 ms |
131288 KB |
Output is correct |
11 |
Correct |
319 ms |
130808 KB |
Output is correct |
12 |
Correct |
138 ms |
14424 KB |
Output is correct |
13 |
Correct |
412 ms |
132288 KB |
Output is correct |
14 |
Correct |
390 ms |
132184 KB |
Output is correct |
15 |
Correct |
351 ms |
132100 KB |
Output is correct |
16 |
Correct |
319 ms |
131420 KB |
Output is correct |
17 |
Correct |
327 ms |
131672 KB |
Output is correct |
18 |
Correct |
209 ms |
61144 KB |
Output is correct |
19 |
Correct |
384 ms |
132312 KB |
Output is correct |
20 |
Correct |
400 ms |
132372 KB |
Output is correct |
21 |
Correct |
337 ms |
132316 KB |
Output is correct |
22 |
Correct |
282 ms |
131084 KB |
Output is correct |
23 |
Correct |
287 ms |
130776 KB |
Output is correct |
24 |
Correct |
142 ms |
14424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
8 ms |
748 KB |
Output is correct |
8 |
Correct |
9 ms |
876 KB |
Output is correct |
9 |
Correct |
9 ms |
876 KB |
Output is correct |
10 |
Correct |
7 ms |
876 KB |
Output is correct |
11 |
Correct |
7 ms |
876 KB |
Output is correct |
12 |
Correct |
6 ms |
940 KB |
Output is correct |
13 |
Correct |
8 ms |
920 KB |
Output is correct |
14 |
Correct |
11 ms |
876 KB |
Output is correct |
15 |
Correct |
9 ms |
924 KB |
Output is correct |
16 |
Correct |
7 ms |
876 KB |
Output is correct |
17 |
Correct |
9 ms |
992 KB |
Output is correct |
18 |
Correct |
4 ms |
748 KB |
Output is correct |
19 |
Correct |
365 ms |
129388 KB |
Output is correct |
20 |
Correct |
367 ms |
132032 KB |
Output is correct |
21 |
Correct |
366 ms |
131956 KB |
Output is correct |
22 |
Correct |
314 ms |
131096 KB |
Output is correct |
23 |
Correct |
337 ms |
131288 KB |
Output is correct |
24 |
Correct |
218 ms |
60888 KB |
Output is correct |
25 |
Correct |
337 ms |
131800 KB |
Output is correct |
26 |
Correct |
349 ms |
131800 KB |
Output is correct |
27 |
Correct |
302 ms |
131812 KB |
Output is correct |
28 |
Correct |
288 ms |
131288 KB |
Output is correct |
29 |
Correct |
319 ms |
130808 KB |
Output is correct |
30 |
Correct |
138 ms |
14424 KB |
Output is correct |
31 |
Correct |
412 ms |
132288 KB |
Output is correct |
32 |
Correct |
390 ms |
132184 KB |
Output is correct |
33 |
Correct |
351 ms |
132100 KB |
Output is correct |
34 |
Correct |
319 ms |
131420 KB |
Output is correct |
35 |
Correct |
327 ms |
131672 KB |
Output is correct |
36 |
Correct |
209 ms |
61144 KB |
Output is correct |
37 |
Correct |
384 ms |
132312 KB |
Output is correct |
38 |
Correct |
400 ms |
132372 KB |
Output is correct |
39 |
Correct |
337 ms |
132316 KB |
Output is correct |
40 |
Correct |
282 ms |
131084 KB |
Output is correct |
41 |
Correct |
287 ms |
130776 KB |
Output is correct |
42 |
Correct |
142 ms |
14424 KB |
Output is correct |
43 |
Correct |
429 ms |
133336 KB |
Output is correct |
44 |
Correct |
439 ms |
133356 KB |
Output is correct |
45 |
Correct |
449 ms |
133360 KB |
Output is correct |
46 |
Correct |
359 ms |
132604 KB |
Output is correct |
47 |
Correct |
363 ms |
132876 KB |
Output is correct |
48 |
Correct |
213 ms |
60880 KB |
Output is correct |
49 |
Correct |
474 ms |
133464 KB |
Output is correct |
50 |
Correct |
382 ms |
133352 KB |
Output is correct |
51 |
Correct |
363 ms |
133436 KB |
Output is correct |
52 |
Correct |
322 ms |
132736 KB |
Output is correct |
53 |
Correct |
296 ms |
131648 KB |
Output is correct |