/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define isz(x) (int)x.size()
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T, class U, class Compare = less<>> using order_statistic_map = tree<T, U, Compare, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class Compare = less<>> using order_statistic_set = order_statistic_map<T, null_type, Compare>;
struct Query {
int x, y, z, idx;
};
void solve() {
int n, q;
cin >> n >> q;
vector<pair<int, int>> vec;
for (int i = 0; i < n; ++i) {
int s, t;
cin >> s >> t;
vec.emplace_back(s, t);
}
vector<Query> queries(q);
for (int i = 0; i < q; ++i) {
int x, y, z;
cin >> x >> y >> z;
queries[i] = {x, y, z, i};
}
vector<int> res(q);
{
sort(all(queries), [&](const auto &A, const auto &B) {
return A.z > B.z;
});
sort(all(vec), [&](const auto &A, const auto &B) {
return A.first + A.second > B.first + B.second;
});
int ptr = 0;
order_statistic_set<int> oss;
for (auto [x, y, z, idx] : queries) {
if (x >= z - y) continue;
// cout << x << " " << z - y << endl;
while (ptr < n and vec[ptr].first + vec[ptr].second >= z) {
oss.insert(vec[ptr].first);
++ptr;
}
res[idx] += oss.order_of_key(z - y) - oss.order_of_key(x);
// cout << idx << " " << res[idx] << endl;
}
}
{
sort(all(queries), [&](const auto &A, const auto &B) {
return max(A.x, A.z - A.y) > max(B.x, B.z - B.y);
});
sort(all(vec), [&](const auto &A, const auto &B) {
return A.first > B.first;
});
int ptr = 0;
order_statistic_set<int> oss;
for (auto [x, y, z, idx] : queries) {
int val = max(x, z - y);
while (ptr < n and vec[ptr].first >= val) {
oss.insert(vec[ptr].second);
++ptr;
}
res[idx] += isz(oss) - oss.order_of_key(y);
}
}
for (auto val : res) cout << val << "\n";
}
signed main() {
#ifndef CDuongg
if(fopen(taskname".inp", "r"))
assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
cout << "Check array size pls sir" << endl;
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
100 ms |
9056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
100 ms |
9056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |