Submission #198612

#TimeUsernameProblemLanguageResultExecution timeMemory
198612MetBSails (IOI07_sails)C++14
5 / 100
657 ms34848 KiB
#include <bits/stdc++.h> #define N 1000001 using namespace std; typedef long long ll; const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3; struct V { ll min, max, midl, midr; V () { min = max = midl = midr = INF; } V (ll x) { min = max = midl = midr = x; } V (ll a, ll b, ll c, ll d) : min (a), max (b), midl (c), midr (d) {} }; struct LazySeg { V t[N]; ll ta[N], start; V merge (V a, V b) { return V (a.min, b.max, a.max, b.min); } void push (ll node) { t[node].min += ta[node]; t[node].max += ta[node]; t[node].midl += ta[node]; t[node].midr += ta[node]; if (node < start) { ta[2 * node] += ta[node]; ta[2 * node + 1] += ta[node]; } ta[node] = 0; } void build (ll n) { start = 1; while (start < n) start <<= 1; for (ll i = 0; i < n; i++) t[start + i] = V (0); for (ll i = start - 1; i > 0; i--) t[i] = merge (t[2 * i], t[2 * i + 1]); } void update (ll node, ll tl, ll tr, ll l, ll r, ll d) { push (node); if (r < tl || tr < l) return; if (l <= tl && tr <= r) { ta[node] += d; push (node); return; } ll tm = (tl + tr) / 2; update (2 * node, tl, tm, l, r, d); update (2 * node + 1, tm + 1, tr, l, r, d); t[node] = merge (t[2 * node], t[2 * node + 1]); } ll get (ll node, ll tl, ll tr, ll x) { push (node); if (tl == tr) return t[node].min; ll tm = (tl + tr) / 2; if (x <= tm) return get (2 * node, tl, tm, x); else return get (2 * node + 1, tm + 1, tr, x); } ll lower_bound (ll n, ll x) { int l = 0, r = n - 1; while (l < r) { int mid = (l + r + 1) / 2; if (get (1, 0, start - 1, mid) > x) r = mid - 1; else l = mid; } return l; } ll upper_bound (ll n, ll x) { int l = 0, r = n - 1; while (l < r) { int mid = (l + r) / 2; if (get (1, 0, start - 1, mid) < x) l = mid + 1; else r = mid; } return l; } } t; ll n, m; pair <ll, ll> a[N]; int main () { cin >> n; for (ll i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; m = max (m, a[i].first); } t.build (m); sort (a, a + n); for (ll i = n - 1; i >= 0; i--) { if (!a[i].second) continue; ll x = t.get (1, 0, t.start - 1, a[i].second - 1); ll l = t.upper_bound (a[i].first, x); ll r = t.lower_bound (a[i].first, x); assert (l != -1); assert (r != -1); if (l) t.update (1, 0, t.start - 1, 0, l - 1, 1); a[i].second -= l; t.update (1, 0, t.start - 1, r - a[i].second + 1, r, 1); } ll sum = 0; for (ll i = 0; i < m; i++) { ll x = t.get (1, 0, t.start - 1, i); sum += x * (x - 1) / 2; } cout << sum; }
#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...