제출 #1118662

#제출 시각아이디문제언어결과실행 시간메모리
1118662HuyATBigger segments (IZhO19_segments)C++14
0 / 100
1 ms2524 KiB
#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 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...