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. UVa 10297 - Beavergnaw

    题目:假设一个底边与高为D的圆柱切去一部分使得.剩下的中心是底边与高为d的圆柱. 和以他们底面为上下地面的圆锥台,已知切去的体积,求d. 分析:二分,计算几何.圆锥台体积公式:π*(r^2+r*R+R ...

  2. 【MongoDB】windows平台搭建Mongo数据库复制集(相似集群)(三)

    关于windows平台搭建Mongo数据库复制集这个话题,我已经在前面写了两篇博客 第一篇: 怎样在windows平台搭建Mongo数据库复制集 第二篇: 数据同步和故障自适应測试 在本篇里面,咱们重 ...

  3. ACM-并查集之小希的迷宫——hdu1272

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  4. 什么是Spark?

    什么是Spark Spark是一个基于内存计算的开源的集群计算系统,目的是让数据分析更加高速.Spark很小巧玲珑,由加州伯克利大学AMP实验室的Matei为主的小团队所开发. 使用的语言是Scala ...

  5. mybits 操作指南

    第一.一对一: <resultMap type="com.zktx.platform.entity.tb.Module" id="BaseResultMap&quo ...

  6. android 系统签名【转】

    本文转载自:http://blog.csdn.net/csh86277516/article/details/73549824 Android——编译release版签名系统 AndroidManif ...

  7. hdoj--2015--偶数求和(水题)

    偶数求和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  8. [Javascript] 40个轻量级JavaScript脚本库

    诸如jQuery, MooTools, Prototype, Dojo和YUI等JavaScript脚本库,大家都已经很熟悉.但这些脚本库有利也有弊--比如说JavaScript文件过大的问题.有时你 ...

  9. Android 关于Toolbar和FragmentActivity的问题

    今天在工作中遇到用Fragment搭Tab框架时,FragmentActivity无法使用Toolbar的问题.查了许多资料,其实AppComponent继承自FragmentActivity,所以A ...

  10. Retrofit进行post提交json数据

    1:先看一看xutils3的提交代码 String account = editText1.getText().toString(); String password = editText2.getT ...