标签:print amp ring mat efi uil pushd for char s
/*
//fang zhi luan ma er xie E and C hun xue
yi kai shi que shi mei kan chu lai dan diao xing
mo bu shi zai jia wo
ran hou guo duan liang fa ti jie hou hai shi kan bu chu dan xiao xing
na jiou zai lai yi fa ti jie
interesting
yuan lai check han shu shi zhe yang de ya
23333
I konw
bing bu shi zhi jie pan duan zhe ge mid shi bu shi ans
er shi check zhe ge mid he ans de da xiao guan xi
other:
yuan lai seg tree hai ke yi qu jian fu zhi me
interesting
xian duan tree tql
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const int maxn = 1e5 + 7;
const int maxm = 4e5 + 7;
int n, m, k, a[maxn], b[maxn], S[maxn], T[maxn];;
// lazy is first 1 space
int sum[maxm], lazy[maxn];
bool is_up_down[maxn];
int read() {
int x = 0, f = 1; char s = getchar();
for (; s < '0' || s > '9'; s = getchar()) if (s == '-') f = -1;
for (; s >= '0' && s <= '9'; s = getchar()) x = x * 10 + s - '0';
return x * f;
}
void pushup(int rt) {
sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
void pushdown(int rt, int lsize, int rsize) {
if (lazy[rt] != -1) {
lazy[rt << 1] = lazy[rt];
lazy[rt << 1 | 1] = lazy[rt];
sum[rt << 1] = lazy[rt] * lsize;
sum[rt << 1 | 1] = lazy[rt] * rsize;
lazy[rt] = -1;
}
}
void build(int l, int r, int rt) {
if (l == r) {
sum[rt] = b[l];
return;
}
int mid = (l + r) >> 1;
build(lson);
build(rson);
pushup(rt);
}
void update(int L, int R, int k, int l, int r, int rt) {
if (L > R) return;
if (L <= l && r <= R) {
sum[rt] = k * (r - l + 1);
lazy[rt] = k;
return;
}
int mid = (l + r) >> 1;
pushdown(rt, mid - l + 1, r - mid);
if (L <= mid) update(L, R, k, lson);
if (R > mid) update(L, R, k, rson);
pushup(rt);
}
int query(int L, int R , int l, int r, int rt) {
if (L > R) return 0;
if (L <= l && r <= R) {
return sum[rt];
}
int mid = (l + r) >> 1;
pushdown(rt, mid - l + 1, r - mid );
int ans = 0;
if (L <= mid) ans += query(L, R, lson);
if (R > mid) ans += query(L, R, rson);
pushup(rt);
return ans;
}
bool check(int x) {
memset(sum, 0, sizeof(sum));
memset(lazy, -1, sizeof(lazy));
for (int i = 1; i <= n; ++i)
b[i] = (a[i] >= x ? 1 : 0);//, cout << b[i] << " "; printf("\n");
build(root);
for (int i = 1; i <= m; ++i) {
int size = query(S[i], T[i], root);
if (is_up_down[i]) {
if(size)
update(S[i], S[i] + size - 1, 1, root);
if(size!=(T[i]-S[i]+1))
update(S[i] + size, T[i], 0, root);
} else {
if(size!=(T[i]-S[i]+1))
update(S[i], T[i] - size, 0, root);
if(size)
update(T[i] - size + 1, T[i], 1, root);
}
// printf("debug\n");
// if(is_up_down[i])
// printf("%d -> %d\n", S[i], T[i]);
// else
// printf("%d <- %d\n", S[i], T[i]);
// printf("size=%d\n", size);
// if (is_up_down[i]) {
// printf("%d %d %d\n", S[i], S[i] + size - 1, 1);
// printf("%d %d %d\n", S[i] + size, T[i], 0);
// } else {
// printf("%d %d %d\n", S[i], T[i] - size, 0);
// printf("%d %d %d\n", T[i] - size + 1, T[i], 1);
// }
// printf("become\n");
// for (int i = 1; i <= n; ++i)
// printf("%d ", query(i, i, root));
// printf("\n");
}
// printf("debug1 all=%d\n", query(1, n, root));
return query(k, k, root);
}
int main() {
//freopen("a.in", "r", stdin);
n = read(), m = read();
for (int i = 1; i <= n; ++i) {
a[i] = read();
}
for (int i = 1; i <= m; ++i) {
is_up_down[i] = read(), S[i] = read(), T[i] = read();
if(S[i] > T[i]) swap(S[i],T[i]);
}
k = read();
int l = 0, r = 1e7, ans = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) ans = mid, l = mid + 1;
else r = mid - 1;
}
printf("%d\n", ans);
return 0;
}
标签:print amp ring mat efi uil pushd for char s
原文地址:https://www.cnblogs.com/lovedsr/p/9745982.html