Submission #792075

#TimeUsernameProblemLanguageResultExecution timeMemory
792075WLZAdvertisement 2 (JOI23_ho_t2)C++17
59 / 100
1568 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "templates/debug.h" #else #define debug(...) 0 #endif #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define eb emplace_back #define pb push_back #define mt make_tuple #define mp make_pair #define all(x) (x).begin(), (x).end() #define SZ(x) (int) x.size() using ll = long long; using ull = unsigned ll; using lll = __int128_t; using ulll = __uint128_t; using ld = long double; using ii = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vii = vector<ii>; template<typename T> using mx_pq = priority_queue<T>; template<typename T> using mn_pq = priority_queue<T, vector<T>, greater<T>>; template<typename T> void cmax(T &a, const T &b) { a = max(a, b); } template<typename T> void cmin(T &a, const T &b) { a = min(a, b); } const int INF = 0x3f3f3f3f; const ll LINF = (ll) 1e18; const double DINF = 1.0 / 0.0; const double pi = acos(-1); const double EPS = 1e-9; void solve(int current_case); int main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; for (int q = 1; q <= t; q++) solve(q); return 0; } struct node { int l, r, val, lazy; node *left ,*right; }; node *build(int l, int r) { return new node{l, r, -INF, -INF, nullptr, nullptr}; } void propagate(node *cur) { if (cur == nullptr || cur->lazy == -INF) return; cmax(cur->val, cur->lazy); if (cur->l != cur->r) { if (cur->left == nullptr) cur->left = build(cur->l, (cur->l + cur->r) / 2); if (cur->right == nullptr) cur->right = build((cur->l + cur->r) / 2 + 1, cur->r); cmax(cur->left->lazy, cur->lazy); cmax(cur->right->lazy, cur->lazy); } cur->lazy = -INF; } int query(node *cur, int l, int r) { // max if (cur == nullptr) return -INF; propagate(cur); if (l > cur->r || r < cur->l) return -INF; if (l <= cur->l && cur->r <= r) return cur->val; return max(query(cur->left, l, r), query(cur->right, l, r)); } void update(node *cur, int l, int r, int val) { // add propagate(cur); if (l > cur->r || r < cur->l) return; if (l <= cur->l && cur->r <= r) { cmax(cur->lazy, val); propagate(cur); return; } if (cur->left == nullptr) cur->left = build(cur->l, (cur->l + cur->r) / 2); if (cur->right == nullptr) cur->right = build((cur->l + cur->r) / 2 + 1, cur->r); update(cur->left, l, r, val); update(cur->right, l, r, val); cur->val = max(cur->left->val, cur->right->val); } void solve(int current_case) { int n; cin >> n; vi x(n), e(n); vii v(n); rep(i, 0, n) cin >> x[i] >> e[i], v[i] = {e[i], x[i]}; int mx = *max_element(all(x)); sort(v.rbegin(), v.rend()); node *root_l = build(1, mx), *root_r = build(1, mx); int ans = 0; for (auto &p : v) { if (query(root_l, p.second, p.second) >= p.first - p.second || query(root_r, p.second, p.second) >= p.first + p.second) continue; ans++; update(root_l, 1, p.second, p.first - p.second); update(root_r, p.second, mx, p.first + p.second); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...