CC's

Back

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.

分析#

这题强制在线.首先1操作相当于删除了这个数.

dalao自闭了一会get到了它的正确做法,我就直接拿来用了.

维护一权值线段树,位置i存其在a中出现的位置.那么当1到r区间内出现位置的最大值超过了r,根据鸽巢原理,至少有一个数未被限制.

加上不小于k的条件,就是k到r中,找到最小的一个r,使得它满足上面的条件,输出这个r.

代码#

一个奇葩的bug…

当使用了fread这种先读完缓冲区再处理的快速读入而删漏了cin时…会显而易见的遇到bug.

但是,因为缓冲区的存在,小范围数据被快乐的读入了缓冲区,cin并不会实际影响什么.一旦遇到大范围数据,cin提前读入了接下来的数据,导致第一个缓冲区之外的数据全部出错…

艹.

记一个bug (HDU 6703)
https://astro-pure.js.org/blog/a-wonderful-bug
Author Cheng Chen
Published at 2019年8月24日
Comment seems to stuck. Try to refresh?✨