CF813E.Army Creation

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires.

In the game Vova can hire nn different warriors; ii th warrior has the type aia_{i} . Vova wants to create a balanced army hiring some subset of warriors. An army is called balanced if for each type of warrior present in the game there are not more than kk warriors of this type in the army. Of course, Vova wants his army to be as large as possible.

To make things more complicated, Vova has to consider qq different plans of creating his army. ii th plan allows him to hire only warriors whose numbers are not less than lil_{i} and not greater than rir_{i} .

Help Vova to determine the largest size of a balanced army for each plan.

Be aware that the plans are given in a modified way. See input section for details.

输入格式

The first line contains two integers nn and kk ( 1<=n,k<=1000001<=n,k<=100000 ).

The second line contains nn integers a1a_{1} , a2a_{2} , ... ana_{n} ( 1<=ai<=1000001<=a_{i}<=100000 ).

The third line contains one integer qq ( 1<=q<=1000001<=q<=100000 ).

Then qq lines follow. ii th line contains two numbers xix_{i} and yiy_{i} which represent ii th plan ( 1<=xi,yi<=n1<=x_{i},y_{i}<=n ).

You have to keep track of the answer to the last plan (let's call it lastlast ). In the beginning last=0last=0 . Then to restore values of lil_{i} and rir_{i} for the ii th plan, you have to do the following:

  1. li=((xi+last) mod n)+1l_{i}=((x_{i}+last) mod n)+1 ;
  2. ri=((yi+last) mod n)+1r_{i}=((y_{i}+last) mod n)+1 ;
  3. If li>ril_{i}>r_{i} , swap lil_{i} and rir_{i} .

输出格式

Print qq numbers. ii th number must be equal to the maximum size of a balanced army when considering ii th plan.

输入输出样例

  • 输入#1

    6 2
    1 1 1 2 2 2
    5
    1 6
    4 3
    1 1
    2 6
    2 6
    

    输出#1

    2
    4
    1
    3
    2
    

说明/提示

In the first example the real plans are:

  1. 1 21 2
  2. 1 61 6
  3. 6 66 6
  4. 2 42 4
  5. 4 64 6
首页