hdoj6703 2019 CCPC网络选拔赛 1002 array
题意
description
Moreover, there are m instructions.
Each instruction is in one of the following two formats:
- (1,pos),indicating to change the value of apos to apos+10,000,000;
- (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
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 )
## 分析
题目中,共有两种操作,一种是将第k个数字+1000,0000,一种是求一个最小的、不等于ai(1
注意 这个数字,可以不出现在array中
因为array中的数字各不相同,因此,不等于ai(1 <= i <= r),等价于 这个数字可能会出现在 ai(r + 1 <= i <= n)。
为什么是可能?因为由于第一种操作+1000,10000,会使得进行第一种操作的那个数字,无论如何都不会和ai重复(1000,0000 比 51,0000大太多了)。
所以,这个题,我们可以将主席树进行适当的修改,每次查找ai[r + 1, n]中,不小于k的最小数字。
由于本题中,array由1-n的n个数字组成,因此不用考虑数字的去重(unique),以及 离散化问题。
除了上面两种情况,还有一种情况,我们没考虑到,如果k = n (已经过异或运算),那么这个答案还有可能是 n + 1。
综上,答案一共有三种情况:
- ai[r + 1, n] 中的某个数字 (可以用主席树求解)
- 进行过第一种操作的某个数字 (将进行过第一种操作的数字放入set中)
- n + 1
三个数字,求最小值即可
代码
#include <iostream>
#include <cstdio>
#include <set>
#include <algorithm>
int const maxn = 530000;
int const inf = 0x3f3f3f3f;
using namespace std;
int a[maxn], b[maxn];
int root[maxn << 5];//第几个版本的根节点编号
int lc[maxn << 5], rc[maxn << 5], sum[maxn << 5];
int sz;//节点个数
int n, m;
void build(int &rt, int l, int r) {
rt = ++sz;
if (l == r) return;
int mid = (l + r) >> 1;
build(lc[rt], l, mid);
build(rc[rt], mid + 1, r);
}
int update(int id, int l, int r, int pos) {
int _id = ++sz;
lc[_id] = lc[id], rc[_id] = rc[id], sum[_id] = sum[id] + 1;
if (l == r) return _id;
int mid = (r + l) >> 1;
if (pos <= mid)
lc[_id] = update(lc[id], l, mid, pos);
else
rc[_id] = update(rc[id], mid + 1, r, pos);
return _id;
}
//查询 不比k大的最小数字
int query(int p, int q, int l, int r, int k) {
if (l == r) return l;
int x1 = sum[lc[q]] - sum[lc[p]];
int x2 = sum[rc[q]] - sum[rc[p]];
int mid = (l + r) >> 1;
int ans = inf;
if (x1 > 0 && mid >= k)
ans = query(lc[p], lc[q], l, mid, k);
//这个if不能写为else,因为第一个if可能无法得到结果,返回inf
if(ans == inf && x2 > 0 && r >= k)
ans = query(rc[p], rc[q], mid + 1, r, k);
return ans;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
while (~scanf("%d %d", &n, &m)) {
sz = 0;
set<int> s;
int lastAns = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
b[i] = a[i];
}
sort(b + 1, b + n + 1);
build(root[0], 1, n);
for (int i = 1; i <= n; i++) {
int pos = lower_bound(b + 1, b + n + 1, a[i]) - b;
root[i] = update(root[i - 1], 1, n, pos);
}
while (m--) {
int l;
scanf("%d", &l);
if (l == 1) {
int pos = 1; // 随意初始化
scanf("%d", &pos);
pos ^= lastAns;
//cout << "pos = " << pos << endl;
s.insert(a[pos]);
}
else {
int l, k;
scanf("%d %d", &l, &k);
l ^= lastAns;
k ^= lastAns;
//cout << "l = " << l << "k = " << k << endl;
int ansPos = query(root[l - 1 + 1], root[n], 1, n, k);
lastAns = (ansPos == inf) ? inf : b[ansPos];
set<int>::iterator it = s.lower_bound(k);
//
if (it != s.end()) lastAns = min(lastAns, *it);
lastAns = min(lastAns, n + 1);
printf("%d\n", lastAns);
}
}
}
}
return 0;
hdoj6703 2019 CCPC网络选拔赛 1002 array的更多相关文章
- hdoj6708 2019 CCPC网络选拔赛 1007 Windows Of CCPC
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; ch ...
- 2016 ccpc 网络选拔赛 F. Robots
Robots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- CCPC 2019 网络赛 1002 array (权值线段树)
HDU 6703 array 题意: 给定一个数组 \(a_1,a_2, a_3,...a_n\) ,满足 \(1 \le a[i]\le n\) 且 \(a[i]\) 互不相同. 有两种 ...
- 2019CCPC网络选拔赛 hdu6703 array(主席树+set)
题意 给你一个1~n的排列,由两种操作: 1 pos:将a[pos]+10 000 000 2 r k:求大于等于k且不等于a[1~r]的数的最小值. 强制在线. 思路 如果没有1操作,那么我们直接主 ...
- 2016 CCPC网络选拔赛 部分题解
HDU 5832 - A water problem 题意:有两颗星球,一年的长度分别为37天和173天.问第n天时它们是否为新年的第一天. 思路:显然 n 同时被37和173整除时,两种历法都在新 ...
- 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛(8/11)
$$2019中国大学生程序设计竞赛(CCPC)\ -\ 网络选拔赛$$ \(A.\hat{} \& \hat{}\) 签到,只把AB都有的位给异或掉 //#pragma comment(lin ...
- 【赛后总结+部分题解】2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛
赛后总结: T:今天状态一般,甚至有点疲惫.然后12点比赛开始,和队友开始看题,从最后往前面看,发现数学题公式看不懂.然后发现队友已经双开做1001和1006了,我看着1007有人A,开始做1007. ...
- [BFS,A*,k短路径] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 path (Problem - 6705)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6705 path Time Limit: 2000/2000 MS (Java/Others) Mem ...
- [贪心,dp] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 Fishing Master (Problem - 6709)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Fishing Master Time Limit: 2000/1000 MS (Java/Othe ...
随机推荐
- 优酷1080p的kux格式文件怎么转换为MP4格式?
直接使用优酷自己的FFMPEG解码! 格式为:"优酷ffmpeg.exe的安装地址" -y -i ".kux文件储存地址" -c:v copy -c:a cop ...
- Springboot的多环境配置
通常应用都会被安装到几个不同的环境(比如开发.测试.生产等),每个环境都会有一些参数是不一样的. Spring Boot对此也提供了支持,配置文件的名称只要满足application-{profile ...
- 2017年陕西省网络空间安全技术大赛——人民的名义-抓捕赵德汉2——Writeup
下载下来的文件是一个jar包,用die和binwalk检查,确实是一个纯正的jar包 java -jar FileName运行jar包,观察文件的外部特征,发现也是判断password的题目 用查 ...
- 获取目标字符串在字符串中第N次出现的位置
/** * 获取目标字符串在字符串中第N次出现的位置 * @file name * @author xiehongwei * @date 2017-8-2 下午3:29:09 * @param sou ...
- 【强烈推荐,超详细,实操零失误】node.js安装 + npm安装教程 + Vue开发环境搭建
node.js安装 + npm安装教程 + Vue开发环境搭建 [强烈推荐,超详细,实操零失误] 原博客园地址:https://www.cnblogs.com/goldlong/p/8027997.h ...
- Unknown failure (Failure - not installed for 0) 、Error while Installing APKs
解决方法一: 设置 -> 更多设置 -> 开发者选项 ->关闭启用MIUI优化 解决方法二:(这种方法就用不了apply changes的功能了) 描述:在一些机型上安装软件 提示卸 ...
- celery task - 2
# celery task 前言 讨论一个定时任务,一般而言,需要的功能如下: 封装成对象,独立执行: 对象有一些接口,便于了解它的状态: 定时调用: 行为控制,包括重试,成功/失败回调等: 下面分别 ...
- SmartRobotControlPlateform——智能机器人控制平台
具体成果参考github项目:https://github.com/ecjtuseclab/SmartRobotControlPlateform 这里我使用的镜像是:2018-11-13-raspbi ...
- Java编译器的常量优化
/* 在给变量进行赋值的时候,如果右侧的表达式当中全都是常量,没有任何变量, 那么编译器javac将会直接将若干个常量表达式计算得到结果. short result = 5 + 8; // 等号右边全 ...
- 干货 | C#开发的电影售票系统
01 介绍 一个有会员制的电影院购票系统.具有会员注册功能,可区分会员和散客两种身份,实现会员及折扣管理.购票具有挑选电影场次,选择座位和查看电影信息等功能. 查看电影详情.获取排片信息. 选择场次座 ...