#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class fenwick {
private:
vector<int> arr, fenw;
public:
int query(int i) {
if (i == -1) return 0;
int ans = 0;
for (; i; i -= (i & (-i)))
ans += fenw[i];
return ans;
}
void add(int i, int x) {
arr[i] += x;
for (; i <= arr.size(); i += (i & (-i)))
fenw[i] += x;
}
fenwick(int n) {
fenw.assign(n + 1, 0);
arr.assign(n + 1, 0);
}
};
int main()
{
int n, q; cin >> n >> q;
vector<pair<int, int>> a(n);
vector<vector<int>> qr;
for (int i = 0; i < n; ++i)
cin >> a[i].first >> a[i].second;
for (int x = 0; x < q; ++x) {
int i, j, k; cin >> i >> j >> k;
qr.push_back({ i,j,k });
}
if (0) {
for (auto it : qr) {
int cnt = 0, x = it[0];
int y = it[1], z = it[2];
for (auto i : a)
if ((i.first >= x) && (i.second >= y) && ((i.first + i.second) >= z))
++cnt;
cout << cnt << endl;
}
}
else {
vector<vector<int>> arr;
vector<int> res(q);
for (auto x : a)
arr.push_back({ x.first, 1, x.second });
for (int i = 0; i < q; ++i)
arr.push_back({ qr[i][0], 0, i });
sort(arr.begin(), arr.end());
int m = arr.size();
for (int i = 0; i < m / 2; ++i)
swap(arr[i], arr[m - i - 1]);
fenwick f(1e5);
int cnt = 0;
for (int i = 0; i < m; ++i)
if (arr[i][1]) f.add(arr[i][2], 1), ++cnt;
else res[arr[i][2]] = f.query(qr[arr[i][2]][1] - 1);
for (auto x : res) cout << x << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |