ccpc网赛 hdu6703 array(权值线段树
http://acm.hdu.edu.cn/showproblem.php?pid=6703
大意:给一个n个元素的数组,其中所有元素都是不重复的[1,n]。
两种操作:
将pos位置元素+1e7
查询不属于[1,r]中的最小的>=k的值
思路:将数组元素排序,根据其下标建立权值线段树,维护下标的最大值。
修改将对应值在线段树中的下标直接改为inf32。
查询时,查[k,n+1]区间内找到第一个下标>r的位置。
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define clean(a,b) memset(a,b,sizeof(a))
using namespace std;
const int MAXN=1e5+10;
const int INF32=0x3f3f3f3f;
const ll INF64=0x3f3f3f3f3f3f3f3f;
const ll MOD=1e9+7;
const double PI=acos(-1.0);
const double EPS=1.0e-8; struct segTree{
struct node{
int l,r,len,id,mx;
}tree[MAXN<<2];
void pushup(int rt){
tree[rt].mx = max(tree[rt<<1].mx,tree[rt<<1|1].mx);
}
void build(int l,int r,int rt,int A[]){
tree[rt].l=l;tree[rt].r=r;tree[rt].len=r-l+1;
if(l==r){
tree[rt].id = tree[rt].mx = A[l];
return;
}
int mid = (l+r)>>1;
build(l,mid,rt<<1,A);
build(mid+1,r,rt<<1|1,A);
pushup(rt);
}
void update(int pos,int val,int rt){
if(tree[rt].l==tree[rt].r){
tree[rt].id = tree[rt].mx = val;
return;
}
if(pos<=tree[rt<<1].r) update(pos,val,rt<<1);
else update(pos,val,rt<<1|1);
pushup(rt);
}
int query(int ql,int qr,int val,int rt){
if(tree[rt].l==tree[rt].r) return tree[rt].l;
int ans = INF32;
if(ql<=tree[rt<<1].r&&val<tree[rt<<1].mx) ans=query(ql,qr,val,rt<<1);
if(ans!=INF32) return ans;
if(qr>=tree[rt<<1|1].l&&val<tree[rt<<1|1].mx) ans=query(ql,qr,val,rt<<1|1);
return ans;
}
};
segTree seg;
PII A[MAXN];
int B[MAXN];
int n,m; int cmp1(PII a,PII b){
return a.second<b.second;
} int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>A[i].first;
A[i].second = i;
}
sort(A+1,A+1+n);
for(int i=1;i<=n;i++){
B[i] = A[i].second;
}
sort(A+1,A+1+n,cmp1);
B[++n] = INF32;
seg.build(1,n,1,B);
int ans = 0;
while(m--){
int opt;
cin>>opt;
if(opt==1){
int t1,pos;
cin>>t1;
pos = t1^ans;
seg.update(A[pos].first,INF32,1);
}
else {
int t2,t3,r,k;
cin>>t2>>t3;
r = t2^ans;
k = t3^ans;
cout<<(ans=seg.query(k,n,r,1))<<endl;
}
}
}
return 0;
}
ccpc网赛 hdu6703 array(权值线段树的更多相关文章
- hdu 6703 array(权值线段树)
Problem Description You are given an array a1,a2,...,an(∀i∈[1,n],1≤ai≤n). Initially, each element of ...
- Petya and Array (权值线段树+逆序对)
Petya and Array http://codeforces.com/problemset/problem/1042/D time limit per test 2 seconds memory ...
- 2019年CCPC网络赛 HDU 6703 array【权值线段树】
题目大意:给出一个n个元素的数组A,A中所有元素都是不重复的[1,n].有两种操作:1.将pos位置的元素+1e72.查询不属于[1,r]中的最小的>=k的值.强制在线. 题解因为数组中的值唯一 ...
- 对权值线段树剪枝的误解--以HDU6703为例
引子 对hdu6703,首先将问题转化为"询问一个排列中大于等于k的值里,下标超过r的最小权值是多少" 我们采用官方题解中的做法:权值线段树+剪枝 对(a[i],i)建线段树,查询 ...
- 2019牛客训练赛第七场 C Governing sand 权值线段树+贪心
Governing sand 题意 森林里有m种树木,每种树木有一定高度,并且砍掉他要消耗一定的代价,问消耗最少多少代价可以使得森林中最高的树木大于所有树的一半 分析 复杂度分析:n 1e5种树木,并 ...
- HDU 6464 免费送气球 【权值线段树】(广东工业大学第十四届程序设计竞赛)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6464 免费送气球 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 6464 权值线段树 && HDU 6468 思维题
免费送气球 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- D. Restore Permutation(权值线段树)
D. Restore Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 2019牛客多校第七场E Find the median 权值线段树+离散化
Find the median 题目链接: https://ac.nowcoder.com/acm/contest/887/E 题目描述 Let median of some array be the ...
随机推荐
- RocketMQ中Producer的启动源码分析
RocketMQ中通过DefaultMQProducer创建Producer DefaultMQProducer定义如下: public class DefaultMQProducer extends ...
- 蘑菇街工程师常用的Linux命令!
一.查看日志 线上出现了问题,登上线上的机器查日志是非常常见的操作了.我第一次登上线上机器查日志的时候,我还只记得以下的几个命令(假设现在我们的日志文件叫做service.log): cat serv ...
- 【iOS】NSNotification 常用方法
NSNotification 常用的几个方法,代码如下: // 发送通知 [[NSNotificationCenter defaultCenter] postNotificationName:@&qu ...
- codeforces 213div(2) 365 A.Good Number 365 B.The Fibonacci Segment
#include <stdio.h> #include <string.h> bool vis[11]; int n, k; bool judge(int x) { memse ...
- 从windows平台转战ubuntu
说到ubuntu,可能很多人会有些陌生,但对于有些人很熟悉.ubuntu是linux里面最为流行的一版,以下来自百度百科. Ubuntu(乌班图)是基于Debian GNU/Linux,支 ...
- bucket list 函数解析
cls_bucket_list 函数 librados::IoCtx index_ctx; // key - oid (for different shards if there is any) ...
- 201312-2ISBN号码
问题描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字.1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”是分隔符(键盘上的减号),最后一位 ...
- .lib .dll 区别介绍、使用(dll的两种引入方式)
.lib .dll文件都是程序可直接引用的文件,前者就是所谓的库文件,后者是动态链接库(Dynamic Link Library)也是一个库文件.而.pdb则可以理解为符号表文件.DLL(Dynami ...
- python3学习-pickle模块
pickle提供了一个简单的持久化功能.可以将对象以文件的形式存放在磁盘上. 基本接口: pickle.dump(obj, file, [,protocol]) 注解:将对象obj保存到文件file中 ...
- 主成分分析 Principle Component Analysis
一.主要思想 利用正交变换把可能线性相关变量表示的观测数据,转换为由少数几个线性无关变量(主成分)表示的数据.(重构原始特征空间:线性降维) 要尽可能保留原始数据中的信息,两个思路:最大投影方差.最小 ...