이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define newl '\n'
const int N = 5e5 + 10;
const int V = 1e7 + 10;
const long long S = 1e16;
const long long INF = 1e18;
const long long M = 1e9 + 7;
struct Node{
int ans;
long long s;
Node *l,*r;
Node() : ans(0),s(0),l(nullptr),r(nullptr){
}
Node(int ans,long long s) : ans(ans),s(s),l(nullptr),r(nullptr){
}
bool operator < (const Node &other){
return (ans < other.ans || (ans == other.ans && s > other.s));
}
};
int a[N + 1],n;
long long s[N + 1];
void readData(){
std::cin >> n;
for(int i = 1;i <= n;++i){
std::cin >> a[i];
s[i] = s[i - 1] + a[i];
}
}
int solve(){
std::map<long long,Node> m;
auto add = [&](long long pos,Node val){
auto it = m.lower_bound(pos);
if(it != m.end() || it->second < val){
return;
}
it = m.insert(it,{pos,val});
it->second = val;
while(next(it) != m.end() && val < next(it)->second){
m.erase(next(it));
}
};
auto query = [&](long long pos)-> Node{
auto it = m.upper_bound(pos);
return prev(it)->second;
};
add(0,Node());
int ans = 0;
for(int i = 1;i <= n;++i){
// std::cout << st.root->ans << newl;
Node t = query(s[i]);
ans = std::max(ans,t.ans + 1);
add(s[i] - t.s + s[i],Node(t.ans + 1,s[i]));
}
return ans;
}
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);std::cout.tie(nullptr);
readData();
std::cout << solve();
return 0;
}
# | 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... |