#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#define f first
#define s second
using namespace std;
const int sz = sqrt(1e5);
int n, test, cur = 1, ans[100010], l, r, mid, pos;
pair<int,int> a[100010], b[100010], grp[100010];
vector<vector<int>> v, vv;
pair<pair<int,int>,pair<int,int>> query[100010];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> test;
for (int i = 1; i <= n; i++) cin >> a[i].f >> a[i].s;
sort(a+1,a+n+1);
for (int i = 1; i <= n; i++) b[i] = {a[i].f+a[i].s,i};
sort(b+1,b+n+1,greater<pair<int,int>>());
for (int i = 1; i <= test; i++) {
cin >> query[i].s.f >> query[i].s.s >> query[i].f.f;
query[i].f.s = i;
}
sort(query+1,query+test+1,greater<pair<pair<int,int>,pair<int,int>>>());
for (int i = 1; i <= n; i++) {
if (i%sz == 1) v.push_back({}), vv.push_back({});
v.back().push_back(-1);
vv.back().push_back(-1);
grp[i] = {v.size()-1,v.back().size()-1};
}
for (int i = 1; i <= test; i++) {
while ((cur <= n) && (b[cur].f >= query[i].f.f)) {
vv[grp[b[cur].s].f][grp[b[cur].s].s] = a[b[cur].s].s;
for (int j = 0; j < v[grp[b[cur].s].f].size(); j++) v[grp[b[cur].s].f][j] = vv[grp[b[cur].s].f][j];
sort(v[grp[b[cur].s].f].begin(),v[grp[b[cur].s].f].end());
cur++;
}
l = 1; r = n;
while (l <= r) {
mid = (l+r)/2;
if (a[mid].f >= query[i].s.f) r = mid-1;
else l = mid+1;
}
pos = l;
int cnt = 0;
if (l == n+1) continue;
for (int j = grp[pos].s; j < v[grp[pos].f].size(); j++) if (vv[grp[pos].f][j] >= query[i].s.s) cnt++;
for (int j = grp[pos].f+1; j < v.size(); j++) {
l = 0; r = v[j].size()-1;
while (l <= r) {
mid = (l+r)/2;
if (v[j][mid] < query[i].s.s) l = mid+1;
else r = mid-1;
}
cnt += v[j].size()-l;
}
ans[query[i].f.s] = cnt;
}
for (int i = 1; i <= test; i++) cout << ans[i] << "\n";
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int j = 0; j < v[grp[b[cur].s].f].size(); j++) v[grp[b[cur].s].f][j] = vv[grp[b[cur].s].f][j];
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:50:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int j = grp[pos].s; j < v[grp[pos].f].size(); j++) if (vv[grp[pos].f][j] >= query[i].s.s) cnt++;
| ~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:51:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int j = grp[pos].f+1; j < v.size(); j++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
20 ms |
4444 KB |
Output is correct |
8 |
Correct |
20 ms |
4444 KB |
Output is correct |
9 |
Correct |
19 ms |
4664 KB |
Output is correct |
10 |
Correct |
17 ms |
4660 KB |
Output is correct |
11 |
Correct |
21 ms |
4652 KB |
Output is correct |
12 |
Correct |
13 ms |
4440 KB |
Output is correct |
13 |
Correct |
19 ms |
4780 KB |
Output is correct |
14 |
Correct |
20 ms |
4696 KB |
Output is correct |
15 |
Correct |
19 ms |
4792 KB |
Output is correct |
16 |
Correct |
11 ms |
4752 KB |
Output is correct |
17 |
Correct |
11 ms |
4760 KB |
Output is correct |
18 |
Correct |
13 ms |
4688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1489 ms |
6532 KB |
Output is correct |
2 |
Correct |
1480 ms |
9036 KB |
Output is correct |
3 |
Correct |
1478 ms |
9304 KB |
Output is correct |
4 |
Correct |
1026 ms |
8288 KB |
Output is correct |
5 |
Correct |
638 ms |
8292 KB |
Output is correct |
6 |
Correct |
584 ms |
7764 KB |
Output is correct |
7 |
Correct |
2079 ms |
8960 KB |
Output is correct |
8 |
Correct |
1296 ms |
9040 KB |
Output is correct |
9 |
Correct |
1750 ms |
8864 KB |
Output is correct |
10 |
Correct |
538 ms |
8044 KB |
Output is correct |
11 |
Correct |
587 ms |
8020 KB |
Output is correct |
12 |
Correct |
518 ms |
7264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1489 ms |
6532 KB |
Output is correct |
2 |
Correct |
1480 ms |
9036 KB |
Output is correct |
3 |
Correct |
1478 ms |
9304 KB |
Output is correct |
4 |
Correct |
1026 ms |
8288 KB |
Output is correct |
5 |
Correct |
638 ms |
8292 KB |
Output is correct |
6 |
Correct |
584 ms |
7764 KB |
Output is correct |
7 |
Correct |
2079 ms |
8960 KB |
Output is correct |
8 |
Correct |
1296 ms |
9040 KB |
Output is correct |
9 |
Correct |
1750 ms |
8864 KB |
Output is correct |
10 |
Correct |
538 ms |
8044 KB |
Output is correct |
11 |
Correct |
587 ms |
8020 KB |
Output is correct |
12 |
Correct |
518 ms |
7264 KB |
Output is correct |
13 |
Correct |
1348 ms |
9424 KB |
Output is correct |
14 |
Correct |
1561 ms |
9440 KB |
Output is correct |
15 |
Correct |
1510 ms |
9288 KB |
Output is correct |
16 |
Correct |
999 ms |
8788 KB |
Output is correct |
17 |
Correct |
635 ms |
8700 KB |
Output is correct |
18 |
Correct |
614 ms |
7504 KB |
Output is correct |
19 |
Correct |
1351 ms |
9564 KB |
Output is correct |
20 |
Correct |
1438 ms |
9712 KB |
Output is correct |
21 |
Correct |
1472 ms |
9472 KB |
Output is correct |
22 |
Correct |
535 ms |
8020 KB |
Output is correct |
23 |
Correct |
558 ms |
8132 KB |
Output is correct |
24 |
Correct |
396 ms |
7028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
20 ms |
4444 KB |
Output is correct |
8 |
Correct |
20 ms |
4444 KB |
Output is correct |
9 |
Correct |
19 ms |
4664 KB |
Output is correct |
10 |
Correct |
17 ms |
4660 KB |
Output is correct |
11 |
Correct |
21 ms |
4652 KB |
Output is correct |
12 |
Correct |
13 ms |
4440 KB |
Output is correct |
13 |
Correct |
19 ms |
4780 KB |
Output is correct |
14 |
Correct |
20 ms |
4696 KB |
Output is correct |
15 |
Correct |
19 ms |
4792 KB |
Output is correct |
16 |
Correct |
11 ms |
4752 KB |
Output is correct |
17 |
Correct |
11 ms |
4760 KB |
Output is correct |
18 |
Correct |
13 ms |
4688 KB |
Output is correct |
19 |
Correct |
1489 ms |
6532 KB |
Output is correct |
20 |
Correct |
1480 ms |
9036 KB |
Output is correct |
21 |
Correct |
1478 ms |
9304 KB |
Output is correct |
22 |
Correct |
1026 ms |
8288 KB |
Output is correct |
23 |
Correct |
638 ms |
8292 KB |
Output is correct |
24 |
Correct |
584 ms |
7764 KB |
Output is correct |
25 |
Correct |
2079 ms |
8960 KB |
Output is correct |
26 |
Correct |
1296 ms |
9040 KB |
Output is correct |
27 |
Correct |
1750 ms |
8864 KB |
Output is correct |
28 |
Correct |
538 ms |
8044 KB |
Output is correct |
29 |
Correct |
587 ms |
8020 KB |
Output is correct |
30 |
Correct |
518 ms |
7264 KB |
Output is correct |
31 |
Correct |
1348 ms |
9424 KB |
Output is correct |
32 |
Correct |
1561 ms |
9440 KB |
Output is correct |
33 |
Correct |
1510 ms |
9288 KB |
Output is correct |
34 |
Correct |
999 ms |
8788 KB |
Output is correct |
35 |
Correct |
635 ms |
8700 KB |
Output is correct |
36 |
Correct |
614 ms |
7504 KB |
Output is correct |
37 |
Correct |
1351 ms |
9564 KB |
Output is correct |
38 |
Correct |
1438 ms |
9712 KB |
Output is correct |
39 |
Correct |
1472 ms |
9472 KB |
Output is correct |
40 |
Correct |
535 ms |
8020 KB |
Output is correct |
41 |
Correct |
558 ms |
8132 KB |
Output is correct |
42 |
Correct |
396 ms |
7028 KB |
Output is correct |
43 |
Correct |
1348 ms |
11448 KB |
Output is correct |
44 |
Correct |
1356 ms |
11456 KB |
Output is correct |
45 |
Correct |
1571 ms |
11288 KB |
Output is correct |
46 |
Correct |
1026 ms |
9868 KB |
Output is correct |
47 |
Correct |
671 ms |
9872 KB |
Output is correct |
48 |
Correct |
609 ms |
7396 KB |
Output is correct |
49 |
Correct |
2119 ms |
11296 KB |
Output is correct |
50 |
Correct |
1248 ms |
11352 KB |
Output is correct |
51 |
Correct |
1627 ms |
11196 KB |
Output is correct |
52 |
Correct |
594 ms |
9596 KB |
Output is correct |
53 |
Correct |
560 ms |
9104 KB |
Output is correct |