比赛 4043级2023省选练习赛2 评测结果 AAAAAAAAAA
题目名称 排序 最终得分 100
用户昵称 op_组撒头屯 运行时间 7.843 s
代码语言 C++ 内存使用 13.63 MiB
提交时间 2023-03-06 19:36:22
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=100000+5;
int n,m; 
int a[N],pos;
struct segtree{
    int l,r,val,tag;
}tr[8*N];
struct sdf{
    int opt,l,r;
}q[N];
void pushup(int pt){
    tr[pt].val=tr[pt*2].val+tr[pt*2+1].val;
}
void build(int pt,int l,int r,int x){
    tr[pt]={l,r,0,-1};
    if (l==r){
        tr[pt].val=(a[l]>=x);return ;
    }int mid=(l+r)/2;
    build(pt*2,l,mid,x);build(pt*2+1,mid+1,r,x);
    pushup(pt);
}
void spread(int pt){
    if (!tr[pt].tag){
        tr[pt*2].val=tr[pt*2+1].val=0;
        tr[pt*2].tag=tr[pt*2+1].tag=0;
        tr[pt].tag=-1;
    }
    else if (tr[pt].tag==1){
        tr[pt*2].val=tr[pt*2].r-tr[pt*2].l+1;
        tr[pt*2+1].val=tr[pt*2+1].r-tr[pt*2+1].l+1;
        tr[pt*2].tag=tr[pt*2+1].tag=1;tr[pt].tag=-1;
    }
}
void change(int pt,int x,int y,int w){
    int l=tr[pt].l,r=tr[pt].r;
    if (x<=l&&r<=y){
        if (!w)tr[pt].val=0;
        else tr[pt].val=tr[pt].r-tr[pt].l+1;
        tr[pt].tag=w;return ;
    }
    spread(pt);int mid=(l+r)/2;
    if (x<=mid)change(pt*2,x,y,w);
    if (mid+1<=y)change(pt*2+1,x,y,w);
    pushup(pt);
}
int query(int pt,int x,int y){
    int l=tr[pt].l,r=tr[pt].r;
    if (x<=l&&r<=y)return tr[pt].val;
    spread(pt);int mid=(l+r)/2,ans=0;
    if (x<=mid)ans+=query(pt*2,x,y);
    if (mid+1<=y)ans+=query(pt*2+1,x,y);
    pushup(pt);return ans;
}
bool chck(int x){
    build(1,1,n,x);
    for (int i=1;i<=m;i++){
        int l=q[i].l,r=q[i].r,cnt=query(1,l,r);
        if (!q[i].opt)change(1,l,r-cnt,0),change(1,r-cnt+1,r,1);
        else change(1,l,l+cnt-1,1),change(1,l+cnt,r,0);
    }
    return query(1,pos,pos);
}
int main(){
	freopen ("heoi2016_sort.in","r",stdin);
	freopen ("heoi2016_sort.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=1;i<=m;i++)scanf("%d%d%d",&q[i].opt,&q[i].l,&q[i].r);
	scanf("%d",&pos);
	int l=1,r=n;
	while(l<r){
	    int mid=(l+r+1)/2;
	    if (chck(mid))l=mid;
	    else r=mid-1;
    }
    printf("%d\n",l);
}