# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
737001 | nguyentunglam | Advertisement 2 (JOI23_ho_t2) | C++17 | 223 ms | 14820 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>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 5e5 + 10;
int x[N], e[N], n;
vector<pair<int, int> > v;
struct BIT {
int bit[N];
void up(int pos, int val) {
while (pos <= n) {
bit[pos] = max(bit[pos], val);
pos += pos & -pos;
}
}
int get(int pos) {
int ret = -2e9;
while (pos) {
ret = max(ret, bit[pos]);
pos -= pos & -pos;
}
return ret;
}
} bit[2];
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen ("task.inp", "r")) {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
}
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
cin >> n;
for(int i = 1; i <= n; i++) {
int x, y; cin >> x >> y;
v.emplace_back(x, y);
bit[0].bit[i] = bit[1].bit[i] = -2e9;
}
sort(v.begin(), v.end());
for(int i = 1; i <= n; i++) tie(x[i], e[i]) = v[i - 1];
v.clear();
for(int i = 1; i <= n; i++) v.emplace_back(e[i], i);
sort(v.begin(), v.end());
int res = 0;
while (!v.empty()) {
int i = v.back().second; v.pop_back();
if (bit[0].get(i) >= x[i] + e[i] || bit[1].get(n - i + 1) >= e[i] - x[i]) continue;
res++;
bit[0].up(i, x[i] + e[i]);
bit[1].up(n - i + 1, e[i] - x[i]);
}
cout << res;
}
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... |