J - Jeronimo's List Gym - 101466J (桶排序+二分)

Jeronimo the bear loves numbers and he is planning to write n numbers in his notebook.

After writing the first m numbers, Jeronimo felt that he was spending a lot of time thinking new numbers, so he wrote the next n - m missing numbers as the sum modulo 3 × 107 of the numbers in the i - m and i - m + 1 positions for m < i ≤ n

While Jeronimo was writing, his sister Lupe arrived and asked him q questions. The i - th question consist of a number bi, Jeronimo has to say what would be the number in the position bi if all the numbers were sorted in ascending order. Jeronimo wants to answer each question as soon as possible but he spends a lot of time counting so he ask your help.

Input

The first line of the input has three integers n (3 ≤ n ≤ 3 × 107), m (3 ≤ m ≤ min(100, n)) and q (1 ≤ q ≤ 10000).

The second line contains m numbers a1, a2, ..., am, (0 ≤ ai < 3 × 107), The first mnumbers that Jeronimo wrote.

The third line contains q questions b1, b2, ..., bq (1 ≤ bi ≤ n)

Output

Print q lines. The i - th line must be the answer of the i - th question made by Lupe.

Examples

Input

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

Output

1
2
3
3
5
6

Input

10 4 3
1 2 9 10
1 5 10

Output

1
10
30

//Full of love and hope for life

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
//https://paste.ubuntu.com/
//https://www.cnblogs.com/zzrturist/    //博客园
//https://blog.csdn.net/qq_44134712     //csdn

using namespace std;

typedef long long ll;
const ll maxn=6e7;
int n[maxn];
int m[maxn];

int main()
{
    int a,b,c,x;
    cin >> a >> b >> c;
    memset(m,0,sizeof(m));
    for(int i=1; i<=b; i++)
    {
        cin >> n[i];
         m[n[i]]++;
    }
    for(int i=b+1; i<=a; i++)
    {
        n[i]=(n[i-b]+n[i-b+1])%30000000;
        m[n[i]]++;
    }
    for(int i=1;i<=30000000;i++){
        m[i]+=m[i-1];
    }
    while(c--)
    {
        cin >> x;
        int t=lower_bound(m,m+maxn,x)-m;
        cout << t << endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZZ --瑞 hopeACMer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值