# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
447814 |
2021-07-27T15:03:03 Z |
gromperen |
Sails (IOI07_sails) |
C++14 |
|
133 ms |
2540 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll 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;
}
int 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 |
4 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
204 KB |
Output is correct |
2 |
Correct |
4 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
204 KB |
Output is correct |
2 |
Correct |
4 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
588 KB |
Output is correct |
2 |
Correct |
40 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
1172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
1648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
93 ms |
2236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
115 ms |
2492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
133 ms |
2540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |