Submission #1043093

#TimeUsernameProblemLanguageResultExecution timeMemory
1043093biankAdvertisement 2 (JOI23_ho_t2)C++14
33 / 100
257 ms25680 KiB
#include <bits/stdc++.h> using namespace std; #define sz(x) int(x.size()) #define all(x) begin(x),end(x) using ii = pair<int, int>; const int MAX_N = 5e5; const int INF = 1e9 + 20; ii st[2 * MAX_N]; int n; const ii NEUTR = {INF, -INF}; inline ii op(ii lhs, ii rhs) { return {min(lhs.first, rhs.first), max(lhs.second, rhs.second)}; } void init() { for (int i = 0; i < 2 * n; i++) st[i] = NEUTR; } void update(int p, ii v) { st[p += n] = v; while (p /= 2) st[p] = op(st[2 * p], st[2 * p + 1]); } ii query(int l, int r) { ii res = NEUTR; for (l += n, r += n; l < r; l /= 2, r /= 2) { if (l & 1) res = op(res, st[l++]); if (r & 1) res = op(st[--r], res); } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; vector<int> x(n), e(n); for (int i = 0; i < n; i++) { cin >> x[i] >> e[i]; } vector<int> vals = x; sort(all(vals)); vals.erase(unique(all(vals)), end(vals)); const auto pos = [&](int v) { return int(lower_bound(all(vals), v) - begin(vals)); }; vector<int> id(n); iota(all(id), 0); sort(all(id), [&](const int &lhs, const int &rhs) { return e[lhs] > e[rhs]; }); init(); int ans = 0; for (int i = 0; i < n; i++) { int p = pos(x[id[i]]); int mini = query(p, sz(vals)).first; int maxi = query(0, p).second; int diff = x[id[i]] - e[id[i]]; int sum = x[id[i]] + e[id[i]]; if (mini > diff && maxi < sum) ans++; update(p, ii{diff, sum}); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...