/*
Author: Nguyen Chi Thanh - High School for the Gifted - VNU.HCM (i2528)
*/
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define ull unsigned long long
#define ld long double
#define pii pair<int, int>
#define fi first
#define se second
#define __builtin_popcount __builtin_popcountll
#define all(x) (x).begin(), (x).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(x) ((1ll << (x)))
#define debug(a, l, r) for (int _i = (l); _i <= (r); ++_i) cout << (a)[_i] << ' '; cout << '\n';
// Data structures
struct Normalize {
vector<int> vals;
Normalize() {}
void add(int v) {vals.push_back(v);}
void build() {
sort(all(vals));
vals.erase(unique(all(vals)), end(vals));
}
int compress(int v) {
return (int)(lower_bound(all(vals), v) - begin(vals)) + 1;
}
};
struct FenwickTree{
int n;
vector<int> fen;
FenwickTree(int _n) : n(_n), fen(n + 5, 0) {}
void update(int idx, int v) {
for (int i = idx; i <= n; i += i & -i)
fen[i] += v;
}
int get(int idx) {
int sum = 0;
for (int i = idx; i; i -= i & -i)
sum += fen[i];
return sum;
}
int query(int l, int r) {return get(r) - get(l - 1);}
};
// Main program
const int MAXN = 5e5 + 5;
int n, x[MAXN], e[MAXN];
pii segs[MAXN];
void init() {
cin >> n;
Normalize norm;
for (int i = 1; i <= n; ++i) {
cin >> x[i] >> e[i];
segs[i] = {x[i] - e[i], x[i] + e[i]};
norm.add(segs[i].fi);
norm.add(segs[i].se);
}
// Coords compression
norm.build();
for (int i = 1; i <= n; ++i) {
segs[i].fi = norm.compress(segs[i].fi);
segs[i].se = norm.compress(segs[i].se);
}
// for (int i = 1; i <= n; ++i) cout << segs[i].fi << ' ' << segs[i].se << '\n';
}
void solve() {
sort(segs + 1, segs + n + 1, [&] (pii &i, pii &j) {
if (i.fi == j.fi) return i.se > j.se;
return i.fi < j.fi;
});
FenwickTree fen(2 * n + 5);
int res = 0;
for (int i = 1; i <= n; ++i) {
int l = segs[i].fi, r = segs[i].se;
if (fen.query(r, 2 * n + 5) == 0)
++res;
fen.update(r, 1);
}
cout << res;
}
signed main() {
#ifdef NCTHANH
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(nullptr); cout.tie(nullptr);
init();
solve();
return 0;
}
| # | 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... |