CF1725D.Deducing Sortability
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's say Pak Chanek has an array A consisting of N positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following:
- Choose an index p ( 1≤p≤N ).
- Let c be the number of operations that have been done on index p before this operation.
- Decrease the value of Ap by 2c .
- Multiply the value of Ap by 2 .
After each operation, all elements of A must be positive integers.
An array A is said to be sortable if and only if Pak Chanek can do zero or more operations so that A1<A2<A3<A4<…<AN .
Pak Chanek must find an array A that is sortable with length N such that A1+A2+A3+A4+…+AN is the minimum possible. If there are more than one possibilities, Pak Chanek must choose the array that is lexicographically minimum among them.
Pak Chanek must solve the following things:
- Pak Chanek must print the value of A1+A2+A3+A4+…+AN for that array.
- Q questions will be given. For the i -th question, an integer Pi is given. Pak Chanek must print the value of APi .
Help Pak Chanek solve the problem.
Note: an array B of size N is said to be lexicographically smaller than an array C that is also of size N if and only if there exists an index i such that Bi<Ci and for each j<i , Bj=Cj .
输入格式
The first line contains two integers N and Q ( 1≤N≤109 , 0≤Q≤min(N,105) ) — the required length of array A and the number of questions.
The i -th of the next Q lines contains a single integer Pi ( 1≤P1<P2<…<PQ≤N ) — the index asked in the i -th question.
输出格式
Print Q+1 lines. The 1 -st line contains an integer representing A1+A2+A3+A4+…+AN . For each 1≤i≤Q , the (i+1) -th line contains an integer representing APi .
输入输出样例
输入#1
6 3 1 4 5
输出#1
17 1 3 4
输入#2
1 0
输出#2
1
说明/提示
In the first example, the array A obtained is [1,2,3,3,4,4] . We can see that the array is sortable by doing the following operations:
- Choose index 5 , then A=[1,2,3,3,6,4] .
- Choose index 6 , then A=[1,2,3,3,6,6] .
- Choose index 4 , then A=[1,2,3,4,6,6] .
- Choose index 6 , then A=[1,2,3,4,6,8] .