# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
108662 | 2019-04-30T15:21:16 Z | PeppaPig | Sails (IOI07_sails) | C++14 | 101 ms | 2072 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 | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 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 | 6 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 1152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 768 KB | Output is correct |
2 | Correct | 21 ms | 764 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 1264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 98 ms | 1976 KB | Output is correct |
2 | Correct | 74 ms | 1788 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 1900 KB | Output is correct |
2 | Correct | 78 ms | 1880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 101 ms | 2072 KB | Output is correct |
2 | Correct | 63 ms | 1528 KB | Output is correct |