#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 100005;
template <class T> using Tree = tree<T,null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
Tree<int> tr[N];
void upd (int id, int v) {
id++;
while (id < N) {
tr[id].insert(v);
id += id & -id;
}
}
int qry (int id, int v) {
id++;
int ret = 0;
while (id) {
ret += tr[id].size() - tr[id].order_of_key(v);
id -= id & -id;
}
return ret;
}
int qry (int l, int r, int v) {
return qry(r, v) - qry(l - 1, v);
}
struct St {
int a, b, c, id;
bool operator < (const St& other) {
return c > other.c;
};
};
int a[N];
St s[N], qs[N];
int ans[N];
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
for (int i = 0; i < n; ++i) {
cin >> s[i].a >> s[i].b;
s[i].c = s[i].a + s[i].b;
a[i] = s[i].a;
}
sort(a, a + n);
sort(s, s + n);
for (int i = 0; i < n; ++i) {
s[i].a = lower_bound(a, a + n, s[i].a) - a;
}
for (int i = 0; i < q; ++i) {
cin >> qs[i].a >> qs[i].b >> qs[i].c;
qs[i].id = i;
qs[i].a = lower_bound(a, a + n, qs[i].a) - a;
}
sort(qs, qs + q);
for (int i = 0, p = 0; i < q; ++i) {
while (p < n && s[p].c >= qs[i].c) {
upd(s[p].a, s[p].b);
p++;
}
ans[qs[i].id] = qry(qs[i].a, n - 1, qs[i].b);
}
for (int i = 0; i < q; ++i) {
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8148 KB |
Output is correct |
2 |
Incorrect |
8 ms |
8160 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1175 ms |
54688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1175 ms |
54688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8148 KB |
Output is correct |
2 |
Incorrect |
8 ms |
8160 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |