結果

問題 No.3017 交互浴
ユーザー srjywrdnprkt
提出日時 2025-03-13 01:09:29
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,376 bytes
コンパイル時間 4,639 ms
コンパイル使用メモリ 296,472 KB
実行使用メモリ 31,116 KB
最終ジャッジ日時 2025-03-13 01:10:16
合計ジャッジ時間 39,404 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 WA * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/lazysegtree>

using namespace std;
using namespace atcoder;
using ll = long long;

using S = pair<ll, ll>;
using F = ll;
F ID = -1;
S op(S a, S b){ return {a.first + b.first, a.second + b.second}; }
S e(){ return {0, 0}; }
S mapping(F f, S x){
    if (f == ID) return x;
    else return {x.second*f, x.second};
}
F composition(F f, F g){
    if (f == ID) return g;
    else return f;
}
F id() {return ID;}

template <typename T>
void compress(vector<T> &A){

    map<T, T> comp;
    int N = A.size(), i=0;
    for (int i=0; i<N; i++) comp[A[i]];

    for (auto &e : comp){
        e.second = i;
        i++;
    }

    for (int i=0; i<N; i++) A[i] = comp[A[i]];
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll N;
    cin >> N;
    vector<ll> H(N+1), A;
    vector<S> v;
    H[0] = 1;
    for (int i=1; i<=N; i++) cin >> H[i];
    A = H;
    compress(H);
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    for (int i=0; i<A.size()-1; i++){
        v.push_back({0, A[i+1]-A[i]});
    }
    v.push_back({0, 1});

    lazy_segtree<S, op, e, F, mapping, composition, id> tree(v);

    for (int i=1; i<=N; i++){
        if (i % 2 == 1) tree.apply(0, H[i]+1, 1);
        else tree.apply(0, H[i]+1, 0);
        cout << tree.all_prod().first << endl;
    }

    return 0;
}
0