Submission #885490

#TimeUsernameProblemLanguageResultExecution timeMemory
885490juliany2Advertisement 2 (JOI23_ho_t2)C++17
100 / 100
359 ms27976 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() template<class T> struct ST { static constexpr T ID = {(int) -1e9, (int) -1e9}; // or whatever ID inline T comb(T a, T b) { return {max(a[0], b[0]), max(a[1], b[1])}; } // or whatever function int sz; vector<T> t; void init(int _sz, T val = ID) { t.assign((sz = _sz) * 2, ID); } void init(vector<T> &v) { t.resize((sz = v.size()) * 2); for (int i = 0; i < sz; ++i) t[i + sz] = v[i]; for (int i = sz - 1; i; --i) t[i] = comb(t[i * 2], t[(i * 2) | 1]); } void upd(int i, T x) { for (t[i += sz] = x; i > 1; i >>= 1) t[i >> 1] = comb(t[i], t[i ^ 1]); } T query(int l, int r) { T ql = ID, qr = ID; for (l += sz, r += sz + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) ql = comb(ql, t[l++]); if (r & 1) qr = comb(t[--r], qr); } return comb(ql, qr); } }; int main() { cin.tie(0)->sync_with_stdio(false); int n; cin >> n; vector<array<int, 2>> a(n); vector<int> pos; for (auto &[x, e] : a) { cin >> x >> e; pos.push_back(x); } sort(all(a), greater<>()); sort(all(pos)); pos.erase(unique(all(pos)), pos.end()); vector<array<int, 2>> b; for (auto &[x, e] : a) if (b.empty() || x != b.back()[0]) b.push_back({x, e}); sort(all(b), [&](array<int, 2> &x, array<int, 2> &y) { return x[1] > y[1]; }); ST<array<int, 2>> st; st.init(n + 1); int ans = b.size(); for (auto &[x, e] : b) { int i = lower_bound(all(pos), x) - pos.begin(); if (st.query(i, n)[0] >= e - x || st.query(0, i)[1] >= e + x) ans--; st.upd(i, {e - x, e + x}); } 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...