This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e5+5;
int n, q, ans[maxn];
vector <vector <int> > fen[2];
vector <int> a;
vector <pair <int, pii> > vec;
vector <pair <pii, pii> > qs;
void upd3(int i, int j) {
// cout << i << ' ' << j << ' ' << fen[0][i-1].size() << '\n';
for (j = fen[0][i-1].size()-j; j <= fen[0][i-1].size(); j += j&-j) {
// assert(j < 0);
fen[1][i-1][j-1]++;
}
}
void upd1(int i, int x) {
for (i = fen[0].size()-i; i <= fen[0].size(); i += i&-i) fen[0][i-1].pb(x);
}
void upd2(int i, int x) {
// cout << x << "DD\n";
for (i = fen[0].size()-i; i <= fen[0].size(); i += i&-i) {
int j = lower_bound(all(fen[0][i-1]), x)-fen[0][i-1].begin();
upd3(i, j);
}
}
int get1(int i, int j) {
int ans = 0;
for (j = fen[0][i-1].size()-j; j; j -= j&-j) ans += fen[1][i-1][j-1];
return ans;
}
int get(int i, int x) {
int ans = 0;
for (i = fen[0].size()-i; i; i -= i&-i) {
int j = lower_bound(all(fen[0][i-1]), x)-fen[0][i-1].begin();
ans += get1(i, j);
}
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 0; i < n; i++) {
int s, t; cin >> s >> t;
a.pb(s);
vec.pb(mp(s+t, mp(s, t)));
}
sort(all(a)), sort(all(vec));
a.resize(unique(all(a))-a.begin());
fen[0].resize(a.size());
fen[1].resize(a.size());
for (int i = 0; i < n; i++) {
int j = lower_bound(all(a), vec[i].S.F)-a.begin();
upd1(j, vec[i].S.S);
}
for (int i = 0; i < fen[0].size(); i++) {
sort(all(fen[0][i]));
fen[0][i].resize(unique(all(fen[0][i]))-fen[0][i].begin());
fen[1][i].resize(fen[0][i].size());
}
for (int i = 0; i < q; i++) {
int x, y, z; cin >> x >> y >> z;
qs.pb(mp(mp(z, x), mp(y, i)));
}
sort(all(qs));
for (int i = q-1; i >= 0; i--) {
while (vec.size() and vec.back().F >= qs[i].F.F) {
int j = lower_bound(all(a), vec.back().S.F)-a.begin();
upd2(j, vec.back().S.S);
vec.pop_back();
}
int j = lower_bound(all(a), qs[i].F.S)-a.begin();
ans[qs[i].S.S] = get(j, qs[i].S.F);
}
for (int i = 0; i < q; i++) cout << ans[i] << '\n';
return 0;
}
Compilation message (stderr)
examination.cpp: In function 'void upd3(int, int)':
examination.cpp:27:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (j = fen[0][i-1].size()-j; j <= fen[0][i-1].size(); j += j&-j) {
| ~~^~~~~~~~~~~~~~~~~~~~~
examination.cpp: In function 'void upd1(int, int)':
examination.cpp:34:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (i = fen[0].size()-i; i <= fen[0].size(); i += i&-i) fen[0][i-1].pb(x);
| ~~^~~~~~~~~~~~~~~~
examination.cpp: In function 'void upd2(int, int)':
examination.cpp:38:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (i = fen[0].size()-i; i <= fen[0].size(); i += i&-i) {
| ~~^~~~~~~~~~~~~~~~
examination.cpp: In function 'int32_t main()':
examination.cpp:75:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int i = 0; i < fen[0].size(); i++) {
| ~~^~~~~~~~~~~~~~~
# | 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... |