Submission #729011

#TimeUsernameProblemLanguageResultExecution timeMemory
729011MilosMilutinovicAdvertisement 2 (JOI23_ho_t2)C++14
100 / 100
717 ms25028 KiB
/** * author: wxhtzdy * created: 12.02.2023 12:07:23 **/ #include <bits/stdc++.h> using namespace std; const int N = 500500; const int M = 8 * N; int st[2][M]; void build(int x, int p, int l, int r, int v) { st[x][p] = v; if (l == r) { return; } int mid = l + r >> 1; build(x, p * 2, l, mid, v); build(x, p * 2 + 1, mid + 1, r, v); } int query(int x, int p, int l, int r, int ll, int rr) { if (l > r || l > rr || r < ll) { return -2e9; } if (ll <= l && r <= rr) { return st[x][p]; } int mid = l + r >> 1; return max(query(x, p * 2, l, mid, ll, rr), query(x, p * 2 + 1, mid + 1, r, ll, rr)); } void modify(int x, int p, int l, int r, int i, int v) { st[x][p] = max(st[x][p], v); if (l == r) { return; } int mid = l + r >> 1; if (i <= mid) { modify(x, p * 2, l, mid, i, v); } else { modify(x, p * 2 + 1, mid + 1, r, i, v); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> x(n); vector<int> e(n); for (int i = 0; i < n; i++) { cin >> x[i] >> e[i]; } vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int i, int j) { return e[i] > e[j]; }); vector<int> xs; for (int i = 0; i < n; i++) { xs.push_back(x[i]); } sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); int k = (int) xs.size(); auto GetVal = [&](int t) { return (int) (lower_bound(xs.begin(), xs.end(), t) - xs.begin()); }; build(0, 1, 0, k - 1, -2e9); build(1, 1, 0, k - 1, -2e9); int ans = 0; for (int i : order) { // e[j] - x[j] >= e[i] - x[i], x[i] <= x[j] // e[j] + x[j] >= x[i] + e[i], x[i] >= x[j] int p = GetVal(x[i]); if (query(0, 1, 0, k - 1, p, k - 1) >= e[i] - x[i]) { continue; } if (query(1, 1, 0, k - 1, 0, p) >= e[i] + x[i]) { continue; } ans += 1; modify(0, 1, 0, k - 1, p, e[i] - x[i]); modify(1, 1, 0, k - 1, p, e[i] + x[i]); } cout << ans << '\n'; return 0; }

Compilation message (stderr)

Main.cpp: In function 'void build(int, int, int, int, int)':
Main.cpp:19:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   19 |   int mid = l + r >> 1;
      |             ~~^~~
Main.cpp: In function 'int query(int, int, int, int, int, int)':
Main.cpp:31:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |   int mid = l + r >> 1;
      |             ~~^~~
Main.cpp: In function 'void modify(int, int, int, int, int, int)':
Main.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |   int mid = l + r >> 1;
      |             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...