# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
992035 | ThMinh_ | Advertisement 2 (JOI23_ho_t2) | C++17 | 178 ms | 19908 KiB |
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>
using namespace std;
const int N = 5e5 + 10;
int n, ans, inf;
struct rei {
int x, e, pos;
};
rei a[N];
void init() {
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i].x >> a[i].e;
}
struct bit {
int tr[N];
void up(int x, int val) {
while(x) {
tr[x] = max(tr[x], val);
x -= x & -x;
}
}
int get(int x) {
int res = inf;
while(x <= n) {
res = max(res, tr[x]);
x += x & -x;
}
return res;
}
} f, l;
int main () {
cin.tie(0) -> sync_with_stdio(0);
if(fopen("Task.inp", "r")) {
freopen("Task.inp", "r", stdin);
freopen("WA.out", "w", stdout);
}
inf = - 2e9;
init();
sort(a + 1, a + n + 1, [] (rei x, rei y) {
return x.x < y.x;
});
for(int i = 1; i <= n; ++i) a[i].pos = i;
sort(a + 1, a + n + 1, [] (rei x, rei y) {
return x.e > y.e;
});
fill(f.tr + 1, f.tr + n + 1, inf);
fill(l.tr + 1, l.tr + n + 1, inf);
for(int i = 1; i <= n; ++i) {
bool ok = 1;
if(a[i].pos - 1) ok &= (f.get(n + 2 - a[i].pos) < a[i].e + a[i].x);
if(n - a[i].pos) ok &= (l.get(a[i].pos + 1) < a[i].e - a[i].x);
ans += ok;
f.up(n - a[i].pos + 1, a[i].e + a[i].x);
l.up(a[i].pos, a[i].e - a[i].x);
}
cout << ans;
}
Compilation message (stderr)
# | 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... |