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(权值线段树的更多相关文章

  1. hdu 6703 array(权值线段树)

    Problem Description You are given an array a1,a2,...,an(∀i∈[1,n],1≤ai≤n). Initially, each element of ...

  2. Petya and Array (权值线段树+逆序对)

    Petya and Array http://codeforces.com/problemset/problem/1042/D time limit per test 2 seconds memory ...

  3. 2019年CCPC网络赛 HDU 6703 array【权值线段树】

    题目大意:给出一个n个元素的数组A,A中所有元素都是不重复的[1,n].有两种操作:1.将pos位置的元素+1e72.查询不属于[1,r]中的最小的>=k的值.强制在线. 题解因为数组中的值唯一 ...

  4. 对权值线段树剪枝的误解--以HDU6703为例

    引子 对hdu6703,首先将问题转化为"询问一个排列中大于等于k的值里,下标超过r的最小权值是多少" 我们采用官方题解中的做法:权值线段树+剪枝 对(a[i],i)建线段树,查询 ...

  5. 2019牛客训练赛第七场 C Governing sand 权值线段树+贪心

    Governing sand 题意 森林里有m种树木,每种树木有一定高度,并且砍掉他要消耗一定的代价,问消耗最少多少代价可以使得森林中最高的树木大于所有树的一半 分析 复杂度分析:n 1e5种树木,并 ...

  6. HDU 6464 免费送气球 【权值线段树】(广东工业大学第十四届程序设计竞赛)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6464 免费送气球 Time Limit: 2000/1000 MS (Java/Others)    M ...

  7. HDU 6464 权值线段树 && HDU 6468 思维题

    免费送气球 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  8. D. Restore Permutation(权值线段树)

    D. Restore Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. 2019牛客多校第七场E Find the median 权值线段树+离散化

    Find the median 题目链接: https://ac.nowcoder.com/acm/contest/887/E 题目描述 Let median of some array be the ...

随机推荐

  1. 有关vs2010将c++生成exe文件时出现LINK : fatal error LNK1123: 转换到 COFF 期间失败和环境变量问题

    不知怎么本来编译好好的VS2010环境,忽然出现“转换到 COFF 期间失败: 文件无效或损坏”的链接错误.花了好多天,试了好多方法,最终解决了这个问题.现在罗列一下这几种解决方案:方案1:点击“项目 ...

  2. 【Android】ViewModel+LiveData:更加直接地控制视图的方式

    目录 LiveData 前言 使用ViewModel+LiveData LiveData 前言   ViewModel通过将UI data保存在ViewModel类实例的内部,从而大大地将MVC中的 ...

  3. Something wrong with EnCase v8 index search results

    My friend told me that she installed EnCase v8.05 on her workstation which OS version is Win 10. She ...

  4. 一文搞懂 Prometheus 的直方图

    原文链接:一文搞懂 Prometheus 的直方图 Prometheus 中提供了四种指标类型(参考:Prometheus 的指标类型),其中直方图(Histogram)和摘要(Summary)是最复 ...

  5. 02、Java的lambda表达式和JavaScript的箭头函数

    前言 在JDK8和ES6的语言发展中,在Java的lambda表达式和JavaScript的箭头函数这两者有着千丝万缕的联系:本次试图通过这篇文章弄懂上面的两个"语法糖". 简介 ...

  6. American daily English notes (enlarged edition): A review

    Life English is the most pragmatic kind of English when one wants to associate with foreigner friend ...

  7. spark shuffle读操作

    提出问题 1. shuffle过程的数据是如何传输过来的,是按文件来传输,还是只传输该reduce对应在文件中的那部分数据? 2. shuffle读过程是否有溢出操作?是如何处理的? 3. shuff ...

  8. MySQL数据库基本知识(理论总结)

    定义:数据库就是一个文件系统,通过sql语句来获取数据 关系型数据库:关系型数据库存放的是实体时间的关系,在数据库层面来看就是存放的是表和表之间的关联关系 常见的关系型数据库   MySQL    D ...

  9. TI MSP430工程配置及2019年电赛A题编程示例(使用430 F5529)

    配置 第一步:右击工程,选择Options 第二步:在General Options的Target选项卡里选择对应的器件Device,这里是MSP430G2231 第三步:在Debugger里选择FE ...

  10. ccf 201809-4 再卖菜

    这题一开始不知道剪枝这种操作,只会傻傻地dfs. 然后dfs递归写80分超时,非递归写70分超时(纳尼?我一直以为非递归算法在时间上会更优秀一些,为什么会这样?!!) 剪一下枝就都能过了 #inclu ...