比赛 |
4043级2023省选练习赛2 |
评测结果 |
AAAAAAAAAA |
题目名称 |
排序 |
最终得分 |
100 |
用户昵称 |
yrtiop |
运行时间 |
7.091 s |
代码语言 |
C++ |
内存使用 |
9.35 MiB |
提交时间 |
2023-03-06 19:37:40 |
显示代码纯文本
#include <bits/stdc++.h>
const int maxn = 1e5 + 5;
struct Query {
int op,l,r;
Query() {
op = l = r = 0;
}
Query(int op,int l,int r):op(op),l(l),r(r){}
} Q[maxn];
int ls[maxn << 2],rs[maxn << 2],sum[maxn << 2],lz[maxn << 2],n,m,a[maxn],x,p;
void pushup(int i) {
return sum[i] = sum[i << 1] + sum[i << 1 | 1],void();
}
void pushdown(int i) {
if(~ lz[i])
sum[i << 1] = lz[i] * (rs[i << 1] - ls[i << 1] + 1),sum[i << 1 | 1] = lz[i] * (rs[i << 1 | 1] - ls[i << 1 | 1] + 1),
lz[i << 1] = lz[i << 1 | 1] = lz[i],lz[i] = -1;
return ;
}
void build(int i,int l,int r) {
ls[i] = l;
rs[i] = r;
lz[i] = -1;
if(l == r)
return sum[i] = a[l] >= x,void();
int mid = (l + r) >> 1;
build(i << 1 , l , mid);
build(i << 1 | 1 , mid + 1 , r);
pushup(i);
return ;
}
void modify(int i,int l,int r,int val) {
if(l > r)
return ;
if(ls[i] >= l&&rs[i] <= r)
return sum[i] = (lz[i] = val) * (rs[i] - ls[i] + 1),void();
if(ls[i] > r||rs[i] < l)
return ;
pushdown(i);
int mid = (ls[i] + rs[i]) >> 1;
if(l <= mid)
modify(i << 1 , l , r , val);
if(r > mid)
modify(i << 1 | 1 , l , r , val);
pushup(i);
return ;
}
int query(int i,int l,int r) {
if(ls[i] >= l&&rs[i] <= r)
return sum[i];
if(ls[i] > r||rs[i] < l)
return 0;
pushdown(i);
int mid = (ls[i] + rs[i]) >> 1,s = 0;
if(l <= mid)
s += query(i << 1 , l , r);
if(r > mid)
s += query(i << 1 | 1 , l , r);
return s;
}
bool calc() {
build(1 , 1 , n);
for(int i = 1;i <= m;++ i) {
int l = Q[i].l,r = Q[i].r,cnt = query(1 , Q[i].l , Q[i].r);
if(!Q[i].op) {
modify(1 , l , r - cnt , 0);
modify(1 , r - cnt + 1 , r , 1);
}
else {
modify(1 , l , l + cnt - 1 , 1);
modify(1 , l + cnt , r , 0);
}
}
return query(1 , p , p) > 0;
}
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].op,&Q[i].l,&Q[i].r);
scanf("%d",&p);
int l = 1,r = n;
while(l <= r) {
x = (l + r) >> 1;
if(calc())
l = x + 1;
else
r = x - 1;
}
printf("%d\n",r);
return 0;
}