This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct P {
int x, e;
P(){}
};
int queryMax(vector<int>& seggy, int i, int l, int r, int ql, int qr) {
if(ql > r || qr < l) return 0;
if(ql <= l && r <= qr) return seggy[i];
return max(queryMax(seggy, 2 * i, l, (l + r) / 2, ql, qr), queryMax(seggy, 2 * i + 1, (l + r) / 2 + 1, r, ql, qr));
}
int queryMin(vector<int>& seggy, int i, int l, int r, int ql, int qr) {
if(ql > r || qr < l) return LONG_MAX;
if(ql <= l && r <= qr) return seggy[i];
return min(queryMin(seggy, 2 * i, l, (l + r) / 2, ql, qr), queryMin(seggy, 2 * i + 1, (l + r) / 2 + 1, r, ql, qr));
}
void updateMax(vector<int>& seggy, int i, int l, int r, int qi, int qv) {
if(qi > r || qi < l) return;
if(l == r) {
seggy[i] = qv;
return;
}
updateMax(seggy, 2 * i, l, (l + r) / 2, qi, qv);
updateMax(seggy, 2 * i + 1, (l + r) / 2 + 1, r, qi, qv);
seggy[i] = max(seggy[2 * i], seggy[2 * i + 1]);
}
void updateMin(vector<int>& seggy, int i, int l, int r, int qi, int qv) {
if(qi > r || qi < l) return;
if(l == r) {
seggy[i] = qv;
return;
}
updateMin(seggy, 2 * i, l, (l + r) / 2, qi, qv);
updateMin(seggy, 2 * i + 1, (l + r) / 2 + 1, r, qi, qv);
seggy[i] = min(seggy[2 * i], seggy[2 * i + 1]);
}
void solve() {
int n;
cin >> n;
vector<P> a(n);
vector<int> coords(n);
vector<int> segMax(4 * n), segMin(4 * n, LONG_MAX);
map<int,int> mp;
for(int i = 0; i < n; i++) {
cin >> a[i].x >> a[i].e;
coords[i] = a[i].x;
}
sort(coords.begin(), coords.end());
for(int i = 0; i < n; i++) mp[coords[i]] = i;
sort(a.begin(), a.end(), [&](P x, P y){return x.e > y.e;});
int res = 0;
for(int i = 0; i < n; i++) {
int bebe = queryMax(segMax, 1, 0, n - 1, 0, i - 1), baba = queryMin(segMin, 1, 0, n - 1, i + 1, n - 1);
if(a[i].x + a[i].e > queryMax(segMax, 1, 0, n - 1, 0, mp[a[i].x]) && a[i].x - a[i].e < queryMin(segMin, 1, 0, n - 1, mp[a[i].x] + 1, n - 1)) {
res++;
updateMax(segMax, 1, 0, n - 1, mp[a[i].x], a[i].x + a[i].e);
updateMin(segMin, 1, 0, n - 1, mp[a[i].x], a[i].x - a[i].e);
}
}
cout << res << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:58:13: warning: unused variable 'bebe' [-Wunused-variable]
58 | int bebe = queryMax(segMax, 1, 0, n - 1, 0, i - 1), baba = queryMin(segMin, 1, 0, n - 1, i + 1, n - 1);
| ^~~~
Main.cpp:58:61: warning: unused variable 'baba' [-Wunused-variable]
58 | int bebe = queryMax(segMax, 1, 0, n - 1, 0, i - 1), baba = queryMin(segMin, 1, 0, n - 1, i + 1, n - 1);
| ^~~~
# | 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... |