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. SpringMVC 拦截器不拦截静态资源的三种处理方式方法

    方案一.拦截器中增加针对静态资源不进行过滤(涉及spring-mvc.xml) <mvc:resources location="/" mapping="/**/* ...

  2. declare-styleable的使用

    declare-styleable:declare-styleable是给自定义控件添加自定义属性用的. 1.首先,先写attrs.xml 在res-vlaues文件夹下创建资源文件attrs.xml ...

  3. ajax跨域POST时执行OPTIONS请求服务端返回403forbidden的解决方法

    ajax访问服务端restful api时,由于contentType类型的原因,浏览器会先发送OPTIONS请求. 本人服务端用的是spring mvc框架,web服务器用的是tomcat的,以下给 ...

  4. ASP.NET MVC上传文件 未显示页面,因为请求实体过大。解方案

    在Dropzone中设置   maxFilesize: 350, //MB 但上传的文件没有到最大限定350MB,就报出来 未显示页面,因为请求实体过大的错误 Web.config中设置  maxAl ...

  5. BZOJ 4032 trie树+各种乱搞

    思路 : 先对b 的所有后缀建立trie树 第一问 暴力枚举a串的起点 在trie树上跑 找到最短的 第二问 也是暴力枚举a串的起点 a和b顺着暴力匹配就好 第三问 求出来a在第i个位置 加一个字母j ...

  6. C#控制台显示进度条

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Prog ...

  7. SqlServer动态变换库名

    declare @tname varchar(20),@num intset @tname='Players_Log_L10001'declare @sql Nvarchar(1000)=N'sele ...

  8. zmodem使用方法

    无论有xshell还是secureCRT连接linux的时. 默认都用一个zmodem可以帮助window和linux之间传输文件 很方便和实用的工具. 不过默认是无法使用的 需要安装lrzsz软件 ...

  9. Wireshark抓本地回环

    最近正好要分析下本机两个端口之间通信状况.于是用wireshark抓包分析.对于本地回环要进行一些特殊的设置. 1.通过“运行”---“cmd” 输入“route add [本机IP]mask 255 ...

  10. C++文本操作.Vs.Python

    C++利用文件流: (1):读取一个字符 std::string TestTxt(argv[3]); // freopen(TestTxt.c_str(),"r",stdin);/ ...