이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
struct Data{
ll f, s;
bool operator <(const Data &b){
return f < b.f || (f == b.f && s > b.s);
}
bool operator >(const Data &b){
return f > b.f || (f == b.f && s < b.s);
}
};
struct IPquery{
map<ll, Data> mp;
void insert(ll a, Data x){
auto it = mp.upper_bound(a);
if(it != mp.end() && it!=mp.begin() && prev(it)->second > x){
return;
}
it = mp.insert(it, {a, x});
it->second = x;
while(next(it) != mp.end() && next(it)->second < x){
mp.erase(next(it));
}
}
Data query(ll a){
auto it = mp.upper_bound(a);
return prev(it)->second;
}
};
void chmax(pair<ll, ll> &a, pair<ll, ll> b){
if(a.first < b.first){
a = b;
}else if(a.first == b.first){
if(a.second > b.second){
a = b;
}
}
}
void solve(){
int n;
cin >> n;
vector<ll> a(n+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
vector<ll> pf(n+1, 0);
for(int i = 1; i <= n; i++){
pf[i] = pf[i-1]+a[i];
}
auto sum = [&](int l, int r) -> ll{
return pf[r]-pf[l-1];
};
vector<Data> f(n+1, {-INF, 0});
f[0] = {0, 0};
IPquery T;
T.insert(0, {0, 0});
for(int i = 1; i <= n; i++){
f[i] = T.query(pf[i]);
f[i].f++;
f[i].s += pf[i];
T.insert(pf[i]+f[i].s, {f[i].f, -pf[i]});
}
cout << f[n].f;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("main.inp", "r", stdin);
//freopen("main.out", "w", stdout);
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In function 'void solve()':
segments.cpp:54:10: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
54 | auto sum = [&](int l, int r) -> ll{
| ^~~
# | 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... |