# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1011183 |
2024-06-30T04:27:27 Z |
doducanh |
Sails (IOI07_sails) |
C++14 |
|
86 ms |
3932 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()
{
// freopen("sail.inp","r",stdin);
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;
if(h==k)right=0;
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 |
344 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 |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
860 KB |
Output is correct |
2 |
Correct |
17 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
3240 KB |
Output is correct |
2 |
Correct |
59 ms |
3216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
3516 KB |
Output is correct |
2 |
Correct |
50 ms |
3152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
3932 KB |
Output is correct |
2 |
Correct |
53 ms |
3152 KB |
Output is correct |