제출 #1105282

#제출 시각아이디문제언어결과실행 시간메모리
1105282ducanh1234수열 (APIO14_sequence)C++17
0 / 100
5 ms1104 KiB
#include<bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i <= (b); ++(i)) #define all(x) x.begin(), x.end() const int mxN = 1e5 + 6; int a[mxN], pre[mxN]; auto sumSegment(int l, int r) { return pre[r] - (l > 0 ? pre[l - 1] : 0); } auto getMidPos(int l, int r){ return lower_bound(pre + l, pre + r + 1, (l > 0 ? sumSegment(0, l - 1) : 0) + (sumSegment(l, r) / 2)) - pre; } auto maxPointInSeg(int l, int r){ int midPos = getMidPos(l, r); int64_t point = 1LL * sumSegment(l, midPos) * sumSegment(midPos + 1, r); assert(l != r); return point; } struct Segment{ int l, r; Segment(int _l, int _r): l(_l), r(_r) {} bool operator < (const Segment& other) const{ return maxPointInSeg(l, r) > maxPointInSeg(other.l, other.r); } }; void solve() { int n, k; cin >> n >> k; for(int i = 0; i < n; ++i){ cin >> a[i]; pre[i] = (i > 0 ? pre[i-1] : 0) + a[i]; } set<Segment> val; vector<int> pos; val.insert(Segment(0, n - 1)); int64_t ans = 0; for(int i = 1; i <= k; ++i){ auto [l, r] = *val.begin(); val.erase(val.begin()); ans += maxPointInSeg(l, r); auto midPos = getMidPos(l, r); pos.push_back(midPos+1); if(midPos > l) val.insert(Segment(l, midPos)); if(midPos + 1 < r) val.insert(Segment(midPos + 1, r)); } cout << ans << "\n"; for(auto& p : pos) cout << p << ' '; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...