2018 牛客多校第一场J

链接:https://www.nowcoder.com/acm/contest/139/J

 

题意: 就是给了一个数组a,和q个查询l,r,问 a1-al,ar-an中有多少个不同的数字

 

题解:

     首先把数组a拷贝一份拼接起来,这样两个区间 a1~al, ar~an 就合并成一个区间 ar~al+n

 

    之后就是问区间上不同的数字个数,经典的题方法看这个:http://www.cnblogs.com/tian-luo/p/9338938.html

    在数组上将数字i出现最后一个位置 置为1,然后就可以树状数组区间求和了

 

   把询问离线处理按照r的先后排序,具体处理看代码orz

#include
using namespace std;

struct ques
{int l,r,id;
 bool operator <(const ques b)
  { return this->r

 

你可能感兴趣的:(2018 牛客多校第一场J)