結果

問題 No.3017 交互浴
ユーザー srjywrdnprkt
提出日時 2025-03-13 01:14:52
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 797 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 4,606 ms
コンパイル使用メモリ 294,220 KB
実行使用メモリ 30,704 KB
最終ジャッジ日時 2025-03-13 01:15:41
合計ジャッジ時間 43,848 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

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());
v.push_back({0, 1});
for (int i=1; i<A.size(); i++){
v.push_back({0, A[i]-A[i-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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0