제출 #1109476

#제출 시각아이디문제언어결과실행 시간메모리
1109476imarnBigger segments (IZhO19_segments)C++14
100 / 100
271 ms21320 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define plx pair<ll,int> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() #define vi vector<int> #define vvi vector<vi> #define pp pair<ll,int> #define ub(x,i) upper_bound(all(x),i)-x.begin() using namespace std; const int mxn=5e5+5; ll t[4*mxn]{0}; void build(int i,int l,int r){ if(l==r)return void(t[i]=1e16); int m=(l+r)>>1; build(2*i,l,m);build(2*i+1,m+1,r); t[i]=min(t[2*i],t[2*i+1]); } void upd(int i,int l,int r,int idx,ll v){ if(r<idx||l>idx)return; if(l==r)return void(t[i]=v); int m=(l+r)>>1; upd(2*i,l,m,idx,v);upd(2*i+1,m+1,r,idx,v); t[i]=min(t[2*i],t[2*i+1]); } pair<int,pii> qr(int i,int l,int r,int tr,ll tt){ if(l>tr)return {-1,{-1,-1}}; if(r<=tr&&t[i]<=tt)return {l,{r,i}}; if(r<=tr&&t[i]>tt)return {-1,{-1,-1}}; int m=(l+r)>>1; return max(qr(2*i,l,m,tr,tt),qr(2*i+1,m+1,r,tr,tt)); } int fi(int i,int l,int r,ll tt){ if(l==r)return l;int m=(l+r)>>1; if(t[2*i+1]<=tt)return fi(2*i+1,m+1,r,tt); return fi(2*i,l,m,tt); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n;cin>>n;build(1,0,n); ll a[n+1]={0};for(int i=1;i<=n;i++)cin>>a[i],a[i]+=a[i-1]; ll dp[n+1]={0};dp[0]=0;upd(1,0,n,0,0); for(int i=1;i<=n;i++){ pair<int,pii>rs=qr(1,0,n,i-1,a[i]); int r = fi(rs.s.s,rs.f,rs.s.f,a[i]); dp[i] = dp[r]+1; upd(1,0,n,i,2*a[i]-a[r]); }cout<<dp[n]; }

컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'int fi(int, int, int, long long int)':
segments.cpp:38:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   38 |     if(l==r)return l;int m=(l+r)>>1;
      |     ^~
segments.cpp:38:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   38 |     if(l==r)return l;int m=(l+r)>>1;
      |                      ^~~
#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...