Description

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

Moreover, there are m instructions.

Each instruction is in one of the following two formats:

  1. (1,pos),indicating to change the value of apos to apos+10,000,000;
  2. (2,r,k),indicating to ask the minimum value which is not equal to any ai ( 1≤i≤r ) and **not less ** than k.

Please print all results of the instructions in format 2.

Input

The first line of the input contains an integer T(1≤T≤10), denoting the number of test cases.

In each test case, there are two integers n(1≤n≤100,000),m(1≤m≤100,000) in the first line, denoting the size of array a and the number of instructions.

In the second line, there are n distinct integers a1,a2,...,an (∀i∈[1,n],1≤ai≤n),denoting the array.

For the following m lines, each line is of format (1,t1) or (2,t2,t3).

The parameters of each instruction are generated by such way :

For instructions in format 1 , we defined pos=t1⊕LastAns . (It is promised that 1≤pos≤n)

For instructions in format 2 , we defined r=t2⊕LastAns,k=t3⊕LastAns. (It is promised that 1≤r≤n,1≤k≤n )

(Note that ⊕ means the bitwise XOR operator. )

Before the first instruction of each test case, LastAns is equal to 0 .After each instruction in format 2, LastAns will be changed to the result of that instruction.

(∑n≤510,000,∑m≤510,000 )

Output

For each instruction in format 2, output the answer in one line.

Sample Input

3
5 9
4 3 1 2 5
2 1 1
2 2 2
2 6 7
2 1 3
2 6 3
2 0 4
1 5
2 3 7
2 4 3
10 6
1 2 4 6 3 5 9 10 7 8
2 7 2
1 2
2 0 5
2 11 10
1 3
2 3 2
10 10
9 7 5 3 4 10 6 2 1 8
1 10
2 8 9
1 12
2 15 15
1 12
2 1 3
1 9
1 12
2 2 2
1 9

Sample Output

1
5
2
2
5
6
1
6
7
3
11
10
11
4
8
11

题解

首先理解对题意...题意给了两种操作,一种是将位于pos的数变成\(a_{pos}+10000000\),另一种是询问不等于\([1,r]\)中的任何一个数的,并且大于等于k的最小的数。也就是说这个询问的答案不一定是数组中的数。

因为题中给了限制,一开始数组中的数都满足\(1<=a_i<=n\),且值各不相同,所以一旦进行1操作,这个数就可以被任何答案包含了,那我们就直接维护权值为下标,出现的位置为值得线段树,每次修改就是单点修改,将\(a_{pos}\)的值修改为n+1,询问就是查询区间[k,n+1]内,第一个值大于r的下标,直接利用线段树的二分性查找即可

AC代码

#include <bits/stdc++.h>
#define lson (o << 1)
#define rson (o << 1 | 1)
using namespace std;
const int N = 1e5 + 50;
int a[N], pos[N];
int maxv[N << 2];
int n, m;
void pushup(int o) {
maxv[o] = max(maxv[lson], maxv[rson]);
}
void build(int o, int l, int r) {
if (l == r) {
maxv[o] = pos[l];
return;
}
int mid = (l + r) >> 1;
build(lson, l, mid); build(rson, mid + 1, r);
pushup(o);
}
int query(int o, int l, int r, int ql, int qr, int v) {
if (ql > qr) return n + 1;
if (l == r) {
if (maxv[o] >= v) {
return l;
}
else return n + 1;
}
if (ql <= l && r <= qr) {
if (maxv[o] < v) return n + 1;
}
int mid = (l + r) >> 1;
if (qr <= mid) return query(lson, l, mid, ql, qr, v);
else if (ql > mid) return query(rson, mid + 1, r, ql, qr, v);
else {
int x = query(lson, l, mid, ql, mid, v);
if (x != n + 1) return x;
return query(rson, mid + 1, r, mid + 1, qr, v);
}
}
void update(int o, int l, int r, int pos) {
if (l == r) {
maxv[o] = n + 1;
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) update(lson, l, mid, pos);
else update(rson, mid + 1, r, pos);
pushup(o);
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
pos[a[i]] = i;
}
pos[n + 1] = n + 1;
build(1, 1, n + 1);
int ans = 0;
for (int i = 1; i <= m; i++) {
int t;
scanf("%d", &t);
if (t == 2) {
int r, k; scanf("%d%d", &r, &k);
r ^= ans, k ^= ans;
printf("%d\n", ans = query(1, 1, n + 1, k, n + 1, r + 1));
}
if (t == 1) {
int x;
scanf("%d", &x);
x ^= ans;
update(1, 1, n + 1, a[x]);
}
}
}
return 0;
}

