이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <int> pf(n + 2);
for ( int i = 0; i < n; i++ ){
int x; cin >> x;
pf[i + 1] = pf[i] + x;
}
vector <int> dp(n + 1), opt(n + 2);
for ( int i = 1; i <= n; i++ ){
if ( chmax(dp[i], dp[i - 1]) ){
opt[i] = opt[i - 1];
} else if ( dp[i] == dp[i - 1] ){
chmax(opt[i], opt[i - 1]);
}
dp[i] = dp[opt[i]] + 1;
int df = pf[i] * 2 - pf[opt[i]];
int l = i + 1, r = n + 1;
while ( l < r ){
int md = (l + r) >> 1;
if ( pf[md] < df ){
l = md + 1;
} else r = md;
}
if ( chmax(dp[l], dp[i] + 1) ){
opt[l] = i;
} else if ( dp[l] == dp[i] + 1 ){
chmax(opt[l], i);
}
}
cout << dp.back();
cout << '\n';
}
# | 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... |