#include <bits/stdc++.h>
#define ll long long
#define name "Advertisement"
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; ++i)
#define fid(i, a, b) for(int i = a; i >= b; --i)
#define maxn (int) (5e5 + 7)
using namespace std;
int n;
pair<int, int> a[maxn];
vector<int> Comp;
struct IT {
int st[4 * maxn];
IT() { memset(st, -60, sizeof st); }
void update(int x, int val, int id = 1, int l = 1, int r = n) {
if(l > x || r < x) return;
if(l == r) return st[id] = val, void();
int mid = (l + r) >> 1;
update(x, val, _left), update(x, val, _right);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
int get(int u, int v, int id = 1, int l = 1, int r = n) {
if(l > v || r < u) return -2e9 - 7;
if(u <= l && r <= v) return st[id];
int mid = (l + r) >> 1;
return max(get(u, v, _left), get(u, v, _right));
}
} StMax, StMin;
void solve() {
cin >> n;
fi(i, 1, n) cin >> a[i].first >> a[i].second;
fi(i, 1, n) Comp.push_back(a[i].first);
sort(all(Comp));
Comp.resize(unique(all(Comp)) - Comp.begin());
sort(a + 1, a + 1 + n, [](pair<int, int> x, pair<int, int> y) { return x.second > y.second; });
int ans = 0;
fi(i, 1, n) {
int x = a[i].first, e = a[i].second;
int it = upper_bound(all(Comp), x) - Comp.begin();
bool ok = 1;
if( StMax.get(1, it) >= x + e) ok = 0;
if(-StMin.get(it, n) <= x - e) ok = 0;
ans += ok;
StMax.update(it, x + e);
StMin.update(it, -(x - e));
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
if(fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(name".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(name".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... |