cf 101433j Jeronimo's List (思维)

本文解析了CodeForces健身房101466的J题“Jeronimo's List”,详细介绍了如何通过记录数值出现次数并进行排序来解决Lupe提出的关于已排序列表位置的问题。文章提供了一个C++实现示例,展示了从输入读取数据,计算后续数值,并最终输出排序后的列表中特定位置数值的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://codeforces.com/gym/101466/problem/J

J. Jeronimo's List

time limit per test

2.0 s

memory limit per test

1024 MB

input

standard input

output

standard output

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 - mmissing 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 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

Copy

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

output

Copy

1
2
3
3
5
6

input

Copy

10 4 3
1 2 9 10
1 5 10

output

Copy

1
10
30

俺不知道什么桶排序,俺用v标记出现的次数 在放到b数组里面去,

#include<bits/stdc++.h>
using namespace std;

const int N = 3e7 + 7;
const int mod = 3e7;
int a[N], n, m, q, v[N], b[N];
int main()
{
	cin >> n >> m >> q;
	for(int i = 0; i < m; i++)
	{
		scanf("%d", a+i);
		v[a[i]]++;
	}
	
	for(int i = m; i < n; i++)	
	{
		a[i] = a[i-m]+a[i-m+1];
		if(a[i] >= mod) a[i] %= mod;
		v[a[i]]++;
	}

	
	int k = 0;
	for(int i = 0; i < mod; i++)
	if(v[i])
		while(v[i]--) b[k++] = i;

	while(q--)	
	{
		int x;
		scanf("%d",&x);
		printf("%d\n",b[x-1]);
	}
	
	return 0;
	
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值