Jeronimo's List(模拟+计数排序||桶排)

 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 - thquestion consist of a number bi, Jeronimo has to say what would be the number in the position biif 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 m numbers 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


开始没注意3e7开始对整个数组sort排了下序,T了,
后来二分查第x小的数,T了,又另加了vis数组记忆化标记计算过的,也T了,
愣是没想过桶排
 
计数存,俗称桶排,代码超友好:
 
 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 #define mod 30000000
 5 #define MAX 30000007
 6 
 7 int a[MAX], num[MAX];
 8 int re[MAX];
 9 
10 int main()
11 {
12     int n, i, j, pos, m, q, cur;
13     scanf("%d %d %d", &n, &m, &q);
14     memset(num, 0, sizeof(num));
15     
16     //数组里的数计数到num数组里
17     for(i=0; i<m; i++)
18     {
19         scanf("%d", &a[i]);
20         num[a[i]]++;;
21     }
22     for(; i<n; i++)
23     {
24         a[i] = (a[i-m] + a[i-m+1])%mod;
25         num[a[i]]++;
26     }
27     
28     //数组re是利用计数数组num的到的排序的后数组
29     cur = 0;
30     for(i=0;i<MAX;i++)
31     {
32         for(j=0;j<num[i];j++)
33         {
34             re[cur++] = i;
35         }
36     }
37     
38     while(q--)
39     {
40         scanf("%d", &pos);
41         printf("%d\n", re[pos-1]);
42     }
43     return 0;
44 }
 
 
 
 
 
 
 

转载于:https://www.cnblogs.com/0xiaoyu/p/11345852.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值