이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Node{
pair<int,int>val;
ll l, r;
Node*left;
Node*right;
Node(ll _l, ll _r) {
val={0,0};
l=_l;
r=_r;
left=nullptr;
right=nullptr;
}
};
void update(Node *root, ll p, int x, int y) {
if(root->l==p && root->r==p){
root->val=max(make_pair(x,y),root->val);
return;
}
ll m=(root->l+root->r)/2;
if(root->l<=p&&p<=m){
if(root->left==nullptr){
root->left=new Node(root->l,m);
}
update(root->left,p,x,y);
}
else{
if(root->right==nullptr){
root->right=new Node(m+1,root->r);
}
update(root->right,p,x,y);
}
}
pair<int,int> get(Node *root, ll l, ll r){
if(l>root->r || root->l>r) {
return {0,0};
}
if(l<=root->l && root->r<=r){
return root->val;
}
pair<int,int> ans={0,0};
if(root->right!=nullptr){
ans=max(ans,get(root->right,l,r));
}
if(root->left!=nullptr){
ans=max(ans,get(root->left,l,r));
}
return ans;
}
int main() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector<ll>pr(n+1);
for(int i=0;i<n;i++)pr[i+1]=pr[i]+a[i];
vector<int>ans(n);
vector<ll> ans_sum(n);
ll sum=0;
for(int i=0;i<n;i++){
sum+=a[i];
ans_sum[i]=sum;
ans[i]=1;
}
Node *tree=new Node(0,1e15);
for(int i=1;i<n;i++){
for(int j=i-1;j>=0;j--){
if(pr[i+1]>=ans_sum[j]+pr[j+1]){
if(ans[i]<ans[j]+1){
ans[i]=ans[j]+1;
ans_sum[i]=pr[i+1]-pr[j+1];
}
}
}
/*auto t=get(tree,0,pr[i+1]);
ans[i]=t.first+1;
ans_sum[i]=pr[i+1]-pr[t.second];
update(tree,ans_sum[i]+pr[i],ans[i],i); */
}
cout<<ans[n-1];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In function 'int main()':
segments.cpp:73:8: warning: unused variable 'tree' [-Wunused-variable]
Node *tree=new Node(0,1e15);
^~~~
# | 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... |