結果
問題 | No.3017 交互浴 |
ユーザー |
|
提出日時 | 2025-01-25 13:09:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 286 ms / 2,000 ms |
コード長 | 3,166 bytes |
コンパイル時間 | 2,383 ms |
コンパイル使用メモリ | 209,784 KB |
実行使用メモリ | 12,680 KB |
最終ジャッジ日時 | 2025-01-25 22:34:48 |
合計ジャッジ時間 | 19,479 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename T> vector<T> zaatu(vector<T> &A){ //座標圧縮=Compress. vector<T> B = A; sort(B.begin(),B.end()); B.erase(unique(B.begin(),B.end()),B.end()); for(auto &a : A) a = lower_bound(B.begin(),B.end(),a)-B.begin(); return B; } using SS = pair<int,int>; using FF = int; class LazySegmentTree{ public: int siz = 1; vector<SS> dat; vector<FF> lazy; FF ID = -1; SS op(SS a,SS b){return {a.first+b.first,a.second+b.second};} SS mapping(FF f, SS x){ if(f == -1) return x; return {x.second*f,x.second}; } FF composition(FF f, FF g){ if(f == -1) return g; if(g == -1) return f; return f; } SS e(){return {0,0};} FF id(){return ID;} //op区間演算 mapping lazy→data composition lazy→lazy //e 単位元 id map(id,a)=a void make(int N){ while(siz < N) siz *= 2; dat.resize(siz*2,e()); lazy.resize(siz*2,ID); } void make2(int N,vector<SS> &A){ make(N); for(int i=0; i<N; i++){ int pos = i+siz-1; dat.at(pos) = A.at(i); } for(int i=siz-2; i>=0; i--) dat.at(i) = op(dat.at(i*2+1),dat.at(i*2+2)); } void eval(int u,int a,int b){ if(id() != lazy.at(u)){ dat.at(u) = mapping(lazy.at(u),dat.at(u)); if(b-a > 1){ lazy.at(u*2+1) = composition(lazy.at(u),lazy.at(u*2+1)); lazy.at(u*2+2) = composition(lazy.at(u),lazy.at(u*2+2)); } lazy.at(u) = id(); } } void findadd(int L,int R,int a,int b,int u,FF x){ eval(u,a,b); if(R <= a || b <= L) return; if(L <= a && b <= R){ lazy.at(u) = composition(x,lazy.at(u)); eval(u,a,b); } else{ findadd(L,R,a,(a+b)/2,u*2+1,x); findadd(L,R,(a+b)/2,b,u*2+2,x); dat.at(u) = op(dat.at(u*2+1),dat.at(u*2+2)); } } void update(int L,int R,FF x){findadd(L,R,0,siz,0,x);} SS findans(int L,int R,int a,int b,int u){ if(R <= a || b <= L) return e(); eval(u,a,b); if(L <= a && b <= R) return dat.at(u); return op(findans(L,R,a,(a+b)/2,u*2+1),findans(L,R,(a+b)/2,b,u*2+2)); } SS get(int pos){return findans(pos,pos+1,0,siz,0);} SS rangeans(int l,int r){return findans(l,r,0,siz,0);} SS allrange(){return findans(0,siz,0,siz,0);} }; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> H(N); for(auto &h : H) cin >> h; auto H2 = H; sort(H2.begin(),H2.end()); H2.erase(unique(H2.begin(),H2.end()),H2.end()); int n = H2.size(); vector<SS> give; { int x = 0; for(int i=0; i<n; i++) give.push_back({0,H2.at(i)-x}),x = H2.at(i); } LazySegmentTree Z; Z.make2(n,give); bool cyan = true; for(auto &h : H){ h = lower_bound(H2.begin(),H2.end(),h)-H2.begin(); Z.update(0,h+1,cyan); cout << Z.allrange().first << "\n"; cyan ^= 1; } }