제출 #1121158

#제출 시각아이디문제언어결과실행 시간메모리
1121158IcelastBigger segments (IZhO19_segments)C++17
0 / 100
1 ms504 KiB
#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; it++; 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:55:10: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
   55 |     auto sum = [&](int l, int r) -> ll{
      |          ^~~
#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...