結果
問題 | No.2650 [Cherry 6th Tune *] セイジャク |
ユーザー |
|
提出日時 | 2024-02-23 21:51:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 734 ms / 2,500 ms |
コード長 | 2,935 bytes |
コンパイル時間 | 2,975 ms |
コンパイル使用メモリ | 217,548 KB |
最終ジャッジ日時 | 2025-02-19 19:43:55 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h>using namespace std;using SS = int;using FF = int;class LazySegmentTree{public:int siz = 1;vector<SS> dat;vector<FF> lazy;FF ID = -2;SS op(SS a,SS b){return max(a,b);}SS mapping(FF f, SS x){return max(f,x);}FF composition(FF f, FF g){if(f == ID) return g;if(g == ID) return f;return f;}SS e(){return -2;}FF id(){return ID;}//op区間演算 mapping lazy→data composition lazy→lazy//e 単位元 id map(id,a)=avoid 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(lazy.at(u) != id()){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,A; cin >> N >> A;vector<long long> all;vector<long long> X(N);for(auto &x : X) cin >> x;all = X;int T; cin >> T;vector<pair<long long,long long>> LR(T);for(auto &[l,r] : LR) cin >> l >> r,all.push_back(l),all.push_back(r);sort(all.begin(),all.end());all.erase(unique(all.begin(),all.end()),all.end());map<int,int> name;int n = 0;for(auto a : all) name[a] = n,n++;LazySegmentTree Z; Z.make(n);for(int i=0; i<T; i++){auto [l,r] = LR.at(i);l = name[l],r = name[r];Z.update(l,r+1,i);}for(auto x : X){x = name[x];int now = Z.get(x);cout << now+1 << endl;}}