HDU-6703 array的更多相关文章

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

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

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

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

  3. hdu 5587 Array 数学题

    Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5587 De ...

  4. HDU 6197 array array array 2017沈阳网络赛 LIS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...

  5. hdu 5587 Array

    题目链接:hdu 5587 前两周 bc 上的题了,因为赶大作业所以没有去打,看了下官方给出的思路,感觉好强大~~竟然能转化成求二进制数 1 的个数: 然后数位 dp 就行了, #include< ...

  6. hdu 6197 array array array

    array array array Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. hdu 5587 Array 二分

    Array Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem ...

  8. 2017多校第10场 HDU 6172 Array Challenge 猜公式,矩阵幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6172 题意:如题. 解法: #include <bits/stdc++.h> using ...

  9. HDU 5587——Array——————【规律】

    Array Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Sub ...

  10. hdu 6197 array array array LIS

    正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件. ac代码: #include <cstdio> #include <cstring> #include < ...

随机推荐

  1. 【MM系列】SAP 的账期分析和操作

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 的账期分析和操作   前言部 ...

  2. 【MM系列】SAP 根据采购订单创建外向交货单的BAPI

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 根据采购订单创建外向交货单的 ...

  3. MySQL学习-基础练习题

    day1 学生表操作: 1. 查询出班级205有多少个男生 2. 查询出名字为4个字的所有学生信息(编号.姓名,年龄,班级) 3. 查询出所有姓王的学生信息(编号.姓名,年龄,班级) 4. 查询出班级 ...

  4. JPA-style positional param was not an integral ordinal 异常

    JPA-style positional param was not an integral ordinal 多是sql之间的空格问题,或者sql拼接问题. 字符串与字符串直接相加要加空格

  5. 第8周课程总结&实验报告6

    实验六 Java异常 实验目的 理解异常的基本概念: 掌握异常处理方法及熟悉常见异常的捕获方法. 实验要求 练习捕获异常.声明异常.抛出异常的方法.熟悉try和catch子句的使用. 掌握自定义异常类 ...

  6. CAS单点登录系统--进阶

    2.CAS服务端数据源设置 2.1需求分析 我们现在让用户名密码从我们的优乐选的user表里做验证 2.2配置数据源 (1)修改cas服务端中web-inf下deployerConfigContext ...

  7. B - 卿学姐与基本法 (离散化+成段更新+区间求和)

    卿学姐与基本法 Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit S ...

  8. http请求响应丢包问题

    在与合作方联调某个明细数据接口的时候发现 1.当请求条数为4,content-length<1500时,数据可以正确返回. 2.当请求条数为5,content-length>1500时,无 ...

  9. MySQL---数据库切分

    3.切分 水平切分   水平切分又称为sharding,它是将同一个表的记录拆分到多个结构相同的表中.当一个表的数据不断的增加的时候,sharding是必然的选择,它可以将数据分布到集群的不同节点上, ...

  10. 2019全国大学生数学建模竞赛(高教社杯)A题题解

    文件下载:https://www.lanzous.com/i6x5iif 问题一 整体过程: 0x01. 首先,需要确定燃油进入和喷出的间歇性工作过程的时间关系.考虑使用决策变量对一段时间内燃油进入和 ...