hdu 5649 DZY Loves Sorting(二分+线段树)
来源:互联网 发布:bluestacks官网 mac 编辑:程序博客网 时间:2024/05/12 04:16
和bzoj 2653 middle 有点像
点击打开链接
#include <bits/stdc++.h>#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")#define LL long long #define pii pair<int, int>#define MP make_pair#define ls i << 1#define rs ls | 1#define md (ll + rr >> 1)#define lson ll, md, ls#define rson md + 1, rr, rs#define mod 1000000007#define inf 0x3f3f3f3f#define N 100020#define M 500010struct oper{ int ty, l, r; void input(){ scanf("%d%d%d", &ty, &l, &r); }};oper q[N];int n, op, k;int a[N], b[N], sum[N<<2], down[N<<2];void push_up(int i){ sum[i] = sum[ls] + sum[rs];}void push_down(int i, int ll, int rr){ if(down[i] != -1){ sum[ls] = (md - ll + 1) * down[i]; down[ls] = down[i]; sum[rs] = (rr - md) * down[i]; down[rs] = down[i]; down[i] = -1; }}void build(int ll, int rr, int i){ sum[i] = 0, down[i] = -1; if(ll == rr){ sum[i] = b[ll]; return ; } build(lson), build(rson); push_up(i);}void update(int l, int r, int v, int ll, int rr, int i){ if(l > r) return ; if(l <= ll && r >= rr){ sum[i] = (rr - ll + 1) * v; down[i] = v; return ; } push_down(i, ll, rr); if(r <= md) update(l, r, v, lson); else if(l > md) update(l, r, v, rson); else update(l, md, v, lson), update(md + 1, r, v, rson); push_up(i);}int query(int l, int r, int ll, int rr, int i){ if(l <= ll && r >= rr) return sum[i]; push_down(i, ll, rr); if(r <= md) return query(l, r, lson); else if(l > md) return query(l, r, rson); else return query(l, md, lson) + query(md + 1, r, rson);}bool check(int v){ for(int i = 1; i <= n; ++i) b[i] = a[i] > v ? 1 : 0; build(1, n, 1); for(int i = 0; i < op; ++i){ int ty = q[i].ty, l = q[i].l, r = q[i].r; int tot = query(l, r, 1, n, 1); if(ty){ update(l, l + tot - 1, 1, 1, n, 1); update(l + tot, r, 0, 1, n, 1); } else{ update(r - tot + 1, r, 1, 1, n, 1); update(l, r - tot, 0, 1, n, 1); } } return query(k, k, 1, n, 1);}int main(){ int cas; scanf("%d", &cas); while(cas--){ scanf("%d%d", &n, &op); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); for(int i = 0; i < op; ++i) q[i].input(); scanf("%d", &k); int L = 1, R = n; while(L < R){ int mid = (L + R) >> 1; if(!check(mid)) R = mid; else L = mid + 1; } printf("%d\n", L); } return 0;}
0 0
- hdu 5649 DZY Loves Sorting(二分+线段树)
- [HDU 5649] DZY Loves Sorting (线段树+二分)
- HDU 5649 DZY Loves Sorting(线段树+二分)
- HDU 5649 DZY Loves Sorting (二分 + 线段树)
- HDU5649 DZY Loves Sorting 二分+线段树
- 线段树+二分 hdu5649 DZY Loves Sorting
- HDU 5195 DZY Loves Topological Sorting(线段树)
- HDU 5195 DZY Loves Topological Sorting (拓扑排序+线段树)
- hdu 5195 DZY Loves Topological Sorting(线段树)
- [线段树] hdu5195 DZY Loves Topological Sorting
- HDU 5195 DZY Loves Topological Sorting(线段树单点更新)
- 【HDU】5195-DZY Loves Topological Sorting(拓扑 + 线段树 + 贪心)
- hdu5195 DZY Loves Topological Sorting 线段树+拓扑排序
- Hdoj 5195 DZY Loves Topological Sorting 【拓扑】+【线段树】
- HDU 5195 DZY Loves Topological Sorting
- hdu 5195 DZY Loves Topological Sorting
- HDU 5195 DZY Loves Topological Sorting
- HDU 5195 DZY Loves Topological Sorting
- 10分钟-jQuery与Ajax
- poj2342&hdu1520Anniversary party【树型dp模板题】
- nginx日志管理
- hdoj 1426 Sudoku Killer【数独】
- Buy Tickets
- hdu 5649 DZY Loves Sorting(二分+线段树)
- 基础知识之内存管理基础
- 利用js对象的特性去除数组和重复项
- 关于View的ScrollTo, getScrollX 和 getScrollY
- Hdu 2104 hide handkerchief
- JVM垃圾回收(GC 笔记)
- 三连击(升级版)
- GDOI2013 整数分拆
- Transfrom