Submission #971719

#TimeUsernameProblemLanguageResultExecution timeMemory
971719AiperiiiDivide and conquer (IZhO14_divide)C++14
100 / 100
159 ms25540 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; const int N=2e5+5; int t[N*4]; void build(int v,int tl,int tr){ t[v]=1e9; if(tl!=tr){ int tm=(tl+tr)/2; build(v*2,tl,tm); build(v*2+1,tm+1,tr); } } void update(int v,int tl,int tr,int pos,int x){ if(tl==tr)t[v]=min(t[v],x); else{ int tm=(tl+tr)/2; if(pos<=tm)update(v*2,tl,tm,pos,x); else update(v*2+1,tm+1,tr,pos,x); t[v]=min(t[v*2],t[v*2+1]); } } int get(int v,int tl,int tr,int l,int r){ if(tl>r or tr<l)return 1e9; if(l<=tl && tr<=r)return t[v]; int tm=(tl+tr)/2; return min(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r)); } signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n; cin>>n; vector <int> x(n+1),g(n+1),e(n+1),pre(n+1),prg(n+1); for(int i=1;i<=n;i++){ cin>>x[i]>>g[i]>>e[i]; } vector <int> v; for(int i=1;i<=n;i++){ pre[i]=pre[i-1]+e[i]; v.pb(pre[i]-x[i]); v.pb(pre[i-1]-x[i]); prg[i]=prg[i-1]+g[i]; } sort(all(v)); map <int,int> val_ind; int ind=1; for(int i=0;i<v.size();i++){ if(i==0 or v[i]!=v[i-1]){ val_ind[v[i]]=ind; ind++; } } ind--; int mx=0; build(1,1,ind); for(int i=1;i<=n;i++){ update(1,1,ind,val_ind[pre[i-1]-x[i]],i); int pos=get(1,1,ind,1,val_ind[pre[i]-x[i]]); mx=max(mx,prg[i]-prg[pos-1]); } cout<<mx<<"\n"; } /* 4 0 5 1 1 7 2 4 4 1 7 15 1 */

Compilation message (stderr)

divide.cpp: In function 'int main()':
divide.cpp:52:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...