Submission #380806

#TimeUsernameProblemLanguageResultExecution timeMemory
380806JerryLiu06Sails (IOI07_sails)C++11
100 / 100
279 ms6904 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, int> pii; #define pb push_back #define f first #define s second int N; ll MX; vector<pii> A; pii tree[400010]; void pushdown(int x, int l, int r) { int mid = (l + r) / 2; tree[x].f += tree[x].s; if (l < r) { tree[2 * x].s += tree[x].s; tree[2 * x + 1].s += tree[x].s; } tree[x].s = 0; } void update(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2; pushdown(x, l, r); if (r < tl || l > tr) return ; if (tl <= l && r <= tr) { tree[x].s++; return ; } update(2 * x, l, mid, tl, tr); update(2 * x + 1, mid + 1, r, tl, tr); pushdown(2 * x, l, mid); pushdown(2 * x + 1, mid + 1, r); tree[x].f = max(tree[2 * x].f, tree[2 * x + 1].f); } ll queryMax(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2; pushdown(x, l, r); if (r < tl || l > tr) return -1; if (tl <= l && r <= tr) return tree[x].f; return max(queryMax(2 * x, l, mid, tl, tr), queryMax(2 * x + 1, mid + 1, r, tl, tr)); } ll queryPos(int x, int l, int r, int val) { int mid = (l + r) / 2; pushdown(x, l, r); if (l == r) return l; pushdown(2 * x, l, mid); pushdown(2 * x + 1, mid + 1, r); if (tree[2 * x + 1].f >= val) return queryPos(2 * x + 1, mid + 1, r, val); else if (tree[2 * x].f >= val) return queryPos(2 * x, l, mid, val); return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N; for (int i = 0; i < N; i++) { pii P; cin >> P.f >> P.s; A.pb(P); MX = max(MX, P.f); } sort(A.begin(), A.end()); for (pii P : A) { int FIRST = P.f - P.s + 1; int CUR = queryMax(1, 1, MX, FIRST, FIRST); int END = min(queryPos(1, 1, MX, CUR) + 1, P.f + 1); int START = queryPos(1, 1, MX, CUR + 1) + 1; update(1, 1, MX, END, P.f); update(1, 1, MX, START, P.s - P.f + END + START - 2); } ll ans = 0; for (int i = 1; i <= MX; i++) { ll CUR = queryMax(1, 1, MX, i, i); ans += (CUR * (CUR - 1)) / 2; } cout << ans; }

Compilation message (stderr)

sails.cpp: In function 'void pushdown(int, int, int)':
sails.cpp:15:42: warning: unused variable 'mid' [-Wunused-variable]
   15 | void pushdown(int x, int l, int r) { int mid = (l + r) / 2;
      |                                          ^~~
sails.cpp: In function 'll queryPos(int, int, int, int)':
sails.cpp:42:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   42 |     else if (tree[2 * x].f >= val) return queryPos(2 * x, l, mid, val); return 0;
      |     ^~~~
sails.cpp:42:73: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   42 |     else if (tree[2 * x].f >= val) return queryPos(2 * x, l, mid, val); 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...