#include <bits/stdc++.h>
using namespace std;
#define int long long
#define h first
#define k second
const int maxn=1e5;
pair<int,int>a[maxn+7];
int dem[maxn+7];
int n;
struct BIT{
int n;
vector<int>t;
BIT(){}
BIT(int n):n(n),t(n+7,0){}
void up(int x,int val){
for(;x<=n;x+=(x&(-x)))t[x]+=val;
}
int get(int x){
int ans=0;
for(;x;x-=(x&(-x)))ans+=t[x];
return ans;
}
};
main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i].h>>a[i].k;
sort(a+1,a+n+1);
BIT t(a[n].h);
// for(int i=1;i<=n;i++){
// cout<<a[i].h<<" "<<a[i].k<<"\n";
// }
for(int i=1;i<=n;i++){
int h=a[i].h,k=a[i].k;
int val=t.get(h-k);
int l=1,r=h;
int res=0;
while(l<=r){
int m=(l+r)/2;
if(t.get(m)<=val){
res=m;
r=m-1;
}
else l=m+1;
}
int left=res;
l=1,r=h;
res=h+1;
while(l<=r){
int m=(l+r)/2;
if(t.get(m)>=val){
res=m;
l=m+1;
}
else r=m-1;
}
int right=res;
// cout<<left<<" "<<right<<"\n";
t.up(right+1,1);
t.up(h+1,-1);
t.up(left,1);
t.up(left+(k-(h-right)),-1);
}
int ans=0;
for(int i=1;i<=a[n].h;i++){
int x=t.get(i);
ans+=(x)*(x-1)/2;
}
cout<<ans;
return 0;
}
Compilation message
sails.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1087 ms |
348 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1012 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1059 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
856 KB |
Output is correct |
2 |
Execution timed out |
1088 ms |
1152 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1047 ms |
2140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1039 ms |
3152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1045 ms |
3412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1060 ms |
3668 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |