#include "bits/stdc++.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ep emplace_back
#define pb push_back
#define pf push_front
const ll mod = 1e9 + 7;
const int N = 2e5 + 5;
const ll oo = 1e18;
bool START;
int n, q;
vector<int> arr;
pii a[N];
struct node {
ll c;
int a, b, id;
node(ll c_, int a_, int b_, int id_) : c(c_), a(a_), b(b_), id(id_) {}
bool operator<(const node &other) const {
if (c == other.c) return id < other.id;
return c > other.c;
}
};
vector<node> sw;
int m;
struct BIT {
ordered_set<int> bit[N];
void add(int idx, int val) {
idx = lower_bound(vall(arr), idx) - arr.begin() + 1;
for (; idx <= m; idx += idx & -idx) bit[idx].insert(val);
}
int get(int idx, int val) {
int ans = 0;
idx = upper_bound(vall(arr), idx) - arr.begin();
for (; idx > 0; idx -= idx & -idx) ans += (sze(bit[idx]) - bit[idx].order_of_key(val));
return ans;
}
int get(int l, int r, int val) {
return get(r, val) - get(l - 1, val);
}
} bit;
int ans[N];
inline void solve() {
sort(vall(arr));
arr.erase(unique(vall(arr)), arr.end());
m = sze(arr);
sort(vall(sw));
for (auto &nd : sw) {
if (nd.id == 0) {
bit.add(nd.a, nd.b);
} else {
ans[nd.id] = bit.get(nd.a, arr.back(), nd.b);
}
}
for (int i = 1; i <= q; ++i) cout << ans[i] << endl;
}
inline void input() {
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
cin >> a[i].fi >> a[i].se;
arr.pb(a[i].fi);
sw.pb(node(a[i].fi + a[i].se, a[i].fi, a[i].se, 0));
}
for (int i = 1; i <= q; ++i) {
int a, b, c;
cin >> a >> b >> c;
sw.pb(node(c, a, b, i));
}
return solve();
}
bool END;
int main() {
if(fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
input();
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl;
cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
examination.cpp: In function 'int main()':
examination.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen(task ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | freopen(task ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |