# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71494 | RezwanArefin01 | Sails (IOI07_sails) | C++17 | 161 ms | 8672 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 1e5 + 10;
int t[N]; ii s[N];
void update(int x, int v) {
for(; x < N; x += x & -x)
t[x] += v;
}
int read(int x, int ret = 0) {
for(; x > 0; x -= x & -x)
ret += t[x];
return ret;
}
void update(int l, int r, int v) {
update(l, v); update(r + 1, -v);
}
int main(int argc, char const *argv[]) {
int n; scanf("%d", &n);
for(int i = 0; i < n; i++) {
cin >> s[i].first >> s[i].second;
}
sort(s, s + n);
for(int i = 0; i < n; i++) {
int h = s[i].first, k = s[i].second;
int l = h - k + 1, r = h;
int c = read(l);
int lo = 1, hi = h, L, R;
while(lo <= hi) {
int mid = lo + hi >> 1;
if(read(mid) >= c) lo = mid + 1, R = mid;
else hi = mid - 1;
}
lo = 1, hi = h;
while(lo <= hi) {
int mid = lo + hi >> 1;
if(read(mid) <= c) hi = mid - 1, L = mid;
else lo = mid + 1;
}
update(R + 1, r, 1);
update(L, L + k - r + R - 1, 1);
}
ll ans = 0;
for(int i = 1; i < N; i++) {
int x = read(i);
ans += (ll) x * (x - 1) / 2;
}
printf("%lld\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |