제출 #1136155

#제출 시각아이디문제언어결과실행 시간메모리
1136155mnbvcxz123Bigger segments (IZhO19_segments)C++20
100 / 100
61 ms8264 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<long long> pref(N + 1); for(int i = 1; i <= N; ++i){ cin >> pref[i]; pref[i] += pref[i - 1]; } vector<int> dp(N + 1), pos(N + 1); for(int i = 1; i <= N; ++i){ pos[i] = max(pos[i], pos[i - 1]); dp[i] = dp[pos[i]] + 1; //(pos[i], i] <= (i, x] with x minimum //=> pref[i] - pref[pos[i]] <= pref[x] - pref[i] //=> 2 * pref[i] - pref[pos[i]]; <= pref[x] int ub = lower_bound(pref.begin(), pref.end(), 2 * pref[i] - pref[pos[i]]) - pref.begin(); if(ub < (int)pref.size()) pos[ub] = max(pos[ub], i); } cout << dp[N] << '\n'; 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...