# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
550807 |
2022-04-19T09:00:33 Z |
Jomnoi |
Sails (IOI07_sails) |
C++17 |
|
76 ms |
2624 KB |
#include <bits/stdc++.h>
#define DEBUG false
using namespace std;
const int MAX_N = 1e5 + 10;
namespace fw {
int fenwick[MAX_N];
void add(const int &idx, const int &v) {
for(int i = idx; i < MAX_N; i += (i & -i)) {
fenwick[i] += v;
}
}
int get(const int &idx) {
int res = 0;
for(int i = idx; i >= 1; i -= (i & -i)) {
res += fenwick[i];
}
return res;
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
vector <pair <int, int>> sail(N + 1);
for(int i = 1; i <= N; i++) {
cin >> sail[i].first >> sail[i].second;
}
sort(sail.begin() + 1, sail.end());
for(int i = 1; i <= N; i++) {
auto [h, k] = sail[i];
int now = fw::get(h - k + 1), l, r, lm, rm;
l = 1, r = h, lm = 1;
while(l <= r) {
int mid = (l + r) / 2;
if(fw::get(mid) == now) {
r = mid - 1;
lm = mid;
}
else {
l = mid + 1;
}
}
l = 1, r = h, rm = h;
while(l <= r) {
int mid = (l + r) / 2;
if(fw::get(mid) == now) {
l = mid + 1;
rm = mid;
}
else {
r = mid - 1;
}
}
fw::add(rm + 1, 1);
fw::add(h + 1, -1);
fw::add(lm, 1);
fw::add(lm + k - (h - rm), -1);
}
long long ans = 0;
for(int i = 1; i < MAX_N; i++) {
int cnt = fw::get(i);
ans += 1ll*cnt * (cnt - 1) / 2;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
1356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
2160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
2412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
2624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |