# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
991481 |
2024-06-02T09:51:10 Z |
goats_9 |
Sails (IOI07_sails) |
C++17 |
|
70 ms |
3164 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;
BIT ft(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());
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 <= n; 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 |
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 |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
2504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
3164 KB |
Output is correct |
2 |
Correct |
49 ms |
2908 KB |
Output is correct |