【LOJbeta round1】ZQC的手办
NOI2012-超级钢琴的升级版。
用线段树维护最小值及其出现位置,接下来就跟超级钢琴一个做法了。
#include<bits/stdc++.h> #define N 500010 #define inf 1000000007 #define fi first #define sc second #define lson (o<<1) #define rson (o<<1|1) using namespace std; typedef long long ll; typedef pair<int,int> pir; inline int read(){ int f=1,x=0;char ch; do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9'); do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9'); return f*x; } int n,a[N],l,r,k,v; pir tmp; struct Segment_Tree{ pir minv[N<<2];int tagv[N<<2]; inline void puttag(int o,int v){ tagv[o]=max(tagv[o],v); minv[o].fi=max(minv[o].fi,v); } inline void pushdown(int o){ if(tagv[o]==0)return; puttag(lson,tagv[o]);puttag(rson,tagv[o]); tagv[o]=0; } inline void pushup(int o){minv[o]=min(minv[lson],minv[rson]);} void change(int o,int l,int r,int ql,int qr,int v){ if(ql<=l&&r<=qr){puttag(o,v);return;} pushdown(o);int mid=(l+r)>>1; if(ql<=mid)change(lson,l,mid,ql,qr,v); if(qr>mid)change(rson,mid+1,r,ql,qr,v); pushup(o); } pir query(int o,int l,int r,int ql,int qr){ if(ql<=l&&r<=qr)return minv[o]; pushdown(o);int mid=(l+r)>>1; pir ans=make_pair(inf,0); if(ql<=mid)ans=min(ans,query(lson,l,mid,ql,qr)); if(qr>mid)ans=min(ans,query(rson,mid+1,r,ql,qr)); return ans; } void build(int o,int l,int r){ if(l==r){minv[o]=make_pair(a[l],l);return;} int mid=(l+r)>>1; build(lson,l,mid);build(rson,mid+1,r); pushup(o); } }T; struct seg{int l,r;pir mv;}; bool operator <(seg a,seg b){return a.mv.fi>b.mv.fi;} priority_queue<seg> Q; int ans[N],top,q; inline void push(int l,int r){ if(l>r)return;pir tmp=T.query(1,1,n,l,r); if(tmp.fi>=k)return; Q.push((seg){l,r,tmp}); } int main(){ n=read(); for(int i=1;i<=n;i++)a[i]=read(); T.build(1,1,n); q=read(); while(q--){ int opt=read(); if(opt==1){ int l=read(),r=read(),v=read(); T.change(1,1,n,l,r,v); } else{ top=0;while(!Q.empty())Q.pop(); l=read(),r=read(),k=read(),v=read(); push(l,r); while(!Q.empty()){ seg tmp=Q.top();Q.pop(); ans[++top]=tmp.mv.fi; push(tmp.l,tmp.mv.sc-1);push(tmp.mv.sc+1,tmp.r); if(--v==0)break; } if(v==0){ sort(ans+1,ans+top+1); for(int i=1;i<=top;i++)printf("%d ",ans[i]);puts(""); } else puts("-1"); } } }
zzq wc-ctsc-apio-NOI Au;yql精通多项式;zyz精通女装;由乃精通数据结构;孔老师是毒奶大师;我没有学上:我们都有光明的前途。