# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
134846 |
2019-07-23T10:04:16 Z |
MvC |
Sails (IOI07_sails) |
C++11 |
|
108 ms |
2684 KB |
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "job.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const ll mod=1e9+7;
using namespace std;
int n,i,mx,tot,x,k,l,lb,r,rb,mid,fw[nmax];
pair<int,int>a[nmax];
ll ans;
void upd(int l,int r)
{
for(int i=l;i<=tot;i+=i&(-i))fw[i]++;
for(int i=r;i<=tot;i+=i&(-i))fw[i]--;
}
int qry(int i)
{
int rs=0;
for(;i>=1;i-=i&(-i))rs+=fw[i];
return rs;
}
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i].fr>>a[i].sc;
tot=max(tot,a[i].fr);
}
sort(a+1,a+n+1);
for(i=1;i<=n;i++)
{
mx=a[i].fr,k=a[i].sc;
//cout<<mx<<" "<<k<<endl;
upd(mx-k+1,mx+1);
if(mx-k+1>1 && qry(mx-k+1)>qry(mx-k))
{
x=qry(mx-k);
upd(mx+1,mx-k+1);
l=1,r=mx-k,lb=1;
while(l<=r)
{
mid=(l+r)/2;
if(qry(mid)>x)l=mid+1,lb=l;
else r=mid-1;
}
l=mx-k+1,r=mx,rb=mx;
while(l<=r)
{
mid=(l+r)/2;
if(qry(mid)<x)r=mid-1,rb=r;
else l=mid+1;
}
upd(lb,lb+(rb-(mx-k+1)+1));
upd(rb+1,mx+1);
//cout<<lb<<" "<<rb<<" "<<i<<endl;
}
}
for(i=1;i<=tot;i++)
{
x=qry(i);
ans+=1LL*x*1LL*(x-1);
}
ans/=2LL;
cout<<ans<<endl;
return 0;
}
Compilation message
sails.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
sails.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
632 KB |
Output is correct |
2 |
Correct |
24 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
1416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
2348 KB |
Output is correct |
2 |
Correct |
74 ms |
2272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
2472 KB |
Output is correct |
2 |
Correct |
62 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
2684 KB |
Output is correct |
2 |
Correct |
66 ms |
2296 KB |
Output is correct |