이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |