2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
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)
解题:带修改的区间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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- HDU 5412 CRB and Queries(区间第K大 树套树 按值建树)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5412 Problem Description There are N boys in CodeLan ...
- HDU 5412——CRB and Queries——————【线段树套Treap(并没有AC)】
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- hdu 5412 CRB and Queries
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5412 CRB and Queries Description There are $N$ boys i ...
- 2016 Multi-University Training Contest 10 || hdu 5860 Death Sequence(递推+单线约瑟夫问题)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 题目大意:给你n个人排成一列编号,每次杀第一个人第i×k+1个人一直杀到没的杀.然后 ...
- 2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树:区间覆盖+单点最大小)
HDU 5861 题意 在n个村庄之间存在n-1段路,令某段路开放一天需要交纳wi的费用,但是每段路只能开放一次,一旦关闭将不再开放.现在给你接下来m天内的计划,在第i天,需要对村庄ai到村庄bi的道 ...
- 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 ...
随机推荐
- 【Oracle】RAC删除节点
环境: OS:OEL5.6 RAC:10.2.0.1.0 眼下有rac1.rac2.rac3三个节点,下面是删除rac3节点的具体过程 1.删除rac3节点上的数据库实例 [oracle@rac1 ~ ...
- Linux用户和组的管理
一.概述: 1.Linux下的三类用户: (1).超级用户(root)具有操作系统的一切权限UID值均为0 (2).普通用户具有操作系统有限的权限UID值500~6000 (3).伪用户是为了方便系统 ...
- oc11---结构体作为属性
// // main.m // 结构体作为对象的属性 #import <Foundation/Foundation.h> typedef struct { int year; int mo ...
- Swift3.0中关于日期类的使用指引
日期的处理在大大小小的iOS项目中都十分常见,随着Swift3.0正式版的即将推出,语法的改变让NSDate以及相关类的使用都与之前略有不同,这里将会对基于Swift3.0版本的NSDate及相关类的 ...
- Node.js:模块系统
ylbtech-Node.js:模块系统 1.返回顶部 1. Node.js模块系统 为了让Node.js的文件可以相互调用,Node.js提供了一个简单的模块系统. 模块是Node.js 应用程序的 ...
- yii1 session
在 Yii框架中使用session 的笔记: 首先,在Yii框架中,你不需要像标准PHP代码那样使用session_start(),在Yii框架中,autoStart 属性缺省被设置为true,所以, ...
- vue插件 vue-seamless-scroll 无缝滚动插件ES6使用总结
最近因为需求需要写一个项目信息无缝向上滚动组件,在网上搜了一下,看到大家的一致好评就果断的使用了vue-seamless-scroll组件.下面就简单的介绍它的使用,具体详细的使用推荐大家去看下开发者 ...
- linux下恢复被删除的文件
https://cloud.tencent.com/developer/article/1028317
- week1 notebook1
初识Python 一.python介绍 - 解释器: cpython(默认使用) ipython(shell) jpython(java) ironpython rubypython - 编码: as ...
- 使用Micrisoft.net设计方案 第一章 企业解决方案中构建设计模式
第一章企业解决方案中构建设计模式 我们知道的系统总是由简单到复杂,而不是直接去设计一个复杂系统.如果直接去设计一个复杂系统,结果最终会导致失败.在设计系统的时候,先设计一个能够正常工作的系统,然后在此 ...