結果

問題 No.3017 交互浴
ユーザー takoyaki782
提出日時 2025-07-14 17:27:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 1,490 bytes
コンパイル時間 4,885 ms
コンパイル使用メモリ 257,388 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-07-14 17:27:55
合計ジャッジ時間 32,026 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll inf_ll = 9223372036854775807;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using mint = atcoder::modint998244353;
using mint1 = atcoder::modint1000000007;
using Pa = std::pair<ll, ll>;

int Yes(bool x){
    if(x) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}

int main(){
    ll N;
    cin >> N;
    deque<Pa> A;
    deque<ll> B;
    vector<ll> ans(N);
    A.push_front({0, 2e9});
    B.push_front({0});
    rep(i, N){
        ll H;
        cin >> H;
        while(A.front().second <= H){
            A.pop_front();
            B.pop_front();
        }
        auto [a, b] = A.front();
        if(a == 0){
            if(i % 2 == 0){
                A.push_front({1, H});
                B.push_front(B.front());
            }
        }
        else{
            if(i % 2 == 0){
                chmax(H, b);
            }
            else{
                A.push_front({0, H});
                B.push_front({B.front() + b - H});
            }
        }
        if(i % 2 == 1){
            ans[i] = B.front();
        }
        else{
            ans[i] = B.front() + H;
        }
    }
    rep(i, N){
        cout << ans[i] << endl;
    }
}
0