Submission #374124

#TimeUsernameProblemLanguageResultExecution timeMemory
374124mariowongBigger segments (IZhO19_segments)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> #define int long long #define push_back emplace_back #define push_front emplace_front #define pii pair<int,int> #define ff first #define ss second using namespace std; #define debug(args...) kout("[ " + string(#args) + " ]", args) void kout() { cerr << endl; } template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); } template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; } const int MAXN = 500000; int n; int a[MAXN+1]; int pre[MAXN+1]; int dp[MAXN+1]; int len[MAXN+1]; deque <pii> deq; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], pre[i] = pre[i-1] + a[i]; deq.push_back(0, 0); pii tmp; for (int i = 1; i <= n; i++) { while (deq.size() && pre[i]-pre[deq.front().ss] >= deq.front().ff) { dp[i] = dp[deq.front().ss] + 1; tmp = deq.front(); deq.pop_front(); } deq.push_front(tmp); while (deq.size() && deq.back().ff >= pre[i]-pre[deq.front().ss]) deq.pop_back(); deq.push_back(pre[i]-pre[deq.front().ss], i); } cout << dp[n] << '\n'; }
#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...