# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54712 | 2018-07-04T18:00:08 Z | 0^0(#1466) | Sails (IOI07_sails) | C++11 | 96 ms | 2752 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int tree[100005]; int n; void update(int idx, int val) { while (idx < 100005) { tree[idx] += val; idx += idx & (-idx); } } int query(int idx) { int ret = 0; while (idx) { ret += tree[idx]; idx -= idx & (-idx); } return ret; } int get_idx(ll x) { int ret = 0; int le, ri, mid; le = 1; ri = 100000; while (le <= ri) { mid = (le + ri) / 2; if (query(mid) >= x) { ret = mid; le = mid + 1; } else ri = mid - 1; } return ret; } pair<int, int> arr[100005]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", &arr[i].first, &arr[i].second); sort(arr, arr + n); for (int i = 0; i < n; i++) { int h, k; tie(h, k) = arr[i]; int le = h - k + 1; if (le == 1 || query(le) != query(le-1)) { update(le, 1); update(h + 1, -1); } else { int idx = get_idx(query(le)); if (query(le)) { update(idx + 1, 1); update(h + 1, -1); k -= h - idx; } idx = get_idx(query(le) + 1); update(idx + 1, 1); update(idx + k + 1, -1); } } ll ans = 0; for (int i = 1; i <= 100000; i++) { ll temp = query(i); ans += temp * (temp - 1) / 2; } printf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 488 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 524 KB | Output is correct |
2 | Correct | 3 ms | 608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 608 KB | Output is correct |
2 | Correct | 3 ms | 608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 608 KB | Output is correct |
2 | Correct | 4 ms | 608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 608 KB | Output is correct |
2 | Correct | 6 ms | 936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 936 KB | Output is correct |
2 | Correct | 27 ms | 936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 1080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 77 ms | 1524 KB | Output is correct |
2 | Correct | 71 ms | 1524 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 82 ms | 1600 KB | Output is correct |
2 | Correct | 68 ms | 1728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 96 ms | 1728 KB | Output is correct |
2 | Correct | 72 ms | 2752 KB | Output is correct |