# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1011176 |
2024-06-30T04:13:38 Z |
doducanh |
Sails (IOI07_sails) |
C++14 |
|
98 ms |
3916 KB |
#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=1;
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()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
860 KB |
Output is correct |
2 |
Correct |
22 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
1988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
3252 KB |
Output is correct |
2 |
Incorrect |
59 ms |
3156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
3416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
3916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |