結果
問題 |
No.1435 Mmm......
|
ユーザー |
|
提出日時 | 2024-12-11 09:31:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 1,194 bytes |
コンパイル時間 | 3,025 ms |
コンパイル使用メモリ | 253,612 KB |
実行使用メモリ | 26,712 KB |
最終ジャッジ日時 | 2024-12-11 09:31:26 |
合計ジャッジ時間 | 6,747 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 24 |
ソースコード
#ifndef LOCAL #include <bits/stdc++.h> using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif #include <atcoder/segtree> using dat = array<int64_t, 4>; const int64_t inf = (1 << 30) - 1; dat e() { return dat{inf, inf, inf * 2, 0}; } dat op(dat a, dat b) { if (a == e()) return b; if (b == e()) return a; array<int64_t, 4> c{a[0], a[1], b[0], b[1]}; sort(c.begin(), c.end()); return dat{c[0], c[1], c[0] + c[1], max(a[3], b[3])}; } void solve() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<dat> init(N, e()); for (int i = 0; i < N; i++) { init[i][0] = A[i]; init[i][2] = A[i] + inf; init[i][3] = A[i]; } atcoder::segtree<dat, op, e> seg(init); int64_t ans = 0; for (int i = 0; i < N; i++) { const auto f = [&](dat x) -> bool { return x[3] <= x[2]; }; int j = seg.min_left(i + 1, f); ans += i - j; } cout << ans << endl; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while (tt--) { solve(); } }