/**
* author: NimaAryan
* created: 2024-08-17 22:57:42
**/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T, class C = less<>>
using indexed_set = tree<T, null_type, C, rb_tree_tag,
tree_order_statistics_node_update>;
#ifdef LOCAL
#include "algo/debug.h"
#endif
using i64 = long long;
struct Solver {
int n;
vector<indexed_set<int>> a;
Solver(int n) : n(n) {
a.resize(n);
}
void add(int x, int v) {
for (int i = x + 1; i <= n; i += i & -i) {
a[i - 1].insert(v);
}
}
int query(int x, int v) {
int res = 0;
for (int i = x + 1; i > 0; i -= i & -i) {
res += a[i - 1].size() - a[i - 1].order_of_key(v);
}
return res;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
cin >> N >> Q;
vector<int> S(N), T(N);
for (int i = 0; i < N; ++i) {
cin >> S[i] >> T[i];
}
vector<int> X(Q), Y(Q), Z(Q);
for (int i = 0; i < Q; ++i) {
cin >> X[i] >> Y[i] >> Z[i];
}
vector<int> p(Q);
iota(p.begin(), p.end(), 0);
sort(p.begin(), p.end(), [&](int i, int j) {
return Z[i] > Z[j];
});
vector<int> q(N);
iota(q.begin(), q.end(), 0);
sort(q.begin(), q.end(), [&](int i, int j) {
return S[i] + T[i] > S[j] + T[j];
});
auto xs = S;
xs.insert(xs.end(), X.begin(), X.end());
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
auto id = [&](int x) {
return xs.size() - (lower_bound(xs.begin(), xs.end(), x) - xs.begin()) - 1;
};
vector<int> ans(Q);
Solver f(xs.size());
int x = 0;
for (int i : p) {
while (x < N && S[q[x]] + T[q[x]] >= Z[i]) {
f.add(id(S[q[x]]), T[q[x]]);
++x;
}
ans[i] = f.query(id(X[i]), Y[i]);
}
for (int i = 0; i < Q; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
1884 KB |
Output is correct |
8 |
Correct |
6 ms |
2140 KB |
Output is correct |
9 |
Correct |
7 ms |
1944 KB |
Output is correct |
10 |
Incorrect |
4 ms |
1372 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
705 ms |
53084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
705 ms |
53084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
1884 KB |
Output is correct |
8 |
Correct |
6 ms |
2140 KB |
Output is correct |
9 |
Correct |
7 ms |
1944 KB |
Output is correct |
10 |
Incorrect |
4 ms |
1372 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |