Submission #1050918

#TimeUsernameProblemLanguageResultExecution timeMemory
1050918Dennis_JasonSails (IOI07_sails)C++14
100 / 100
85 ms10092 KiB
#include <bits/stdc++.h> #define NMAX 250001 #define int long long #define pb push_back #define eb emplace_back #define MOD 1000000007 #define nl '\n' #define INF 1000000007 #define LLONG_MAX 9223372036854775807 #define pii pair<int,int> #define tpl tuple<int,int,int,int> #pragma GCC optimize("O3") using namespace std; ifstream fin("aib.in"); ofstream fout("aib.out"); int MAX=100000; vector<int>delta; class segtree{ private: int n; vector<int>before; vector<int>after; public: void init(int sz) { n=sz+1; before.resize(4*sz+1,-1); after.resize(4*sz+1,-1); update(0,MAX+1); } void update(int node,int st,int dr,int pos,int val) { if(st>pos || dr<=pos) return; if(st+1==dr) { delta[st]+=val; if(delta[st]) before[node]=after[node]=pos; else before[node]=after[node]=-1; return; } int mid=(st+dr)/2; update(2*node,st,mid,pos,val); update(2*node+1,mid,dr,pos,val); before[node]=(before[2*node+1]!=-1? before[2*node+1]:before[2*node]); after[node]=(after[2*node]!=-1? after[2*node]:after[2*node+1]); } int first_after(int node,int st,int dr,int L,int R) { if(st>=R || dr<=L) return -1; if(L<=st && dr<=R) { return after[node]; } int mid=(st+dr)/2; int left=first_after(2*node,st,mid,L,R); int right=first_after(2*node+1,mid,dr,L,R); int ans=(left!=-1? left:right); return ans; } int last_before(int node,int st,int dr,int L,int R) { if(st>=R || dr<=L) return -1; if(L<=st && dr<=R) { return before[node]; } int mid=(st+dr)/2; int left=last_before(2*node,st,mid,L,R); int right=last_before(2*node+1,mid,dr,L,R); int ans=(right!=-1? right:left); return ans; } void update(int pos,int val) { update(1,0,MAX+1,pos,val); } int first(int L,int R) { return first_after(1,0,MAX+1,L,R); } int last(int L,int R) { return last_before(1,0,MAX+1,L,R); } }; int n,max_h; vector<pii>v; segtree st; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; v.resize(n); for(int i=0;i<n;++i) { cin>>v[i].first>>v[i].second; max_h=max(max_h,v[i].first); } delta.resize(MAX); st.init(MAX); auto cmp=[&](pii a,pii b) { // if(a.first==b.first) // return a.second<b.second; return a.first<b.first; }; sort(v.begin(),v.end()); for(int i=0;i<n;++i) { int h0=v[i].first-v[i].second; int up=st.first(h0,MAX+1); int down=st.last(0,h0+1); if(up==-1) up=v[i].first; /*------------------DEBUG-------------------- cout<<v[i].first<<" "<<v[i].second<<": "<<nl; cout<<"h0 0-h0+1 h0-maxh+1"<<nl; cout<<h0<<" --- "<<down<<" --- "<<up<<nl<<nl; ------------------------------------------*/ st.update(v[i].first,1); st.update(up,-1); st.update(down+up-h0,1); st.update(down,-1); // for(int i=1;i<=max_h;++i) // { // cout<<delta[i]<<" "; // } // cout<<nl; } int ans=0,aux=0; for(int i=MAX;i>0;--i) { // cout<<delta[i]<<" "; aux+=delta[i]; ans+=(aux*(aux-1))/2; } cout<<ans; return 0; }

Compilation message (stderr)

sails.cpp:10: warning: "LLONG_MAX" redefined
   10 | #define LLONG_MAX 9223372036854775807
      | 
In file included from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:195,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:34,
                 from /usr/include/c++/10/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
                 from sails.cpp:1:
/usr/include/limits.h:135: note: this is the location of the previous definition
  135 | #  define LLONG_MAX __LONG_LONG_MAX__
      | 
sails.cpp: In function 'int main()':
sails.cpp:113:10: warning: variable 'cmp' set but not used [-Wunused-but-set-variable]
  113 |     auto cmp=[&](pii a,pii b)
      |          ^~~
#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...