이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int a[500009];
long long rs[500009];
pair<int,int> dp[500009];
struct node{
pair<int,int> v;
node *l,*r;
node():v({-1,0}),l(NULL),r(NULL){}
void up(long long s,long long e,long long x,pair<int,int> uv){
long long m = (s+e)/2;
if(s==e){
v = max(v,uv);return;
}
if(x>m){
if(r==NULL)r = new node();
r->up(m+1,e,x,uv);
}
else{
if(l==NULL)l = new node();
l->up(s,m,x,uv);
}
v = {-1,0};
if(r)v = max(v,r->v);
if(l)v = max(v,l->v);
}
pair<int,int> qu(long long s,long long e,long long x,long long y){
long long m = (s+e)/2;
if(s==x&&e==y)return v;
if(x>m){
if(r)return r->qu(m+1,e,x,y);
else return {-1,0};
}
if(y<=m){
if(l)return l->qu(s,m,x,y);
else return {-1,0};
}
pair<int,int> qv = {-1,0};
if(r)qv = max(qv,r->qu(m+1,e,m+1,y));
if(l)qv = max(qv,l->qu(s,m,x,m));
return qv;
}
}*root;
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
rs[i+1]=rs[i]+a[i];
}
root = new node();
root->up(0,(long long)5e14,0,{0,0});
for(int i=1;i<=n;i++){
pair<int,int> res = root->qu(0,(long long)5e14,0,rs[i]);
dp[i] = {res.first,rs[res.second] - rs[i]};
dp[i].first++;
root->up(0,(long long)5e14,rs[i] - dp[i].second,{dp[i].first,i});
//cout << dp[i].first << ' ' << dp[i].second << '\n';
// cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n';
}
printf("%d", dp[n].first);
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In function 'int main()':
segments.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
segments.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~| # | 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... |