Submission #1043090

#TimeUsernameProblemLanguageResultExecution timeMemory
1043090biankAdvertisement 2 (JOI23_ho_t2)C++17
0 / 100
58 ms6572 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}; ii op(ii lhs, ii rhs) { return {min(lhs.first, rhs.first), max(lhs.second, rhs.second)}; } 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]; }); int ans = 0; for (int i = 0; i < n; i++) { int p = pos(x[id[i]]); int maxi = query(0, p).second; int mini = query(p, sz(vals)).first; int sum = x[id[i]] + e[id[i]]; int diff = x[id[i]] - e[id[i]]; if (maxi < sum && mini > diff) ans++; update(p, ii{sum, diff}); } 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...