結果
| 問題 |
No.1525 Meximum Sum
|
| ユーザー |
|
| 提出日時 | 2021-05-26 20:19:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,023 bytes |
| コンパイル時間 | 7,708 ms |
| コンパイル使用メモリ | 254,636 KB |
| 最終ジャッジ日時 | 2025-01-21 18:36:58 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
struct S {
long long value;
int size;
};
using F = int;
S op(S a, S b) {
return {a.value + b.value, a.size + b.size};
}
S e() {
return {0, 1};
}
S mapping(F f, S x) {
if (f == -1) return x;
return {x.size * f, x.size};
}
F composition(F f, F g) {
if (f == -1) return g;
return f;
}
F id() {
return -1;
}
int main() {
int n;
cin >> n;
assert(1 <= n && n <= 200000);
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i], assert(1 <= a[i] && a[i] <= 1000000000);
atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(n);
long long ans = 0;
for (int i = 0; i < n; ++i) {
int l = 0, r = n;
while (r - l > 1) {
int m = (l + r) / 2;
if (seg.get(m).value < a[n - i - 1]) l = m;
else r = m;
}
seg.apply(n - i - 1, r, a[n - i - 1]);
ans += seg.prod(n - i - 1, n).value;
}
cout << ans << endl;
}