# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
991484 |
2024-06-02T09:53:46 Z |
goats_9 |
Sails (IOI07_sails) |
C++17 |
|
69 ms |
2652 KB |
/* Author: goats_9 */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define LSOne(s) (s & -(s))
class BIT {
int n;
vector<ll> values;
public:
BIT(int _n) : n(_n), values(n + 1, 0LL) {}
void update(int l, int r, int v) {
if (r <= l) return;
for (; l <= n; l += LSOne(l)) values[l] += v;
for (; r <= n; r += LSOne(r)) values[r] -= v;
}
ll query(int i) {
if (i > n) return -1;
ll ret = 0;
for (; i; i -= LSOne(i)) ret += values[i];
return ret;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<array<int, 2>> mast(n);
for (int i = 0; i < n; i++) cin >> mast[i][0] >> mast[i][1];
sort(mast.begin(), mast.end());
BIT ft(mast.back()[0]);
for (auto [h, k] : mast) {
int ht = ft.query(h - k + 1);
int l = 0, r = h;
while (r - l > 1) {
int g = (l + r) / 2;
if (ft.query(g) > ht) l = g;
else r = g;
}
int l1 = r;
l = 1, r = h + 1;
while (r - l > 1) {
int g = (l + r) / 2;
if (ft.query(g) >= ht) l = g;
else r = g;
}
ft.update(r, h + 1, 1);
ft.update(l1, l1 + k + r - h - 1, 1);
}
ll ans = 0;
for (int i = 1; i <= mast.back()[0]; i++) {
ll u = ft.query(i);
ans += u*(u - 1)/2;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
604 KB |
Output is correct |
2 |
Correct |
13 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
1628 KB |
Output is correct |
2 |
Correct |
50 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
1936 KB |
Output is correct |
2 |
Correct |
56 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
1884 KB |
Output is correct |
2 |
Correct |
46 ms |
1372 KB |
Output is correct |