#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#define f first
#define s second
#define int long long
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 (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:38:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | 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:51:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | 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:52:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int j = grp[pos].f+1; j < v.size(); j++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6612 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
20 ms |
6748 KB |
Output is correct |
8 |
Correct |
21 ms |
6920 KB |
Output is correct |
9 |
Correct |
21 ms |
6748 KB |
Output is correct |
10 |
Correct |
17 ms |
6748 KB |
Output is correct |
11 |
Correct |
15 ms |
6892 KB |
Output is correct |
12 |
Runtime error |
694 ms |
13204 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1979 ms |
25152 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1979 ms |
25152 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6612 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
20 ms |
6748 KB |
Output is correct |
8 |
Correct |
21 ms |
6920 KB |
Output is correct |
9 |
Correct |
21 ms |
6748 KB |
Output is correct |
10 |
Correct |
17 ms |
6748 KB |
Output is correct |
11 |
Correct |
15 ms |
6892 KB |
Output is correct |
12 |
Runtime error |
694 ms |
13204 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |