# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
447815 |
2021-07-27T15:04:05 Z |
gromperen |
Sails (IOI07_sails) |
C++14 |
|
117 ms |
2628 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
const int MAXN = 1e5;
int n, fen[MAXN+5];
void update(int i, ll val) {
for (; i > 0; i -= i & (-i)) fen[i-1] += val;
}
int query(int i) {
ll s = 0;
for (; i < MAXN; i += i & (-i)) s += fen[i-1];
return s;
}
int getft(int x) {
int l = 0, r = MAXN;
while (l < r) {
int m = (r + l + 1) / 2;
if (query(m) >= x) {
l = m;
} else {
r = m - 1;
}
}
return l;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
vector<pair<ll,ll>>a(n);
for (int i= 0; i < n; ++i) cin >> a[i].first >> a[i].second;
sort(a.begin(),a.end());
for (auto IT : a) {
int h, k; tie(h, k) = IT;
int p = h - k;
update(h, 1);
if (p == 0) continue;
int lb = min(getft(query(p)), h), rb = getft(query(p) + 1);
update(lb, -1), update(rb, -1);
update(rb + k - (h - lb), 1);
}
ll ans = 0;
for (int i = 1; i < MAXN; ++i) {
ans += 1LL * query(i) * (query(i)-1) / 2;
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
588 KB |
Output is correct |
2 |
Correct |
35 ms |
824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
1416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
2168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
100 ms |
2512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
117 ms |
2628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |