# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1018261 |
2024-07-09T17:43:21 Z |
ttamx |
Sails (IOI07_sails) |
C++17 |
|
54 ms |
2644 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N=1e5+5;
int n;
vector<pair<int,int>> a;
ll ans;
struct Fenwick{
int t[N];
void update(int i,int v){
for(;i<N;i+=i&-i)t[i]+=v;
}
int query(int i){
int res=0;
for(;i>0;i-=i&-i)res+=t[i];
return res;
}
}f;
int get(int x){
int l=0,r=N-1;
while(l<r){
int m=(l+r+1)/2;
if(f.query(m)>=x)l=m;
else r=m-1;
}
return l;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
a.resize(n);
for(auto &[h,k]:a)cin >> h >> k;
sort(a.begin(),a.end());
for(auto [h,k]:a){
int val=f.query(h-k+1);
int l=get(val+1),r=min(get(val),h);
f.update(r+1,1);
f.update(h+1,-1);
f.update(l+1,1);
f.update(l+k-h+r+1,-1);
}
for(int i=1;i<N;i++){
int val=f.query(i);
ans+=1LL*val*(val-1)/2;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
616 KB |
Output is correct |
2 |
Correct |
13 ms |
988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
2200 KB |
Output is correct |
2 |
Correct |
37 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
2384 KB |
Output is correct |
2 |
Correct |
37 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
2644 KB |
Output is correct |
2 |
Correct |
37 ms |
2392 KB |
Output is correct |