Submission #927940

#TimeUsernameProblemLanguageResultExecution timeMemory
927940TAhmed33Sails (IOI07_sails)C++98
100 / 100
659 ms6364 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define mid ((l + r) >> 1) #define tl (node + 1) #define tr (node + 2 * (mid - l + 1)) struct pp { int sum = 0; int add = 0; }; struct SegmentTree { pp tree[200001] = {}; void prop (int l, int r, int node) { if (l == r) { tree[node].sum += tree[node].add; tree[node].add = 0; return; } tree[node].sum += (r - l + 1) * tree[node].add; tree[tl].add += tree[node].add; tree[tr].add += tree[node].add; tree[node].add = 0; } void update (int l, int r, int a, int b, int c, int node) { prop(l, r, node); if (l >= a && r <= b) { tree[node].add += c; prop(l, r, node); return; } if (l > b || r < a) return; update(l, mid, a, b, c, tl); update(mid + 1, r, a, b, c, tr); tree[node].sum = tree[tl].sum + tree[tr].sum; } int get (int l, int r, int a, int b, int node) { prop(l, r, node); if (l > b || r < a) return 0; if (l >= a && r <= b) return tree[node].sum; return get(l, mid, a, b, tl) + get(mid + 1, r, a, b, tr); } }; SegmentTree cur; const int MAXH = 100000; signed main () { int n; cin >> n; vector <pair <int, int>> arr; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; arr.push_back({x, y}); } sort(arr.begin(), arr.end()); for (auto [x, y] : arr) { int u = cur.get(1, MAXH, x - y + 1, x - y + 1, 1); int l = 1, r = x, ans1 = -1, ans2 = x + 1; while (l <= r) { if (cur.get(1, MAXH, mid, mid, 1) <= u) { ans1 = mid; r = mid - 1; } else { l = mid + 1; } } l = 1, r = x; while (l <= r) { if (cur.get(1, MAXH, mid, mid, 1) >= u) { l = mid + 1; } else { ans2 = mid; r = mid - 1; } } if (ans2 != x + 1) cur.update(1, MAXH, ans2, x, 1, 1); int z = y - (x - ans2 + 1); cur.update(1, MAXH, ans1, ans1 + z - 1, 1, 1); } int sum = 0; for (int i = 1; i <= arr.back().first; i++) { int z = cur.get(1, MAXH, i, i, 1); sum += z * (z - 1) / 2; } cout << sum << '\n'; }

Compilation message (stderr)

sails.cpp: In function 'int main()':
sails.cpp:54:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |  for (auto [x, y] : arr) {
      |            ^
#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...