# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
108661 | 2019-04-30T15:18:35 Z | PeppaPig | Sails (IOI07_sails) | C++14 | 123 ms | 3192 KB |
#include <bits/stdc++.h> #define long long long #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 1e5+5; int n; vector<pii> vec; long t[N]; void update(int x, long k) { for(int i = x; i < N; i += i & -i) t[i] += k; } long query(int x, long ret = 0) { for(int i = x; i; i -= i & -i) ret += t[i]; return ret; } int main() { scanf("%d", &n); for(int i = 1, a, b; i <= n; i++) scanf("%d %d", &a, &b), vec.emplace_back(a, b); sort(vec.begin(), vec.end()); for(int i = 0, h, k; i < n; i++) { auto idx = [&](int x) { int l = 0, r = h; while(l < r) { int m = (l + r + 1) >> 1; if(query(m) >= x) l = m; else r = m-1; } return l; }; tie(h, k) = vec[i]; int up = idx(query(h - k + 1)), dw = idx(query(h - k + 1) + 1); update(up + 1, 1), update(h + 1, -1); update(dw + 1, 1), update(dw + 1 + (k - h + up), - 1); } long ans = 0; for(int i = 1; i < N; i++) { long now = query(i); ans += now * (now - 1) / 2; } printf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 444 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 6 ms | 1124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 768 KB | Output is correct |
2 | Correct | 29 ms | 1092 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 1304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 1776 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 84 ms | 2828 KB | Output is correct |
2 | Correct | 80 ms | 2792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 95 ms | 3040 KB | Output is correct |
2 | Correct | 67 ms | 2540 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 123 ms | 3192 KB | Output is correct |
2 | Correct | 63 ms | 2536 KB | Output is correct |