比赛 |
4043级2023省选练习赛2 |
评测结果 |
AAAAAAAAAA |
题目名称 |
排序 |
最终得分 |
100 |
用户昵称 |
zxhhh |
运行时间 |
9.361 s |
代码语言 |
C++ |
内存使用 |
8.55 MiB |
提交时间 |
2023-03-06 20:00:35 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, a[N], b[N];
int ql[N], qr[N], op[N], idx;
struct node {
int onum, znum, add;
}nodes[N << 2];
inline void push_up (int p) {
nodes[p].onum = nodes[p << 1].onum + nodes[p << 1 | 1].onum;
nodes[p].znum = nodes[p << 1].znum + nodes[p << 1 | 1].znum;
}
inline void upd (int p, int l, int r, int op) {
if(op == -1) return;
if (op == 1) nodes[p].znum = 0, nodes[p].onum = r - l + 1;
else nodes[p].onum = 0, nodes[p].znum = r - l + 1;
nodes[p].add = op;
}
inline void push_down (int p, int l, int r) {
if (nodes[p].add == -1) return;
int mid = (l + r) >> 1;
upd (p << 1, l, mid, nodes[p].add); upd (p << 1 | 1, mid + 1, r, nodes[p].add);
nodes[p].add = -1;
}
void build (int p, int l, int r) {
nodes[p].onum = nodes[p].znum = 0; nodes[p].add = -1;
if (l == r) {
if (b[l] == 0) nodes[p].znum++; else nodes[p].onum++;
return;
}
int mid = (l + r) >> 1;
build (p <<1, l, mid); build (p << 1 | 1, mid + 1, r);
push_up (p);
}
void update (int p, int l, int r, int tl, int tr, int x) {
if (tl > tr) return;
if (l >= tl && r <= tr) {
upd(p, l, r, x);
return;
}
push_down (p, l, r);
int mid = (l + r) >> 1;
if (tl <= mid) update (p << 1, l, mid, tl, tr, x);
if (tr > mid) update (p << 1 | 1, mid + 1, r, tl, tr, x);
push_up (p);
}
node query (int p, int l, int r, int tl, int tr) {
if (l >= tl && r <= tr) return nodes[p];
push_down (p, l, r);
int mid = (l + r) >> 1; node res; res.onum = res.znum = 0;
if (tl <= mid) {
node s = query(p << 1, l, mid, tl, tr);
res.onum += s.onum, res.znum += s.znum;
}
if (tr > mid) {
node s = query(p << 1 | 1, mid + 1, r, tl, tr);
res.onum += s.onum, res.znum += s.znum;
}
return res;
}
int check (int x) {
for (int i = 1;i <= n;i++) if (a[i] < x) b[i] = 0; else b[i] = 1;
build (1, 1, n);
// cout << x << " " << query(1, 1, n, 3, 6).znum << endl;
for (int i = 1;i <= m;i++) {
node s = query(1, 1, n, ql[i], qr[i]);
// cout << x <<" " << ql[i] <<" " << qr[i] <<" " << s.onum <<" " << s.znum << endl;
if (!op[i]) {
// cout << op[i] <<" "ql[i]
update (1, 1, n, ql[i], ql[i] + s.znum - 1, 0);
update (1, 1, n, ql[i] + s.znum, qr[i], 1);
}
else {
update (1, 1, n, ql[i], ql[i] + s.onum - 1, 1);
update (1, 1, n, ql[i] + s.onum, qr[i], 0);
}
}
node s = query(1, 1, n, idx, idx);
// cout <<x << endl;
// for (int i= 1;i <= n;i++) {
// node s = query(1, 1, n, i, i);
// cout << s.onum << " ";
// }
// cout << endl;
if (s.onum == 1) return 1;
return 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", &op[i], &ql[i], &qr[i]);
scanf("%d", &idx);
int l = 1, r = n;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (check(mid)) l = mid;
else r = mid - 1;
}
// for (int i = 1;i <= n;i++) cout << check(i) << endl;
// cout << check(3) << endl;
printf("%d\n", l);
return 0;
}