Submission #295838

#TimeUsernameProblemLanguageResultExecution timeMemory
295838HemimorSails (IOI07_sails)C++14
100 / 100
255 ms3960 KiB
#include <algorithm> #include <iostream> #include <iomanip> #include <numeric> #include <cassert> #include <vector> #include <cmath> #include <queue> #include <set> #include <map> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<P,int> pip; typedef vector<pip> vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=1e9+7; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; class Lazy_Segment_Tree{ private: int n; vi date,lazy; void Set_Lazy(int k,int x){ date[k]+=x; lazy[k]+=x; } void Push(int k){ Set_Lazy(k*2+1,lazy[k]); Set_Lazy(k*2+2,lazy[k]); lazy[k]=0; } void Fix(int k){ date[k]=min(date[k*2+1],date[k*2+2]); } void Add_func(int a,int b,int k,int l,int r){ if(r<=a||b<=l) return; if(a<=l&&r<=b){ Set_Lazy(k,1); return; } Push(k); int m=(l+r)/2; Add_func(a,b,k*2+1,l,m); Add_func(a,b,k*2+2,m,r); Fix(k); } public: Lazy_Segment_Tree(int n_){ n=1; while(n<n_) n*=2; date=lazy=vi(2*n-1); } void Add(int a,int b){ if(a==b) return; Add_func(a,b,0,0,n); } int Query(int x){ int k=0; while(k<n-1){ Push(k); // if(x==-1) cout<<k<endl; if(date[k*2+1]>x) k=2*k+2; else k=2*k+1; } return k-n+1; } int Open(int k){ k+=n-1; int res=date[k]; while(k>0){ k=(k-1)/2; res+=lazy[k]; } return res; } ll Res(){ for(int i=0;i<n-1;i++) Push(i); ll t=0; for(int i=0;i<n;i++){ ll x=date[i+n-1]; t+=x*(x-1)/2; } return t; } }; const int M=1e5; int n; vp a; int main(){ Lazy_Segment_Tree st(M); cin>>n; a=vp(n); for(int i=0;i<n;i++) cin>>a[i].first>>a[i].second; sort(a.begin(),a.end()); for(auto p:a){ int h=p.first,x=p.second; int t=st.Open(h-x),l=st.Query(t),r=min(h,st.Query(t-1)); st.Add(l,x-h+r+l); st.Add(r,h); } cout<<st.Res()<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...