#include using namespace std; #if __has_include() #include using namespace atcoder; templateistream &operator>>(istream &is,static_modint &a){long long b;is>>b;a=b;return is;} istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;} #endif #ifdef LOCAL #include "debug.h" #else #define debug(...) static_cast(0) #define debugg(...) static_cast(0) templateostream &operator<<(ostream &os,const pair&p){os<; templateusing minque=priority_queue,greater>; templatebool chmax(T &a,const T &b){return (abool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} templateistream &operator>>(istream &is,pair&p){is>>p.first>>p.second;return is;} templateistream &operator>>(istream &is,vector &a){for(auto &i:a)is>>i;return is;} templatevoid operator++(pair&a,int n){a.first++,a.second++;} templatevoid operator--(pair&a,int n){a.first--,a.second--;} templatevoid operator++(vector&a,int n){for(auto &i:a)i++;} templatevoid operator--(vector&a,int n){for(auto &i:a)i--;} #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcountll(x) ll myceil(ll a,ll b){return (a+b-1)/b;} template auto vec(const int (&d)[n],const T &init=T()){ if constexpr (id(d,init)); else return init; } void SOLVE(); int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL clock_t start=clock(); #endif int testcase=1; //cin>>testcase; for(int i=0;i struct SegmentTreeBeats{ private: static constexpr T INF=numeric_limits::max()/2; struct node{ T sum; T mx,mx2,mn,mn2; int mxcnt,mncnt; node(T x):sum(x),mx(x),mx2(-INF),mn(x),mn2(INF),mxcnt(1),mncnt(1){} node():sum(0),mx(-INF),mx2(-INF),mn(INF),mn2(INF),mxcnt(0),mncnt(0){} }; struct F{ T chmax,chmin,add; F(T x,int id):chmax(-INF),chmin(INF),add(0){ if(id==0)chmin=x; else if(id==1)chmax=x; else if(id==2)add=x; else chmax=chmin=x; } F():chmax(-INF),chmin(INF),add(0){} }; int n,z,log2n; vectordat; vectorlazy; void update(int id){ node &ret=dat[id],&a=dat[id*2],&b=dat[id*2+1]; ret.sum=a.sum+b.sum; if(a.mx==b.mx){ ret.mx=a.mx; ret.mxcnt=a.mxcnt+b.mxcnt; ret.mx2=max(a.mx2,b.mx2); } else if(a.mxf.chmin){ if(x.mn>=f.chmin){ x.sum=(f.chmin+f.add)<<(__builtin_clz(id)+log2n-31); x.mx=x.mn=f.chmin+f.add; x.mxcnt=x.mncnt=1<<(__builtin_clz(id)+log2n-31); x.mx2=-1ll<<60,x.mn2=1ll<<60; return true; } if(x.mx2>=f.chmin)return false; x.sum-=x.mxcnt*(x.mx-f.chmin); x.mx=f.chmin; if(x.mn2>f.chmin)x.mn2=f.chmin; } x.sum+=f.add<<(__builtin_clz(id)+log2n-31); x.mx+=f.add; x.mx2+=f.add; x.mn+=f.add; x.mn2+=f.add; return true; } void composition(F f,F &g){ f.chmax-=g.add; f.chmin-=g.add; g.add+=f.add; if(f.chmin<=g.chmax)g.chmax=g.chmin=f.chmin; else if(f.chmax>=g.chmin)g.chmax=g.chmin=f.chmax; else{ if(g.chmaxf.chmin)g.chmin=f.chmin; } } void apply2(int id,F &f){ if(id=1;i--){ if(((l>>i)<>i); if(((r>>i)<>i); } int a=l,b=r; while(l>=1,r>>=1; } swap(a,l),swap(b,r); for(int i=1;i<=log2n;i++){ if(((l>>i)<>i); if(((r>>i)<>i); } } public: SegmentTreeBeats(vectora):n(a.size()),z(1),log2n(0){ while(z=1;i--)update(i); } inline void chmin(int l,int r,T x){apply(l,r,F(x,0));} inline void chmax(int l,int r,T x){apply(l,r,F(x,1));} inline void add(int l,int r,T x){apply(l,r,F(x,2));} inline void assign(int l,int r,T x){apply(l,r,F(x,3));} T sum(int l,int r){ l+=z,r+=z; for(int i=log2n;i>=1;i--){ if(((l>>i)<>i); if(((r>>i)<>i); } T ret=0; while(l>=1,r>>=1; } return ret; } }; void SOLVE(){ int n,m; cin>>n>>m; vectora(n); cin>>a; auto z(a); sort(all(z)),z.erase(unique(all(z)),z.end()); rep(i,n)a[i]=lower_bound(all(z),a[i])-z.begin(); SegmentTreeBeatsseg(vector(z.size(),-1)); int t; cin>>t; rep(i,t){ int l,r; cin>>l>>r; r++; l=lower_bound(all(z),l)-z.begin(); r=lower_bound(all(z),r)-z.begin(); seg.chmax(l,r,i+1); } rep(i,n)cout<