https://loj.ac/problem/504

题解

对于区间取\(\max\),这个比较好办,直接在线段树上打标记就行了。

如果让我们弹出前\(n\)个数,我们可以用类似超级钢琴的思想,队列中每个元素是一个线段树节点,弹出时记录最值的位置,然后分成两半继续做就行了。

代码

#include<bits/stdc++.h>
#define N 500009
using namespace std;
typedef long long ll;
int n,a[N],m;
int tr[N<<2],pos[N<<2],la[N<<2];
int ans[N],top;
bool tag[N<<2];
inline ll rd(){ll x=0;char c=getchar();bool f=0;while(!isdigit(c)){if(c=='-')f=1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}return f?-x:x;
}
struct node{int nw,l,r;inline bool operator <(const node &b)const{return tr[nw]>tr[b.nw];}
};
priority_queue<node>q;
inline void pushup(int cnt){tr[cnt]=tr[cnt<<1];pos[cnt]=pos[cnt<<1];if(tr[cnt<<1|1]<tr[cnt])tr[cnt]=tr[cnt<<1|1],pos[cnt]=pos[cnt<<1|1];
}
inline void pushdown(int cnt){la[cnt<<1]=max(la[cnt<<1],la[cnt]);la[cnt<<1|1]=max(la[cnt<<1|1],la[cnt]);tr[cnt<<1]=max(tr[cnt<<1],la[cnt]);tr[cnt<<1|1]=max(tr[cnt<<1|1],la[cnt]);la[cnt]=0;
}
void build(int cnt,int l,int r){if(l==r){pos[cnt]=l;tr[cnt]=a[l];tag[cnt]=1;return;}int mid=(l+r)>>1;build(cnt<<1,l,mid);build(cnt<<1|1,mid+1,r);pushup(cnt);
}
void upd(int cnt,int l,int r,int L,int R,int x){if(l>=L&&r<=R){tr[cnt]=max(tr[cnt],x);la[cnt]=max(la[cnt],x);return;}int mid=(l+r)>>1;if(la[cnt])pushdown(cnt);if(mid>=L)upd(cnt<<1,l,mid,L,R,x);if(mid<R)upd(cnt<<1|1,mid+1,r,L,R,x);pushup(cnt);
}
void query(int cnt,int l,int r,int L,int R){if(l>=L&&r<=R){q.push(node{cnt,l,r});return;}int mid=(l+r)>>1;if(la[cnt])pushdown(cnt);if(mid>=L)query(cnt<<1,l,mid,L,R);if(mid<R)query(cnt<<1|1,mid+1,r,L,R);
}
int main(){n=rd();for(int i=1;i<=n;++i)a[i]=rd(); build(1,1,n);m=rd();int opt,l,r,k,x;while(m--){opt=rd();l=rd();r=rd();k=rd();if(opt==1){upd(1,1,n,l,r,k);}else{x=rd();while(!q.empty())q.pop();query(1,1,n,l,r);for(int i=1;i<=x;++i){if(q.empty())break;int cnt=q.top().nw;node y=q.top();q.pop();if(tr[cnt]>=k)break;ans[++top]=tr[cnt];if(tag[cnt])continue;pushdown(cnt);if(y.l<=pos[cnt]-1)query(cnt,y.l,y.r,y.l,pos[cnt]-1);if(pos[cnt]+1<=y.r)query(cnt,y.l,y.r,pos[cnt]+1,y.r);}if(top==x){for(int i=1;i<=top;++i)printf("%d ",ans[i]);puts("");}else puts("-1");top=0;}}return 0;
}

转载于:https://www.cnblogs.com/ZH-comld/p/11124263.html

LOJ504「LibreOJ β Round」ZQC 的手办相关推荐

  1. 「LibreOJ Round #11」Misaka Network 与求和(杜教筛 + Min_25)

    #572. 「LibreOJ Round #11」Misaka Network 与求和 推式子 ∑i=1n∑j=1nf(gcd(i,j))k∑d=1nf(d)k∑i=1nd∑j=1nd[gcd(i,j ...

  2. #530. 「LibreOJ β Round #5」最小倍数 二分 + 数论

    传送门 文章目录 题意: 思路: 题意: 思路: 本来想刷数位dpdpdp,无意间碰到了这个题来水水. 我们知道n!n!n!中质因子ppp的个数为∑i=1npi\sum_{i=1} \frac{n}{ ...

  3. [LOJ #521]「LibreOJ β Round #3」绯色 IOI(抵达)(结论)

    #521. 「LibreOJ β Round #3」绯色 IOI(抵达) description solution 因为点的庇护所不能为自身,题目背景在树上,有结论一定是两个相邻点互为庇护所 所以树一 ...

  4. LibreOJ545. 「LibreOJ β Round #7」小埋与游乐场【网络流】

    545. 「LibreOJ β Round #7」小埋与游乐场 [题目描述] 传送门 [题解] 网络流,我们发现lowbit之后相同的点连出的边是相同的,所以可以缩点. [代码如下] #include ...

  5. [LOJ#522]「LibreOJ β Round #3」绯色 IOI(危机)

    [LOJ#522]「LibreOJ β Round #3」绯色 IOI(危机) 试题描述 IOI 的比赛开始了.Jsp 和 Rlc 坐在一个角落,这时他们听到了一个异样的声音 -- 接着他们发现自己收 ...

  6. loj #535. 「LibreOJ Round #6」花火 树状数组求逆序对+主席树二维数点+整体二分...

    $ \color{#0066ff}{ 题目描述 }$ 「Hanabi, hanabi--」 一听说祭典上没有烟火,Karen 一脸沮丧. 「有的哦-- 虽然比不上大型烟花就是了.」 还好 Shinob ...

  7. 「LibreOJ β Round #2」计算几何瞎暴力

    https://loj.ac/problem/517 题解 首先我们如果没有排序这个骚操作的话,可以直接记一下各个数位的前缀和,然后异或标记给全局打,查询的时候先把区间信息提取出来然后整体异或就好了. ...

  8. 「LibreOJ β Round #4」子集

    https://loj.ac/problem/526 题目描述 qmqmqm有一个长为 n 的数列 a1,a2,--,an,你需要选择集合{1,2,--,n}的一个子集,使得这个子集中任意两个元素 i ...

  9. LOJ #516. 「LibreOJ β Round #2」DP 一般看规律

    题目描述 给定一个长度为 n 的序列 a,一共有 m 个操作. 每次操作的内容为:给定 x,y,序列中所有 x 会变成 y. 同时我们有一份代码: int ans = 2147483647; for ...

最新文章

  1. firefox html5 canvas,html5 Canvas
  2. nova hypervisor接口添加host_ip字段
  3. wxWidgets:wxStaticText类用法
  4. 投稿 | “轻量应用服务器”征文活动正式启动
  5. django 数据库中中文转化为汉语拼音
  6. LSGO软件技术团队2015~2016学年第十三周(1123~1129)总结
  7. 查询商品信息报错FreeMark template error
  8. 让整个网站变成灰色的做法
  9. Android-ViewPagerIndicator
  10. Java开发中图片压缩工具Thumbnailator
  11. Scrapy爬取makepolo网站数据深入详解
  12. Java基础(二)集合
  13. postMan中文修改
  14. 逻辑与() 逻辑或(||)
  15. 电脑可安装的超炫实用软件
  16. 第一个输出程序 Console.WriteLine
  17. CSDN日报20170407 ——《嘿,程序猿,你该学点经济学了!》
  18. Verilog实现4-bit行波进位加法器和超前进位加法器
  19. MT6763与MT6771是否可 以共用校准文件?
  20. 第五章 WebRTC, SIP和 Verto

热门文章

  1. Script:收集11g Oracle实例IO性能信息
  2. 查看Android API文档的正确方式
  3. Nodejs进阶:express+session实现简易身份认证
  4. Ajax实现的城市二级联动一
  5. 浅析I/O处理过程与存储性能的关系
  6. 权限的继承,取消继承,强制继承
  7. windows中PyCharm的安装和使用
  8. C++读取txt文件
  9. CIC滤波器的Matlab仿真与FPGA实现
  10. FPGA中block ram和distributed ram的区别