CRB and Queries

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 533    Accepted Submission(s): 125

Problem Description
There are N boys in CodeLand.
Boy i has his coding skill Ai.
CRB wants to know who has the suitable coding skill.
So you should treat the following two types of queries.
Query 1: 1 l v
The coding skill of Boy l has changed to v.
Query 2: 2 l r k
This is a report query which asks the k-th smallest value of coding skill between Boy l and Boy r(both inclusive).

Input
There are multiple test cases.
The first line contains a single integer N.
Next line contains N space separated integers A1, A2, …, AN, where Ai denotes initial coding skill of Boy i.
Next line contains a single integer Q representing the number of queries.
Next Q lines contain queries which can be any of the two types.
1 ≤ N, Q ≤ 105
1 ≤ Ai, v ≤ 109
1 ≤ l ≤ r ≤ N
1 ≤ k ≤ r – l + 1

Output
For each query of type 2, output a single integer corresponding to the answer in a single line.

Sample Input
5
1 2 3 4 5
3
2 2 4 2
1 3 6
2 2 4 2

Sample Output
3
4

Author
KUT(DPRK)

Source

解题:带修改的区间K大查询

 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
const int INF = 0x3f3f3f3f;
struct QU {
int x,y,k,id,d;
} Q[maxn],A[maxn],B[maxn];
int a[maxn],c[maxn],ans[maxn],tot;
void add(int i,int val) {
while(i < maxn) {
c[i] += val;
i += i&-i;
}
}
int sum(int i,int ret = ) {
while(i > ) {
ret += c[i];
i -= i&-i;
}
return ret;
}
void solve(int lt,int rt,int L,int R) {
if(lt > rt) return;
if(L == R) {
for(int i = lt; i <= rt; ++i)
if(Q[i].id) ans[Q[i].id] = L;
return;
}
int mid = (L + R)>>,a = ,b = ;
for(int i = lt; i <= rt; ++i) {
if(Q[i].id) {
int tmp = sum(Q[i].y) - sum(Q[i].x-);
if(Q[i].d + tmp >= Q[i].k) A[a++] = Q[i];
else {
Q[i].d += tmp;
B[b++] = Q[i];
}
} else if(Q[i].y <= mid) {
add(Q[i].x,Q[i].d);
A[a++] = Q[i];
} else B[b++] = Q[i];
}
for(int i = lt; i <= rt; ++i)
if(!Q[i].id && Q[i].y <= mid) add(Q[i].x,-Q[i].d);
for(int i = ; i < a; ++i) Q[lt + i] = A[i];
for(int i = ; i < b; ++i) Q[lt + a + i] = B[i];
solve(lt,lt + a - ,L,mid);
solve(lt + a,rt,mid + ,R);
}
int main() {
int n,m,cnt,x,y;
while(~scanf("%d",&n)) {
memset(c,,sizeof c);
cnt = tot = ;
for(int i = ; i <= n; ++i) {
scanf("%d",a + i);
Q[++tot].y = a[i];
Q[tot].x = i;
Q[tot].id = ;
Q[tot].d = ;
}
scanf("%d",&m);
for(int i = ,op; i <= m; ++i) {
scanf("%d",&op);
if(op == ) {
tot++;
scanf("%d%d%d",&Q[tot].x,&Q[tot].y,&Q[tot].k);
Q[tot].id = ++cnt;
Q[tot].d = ;
} else {
scanf("%d%d",&x,&y);
Q[++tot].x = x;
Q[tot].y = a[x];
Q[tot].id = ;
Q[tot].d = -; Q[++tot].x = x;
Q[tot].y = a[x] = y;
Q[tot].id = ;
Q[tot].d = ;
}
}
solve(,tot,,INF);
for(int i = ; i <= cnt; ++i)
printf("%d\n",ans[i]);
}
return ;
}

2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries的更多相关文章

  1. 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple

    CRB and Apple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  2. 2015 Multi-University Training Contest 10 hdu 5411 CRB and Puzzle

    CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  3. 2015 Multi-University Training Contest 10 hdu 5407 CRB and Candies

    CRB and Candies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. HDU 5412 CRB and Queries(区间第K大 树套树 按值建树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5412 Problem Description There are N boys in CodeLan ...

  5. HDU 5412——CRB and Queries——————【线段树套Treap(并没有AC)】

    CRB and Queries Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  6. hdu 5412 CRB and Queries

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5412 CRB and Queries Description There are $N$ boys i ...

  7. 2016 Multi-University Training Contest 10 || hdu 5860 Death Sequence(递推+单线约瑟夫问题)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 题目大意:给你n个人排成一列编号,每次杀第一个人第i×k+1个人一直杀到没的杀.然后 ...

  8. 2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树:区间覆盖+单点最大小)

    HDU 5861 题意 在n个村庄之间存在n-1段路,令某段路开放一天需要交纳wi的费用,但是每段路只能开放一次,一旦关闭将不再开放.现在给你接下来m天内的计划,在第i天,需要对村庄ai到村庄bi的道 ...

  9. HDU 5412 CRB and Queries 动态整体二分

    Problem Description There are N boys in CodeLand.Boy i has his coding skill Ai.CRB wants to know who ...

随机推荐

  1. A. Music(Codeforces Round #315 (Div. 2) 求最大的容纳量)

    A. Music time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  2. 文字录入无限制Undo,Redo的实现

    这里只针对Edit的内容做一个简单的undo,redo功能: 原理就是,将新增字符和相关信息添加到undo列表,在undo动作时,取记录信息,并在edit中删除新增的字符,然后将此动作添加到redo列 ...

  3. 怎样在Android.mk上加宏定义【转】

    本文转载自:http://blog.csdn.net/ttxgz/article/details/7591282 很简单, LOCAL_CFLAGS += -DWHATEVERDEFINE 就可以了

  4. Linux - 环境变量与位置变量

    环境变量 [root@local ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin 注:只有自己执行 ...

  5. [转载]H3C&nbsp;S3600&nbsp;DHCP-SERVER&nbsp;配置【原创】

    原文地址:H3C S3600 DHCP-SERVER 配置[原创]作者:旅行者萧 案例要求: 在H3C S3600-28TP-SI 的vlan 里配置DHCP server,使用vlan 里部分网段为 ...

  6. c语言open()介绍

    2013-09-0914:40:13 1. 头文件: #include <sys/types.h> #include <sys/stat.h> #include <fcn ...

  7. 从Android源码分析View绘制

    在开发过程中,我们常常会来自定义View.它是用户交互组件的基本组成部分,负责展示图像和处理事件,通常被当做自定义组件的基类继承.那么今天就通过源码来仔细分析一下View是如何被创建以及在绘制过程中发 ...

  8. Web-数据库-mysql篇

    DDL创造 create  修改 alter  删除 dorp DML插入 insert  删除 delete 更新 updateDQLselect from where MySQL与JDBC 一.用 ...

  9. 函数的arguments

    1.arguments a.只能在函数内部被访问. b.arguments是一个伪数组(有下标索引,可以存放多个值,但是他里面没有数组的方法.) c.arguments里面存的是什么?函数的实际参数传 ...

  10. 完整安装sqlserver always on集群

    准备工作 1.  四台已安装windows server 2008 r2 系统的虚拟机,配置如下: CPU : 1核 MEMORY : 2GB DISK : 40GB(未分区) NetAdapter ...