WA 0pts求调
查看原帖
WA 0pts求调
477821
toolong114514楼主2023/12/30 19:00
#include<algorithm>
#include<iostream>
using namespace std;
const int N=1e5+10;
struct node{
	int l,r,cnt1,laz;
}tree[4*N];
int tnum;
int a[N];
void build(int pos,int lft,int rgt){
	tree[pos].laz=-1;
	tree[pos].l=lft;
	tree[pos].r=rgt;
	if(lft==rgt){
		if(a[lft]>=tnum) tree[pos].cnt1=1;
		return;
	}
	int mid=(lft+rgt)/2;
	build(pos*2,lft,mid);
	build(pos*2+1,mid+1,rgt);
	tree[pos].cnt1=tree[pos*2].cnt1+tree[pos*2+1].cnt1;
}
void push_down(int pos){
	if(tree[pos].laz==1){
		tree[pos*2].cnt1=(tree[pos*2].r-tree[pos*2].l+1);
		tree[pos*2+1].cnt1=(tree[pos*2+1].r-tree[pos*2+1].l+1);
		tree[pos*2].laz=1;
		tree[pos*2+1].laz=1;
	}
	if(tree[pos].laz==0){
		tree[pos*2].cnt1=0;
		tree[pos*2+1].cnt1=0;
		tree[pos*2].laz=0;
		tree[pos*2+1].laz=0;
	}
	tree[pos].laz=-1; 
}
void sgfill(int pos,int lft,int rgt,bool is_1){
	if(lft<=tree[pos].l&&tree[pos].r<=rgt){
		if(is_1){
			tree[pos].cnt1=(tree[pos].r-tree[pos].l+1);
			tree[pos].laz=1;
		}else{
			tree[pos].cnt1=0;
			tree[pos].laz=0;
		}
		return; 
	}
	if(rgt<tree[pos].l||tree[pos].r<lft) return;
	push_down(pos);
	sgfill(pos*2,lft,rgt,is_1);
	sgfill(pos*2+1,lft,rgt,is_1);
	tree[pos].cnt1=tree[pos*2].cnt1+tree[pos*2+1].cnt1;
}
int ask(int pos,int lft,int rgt){
	if(lft<=tree[pos].l&&tree[pos].r<=rgt) return tree[pos].cnt1;
	if(rgt<tree[pos].l||tree[pos].r<lft) return 0;
	push_down(pos); 
	return ask(pos*2,lft,rgt)+ask(pos*2+1,lft,rgt);
}
struct ccf{
	int op,ll,rr;
}opr[N];
int b[N];
int n,m,q,ans;
bool check(int x){
	tnum=x;
	build(1,1,n);
	for(int i=1;i<=m;i++){
		int tmp=ask(1,opr[i].ll,opr[i].rr);
		if(opr[i].op==0){
			sgfill(1,opr[i].ll,opr[i].rr-tmp,false);
			sgfill(1,opr[i].rr-tmp+1,opr[i].rr,true);
		}else{
			sgfill(1,opr[i].ll,opr[i].ll+tmp-1,true);
			sgfill(1,opr[i].ll+tmp,opr[i].rr,false);
		}
	}
	return ask(1,q,q);
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	for(int i=1;i<=m;i++){
		cin>>opr[i].op>>opr[i].ll>>opr[i].rr;
	}
	cin>>q;
	sort(b+1,b+n+1);
	int L=1,R=n;
	while(L<=R){
		int mid=(L+R)/2;
		if(check(b[mid])){
			ans=b[mid];
			L=mid+1;
		}else{
			R=mid-1;
		}
	}
	cout<<ans;
	return 0;	
}
2023/12/30 19:00
加载中...