# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1112173 |
2024-11-13T18:16:06 Z |
farica |
Sails (IOI07_sails) |
C++14 |
|
61 ms |
3764 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
template <class T> class BIT {
private:
int size;
vector<T> bit;
vector<T> arr;
public:
BIT(int size) : size(size), bit(size + 1), arr(size) {}
void set(int ind, T val) { add(ind, val - arr[ind]); }
void add(int ind, T val) {
arr[ind] += val;
ind++;
for (; ind <= size; ind += ind & -ind) { bit[ind] += val; }
}
T pref_sum(int ind) {
ind++;
T total = 0;
for (; ind > 0; ind -= ind & -ind) { total += bit[ind]; }
return total;
}
};
void solve() {
int n;
cin >> n;
vector<pair<int,int>>v(n);
for(int i=0; i<n; ++i) cin >> v[i].first >> v[i].second;
sort(v.begin(), v.end());
BIT<int> bit(N);
const auto first = [&](int val, int r) {
int l = 0;
while(l < r) {
int mid = l + (r - l) / 2, x = bit.pref_sum(mid);
if(x < val) r = mid;
else l = mid + 1;
}
return l;
};
for(int i=0; i<n; ++i) {
int len = v[i].first - v[i].second, val = bit.pref_sum(len), x = first(val, v[i].first), y = first(val+1, v[i].second);
bit.add(x, 1);
bit.add(v[i].first, -1);
bit.add(y, 1);
bit.add(y + v[i].second - (v[i].first - x), -1);
}
long long ans = 0;
for(int i=0; i<N; ++i) {
int tmp = bit.pref_sum(i);
ans += 1ll * tmp * (tmp-1) / 2;
}
cout << ans << endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1104 KB |
Output is correct |
2 |
Correct |
2 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1104 KB |
Output is correct |
2 |
Correct |
2 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1104 KB |
Output is correct |
2 |
Correct |
2 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2128 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1104 KB |
Output is correct |
2 |
Incorrect |
2 ms |
1104 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
2128 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
2896 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
17 ms |
3144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
1940 KB |
Output is correct |
2 |
Incorrect |
42 ms |
1884 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
3764 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |