Submission #934404

#TimeUsernameProblemLanguageResultExecution timeMemory
934404thinknoexitSails (IOI07_sails)C++17
70 / 100
406 ms4724 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; pair<int, int> a[100100]; int tree[400400], lazy[400400]; ll ans = 0; void lzy(int now, int l, int r) { if (lazy[now] == 0) return; tree[now] += lazy[now]; if (l != r) { lazy[2 * now] += lazy[now]; lazy[2 * now + 1] += lazy[now]; } lazy[now] = 0; } void update(int ql, int qr, int now = 1, int l = 1, int r = 100000) { lzy(now, l, r); if (l > qr || r < ql) return; if (ql <= l && r <= qr) { lazy[now]++; lzy(now, l, r); return; } int mid = (l + r) / 2; update(ql, qr, 2 * now, l, mid), update(ql, qr, 2 * now + 1, mid + 1, r); tree[now] = max(tree[2 * now], tree[2 * now + 1]); } int query(int v, int now = 1, int l = 1, int r = 100000) { lzy(now, l, r); if (l == r) return tree[now]; int mid = (l + r) / 2; if (v <= mid) return query(v, 2 * now, l, mid); else return query(v, 2 * now + 1, mid + 1, r); } void print(int now = 1, int l = 1, int r = 100000) { lzy(now, l, r); if (l == r) { if (l <= 4) cout << tree[now] << ' '; return; } int mid = (l + r) / 2; print(2 * now, l, mid); print(2 * now + 1, mid + 1, r); } void dfs(int now = 1, int l = 1, int r = 100000) { lzy(now, l, r); if (l == r) { ans += 1ll * tree[now] * (tree[now] - 1) / 2; return; } int mid = (l + r) / 2; dfs(2 * now, l, mid); dfs(2 * now + 1, mid + 1, r); } int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; for (int i = 1;i <= n;i++) { cin >> a[i].first >> a[i].second; } sort(a + 1, a + 1 + n); for (int i = 1;i <= n;i++) { int h = a[i].first, k = a[i].second; int mn = query(h); int v = query(h - k + 1); int l = 1, r = h - k + 1; while (l < r) { int mid = (l + r) / 2; if (query(mid) == v) r = mid; else l = mid + 1; } int p = l; if (v != mn) { l = h - k + 2, r = n; while (l < r) { int mid = (l + r) / 2; if (query(mid) < v) r = mid; else l = mid + 1; } update(l, h); k -= h - l + 1; } if (k != 0) update(p, p + k - 1); } dfs(); cout << ans; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...