CF1725D.Deducing Sortability

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Let's say Pak Chanek has an array AA consisting of NN positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following:

  1. Choose an index pp ( 1pN1 \leq p \leq N ).
  2. Let cc be the number of operations that have been done on index pp before this operation.
  3. Decrease the value of ApA_p by 2c2^c .
  4. Multiply the value of ApA_p by 22 .

After each operation, all elements of AA must be positive integers.

An array AA is said to be sortable if and only if Pak Chanek can do zero or more operations so that A1<A2<A3<A4<<ANA_1 < A_2 < A_3 < A_4 < \ldots < A_N .

Pak Chanek must find an array AA that is sortable with length NN such that A1+A2+A3+A4++ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N 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++ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N for that array.
  • QQ questions will be given. For the ii -th question, an integer PiP_i is given. Pak Chanek must print the value of APiA_{P_i} .

Help Pak Chanek solve the problem.

Note: an array BB of size NN is said to be lexicographically smaller than an array CC that is also of size NN if and only if there exists an index ii such that Bi<CiB_i < C_i and for each j<ij < i , Bj=CjB_j = C_j .

输入格式

The first line contains two integers NN and QQ ( 1N1091 \leq N \leq 10^9 , 0Qmin(N,105)0 \leq Q \leq \min(N, 10^5) ) — the required length of array AA and the number of questions.

The ii -th of the next QQ lines contains a single integer PiP_i ( 1P1<P2<<PQN1 \leq P_1 < P_2 < \ldots < P_Q \leq N ) — the index asked in the ii -th question.

输出格式

Print Q+1Q+1 lines. The 11 -st line contains an integer representing A1+A2+A3+A4++ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N . For each 1iQ1 \leq i \leq Q , the (i+1)(i+1) -th line contains an integer representing APiA_{P_i} .

输入输出样例

  • 输入#1

    6 3
    1
    4
    5

    输出#1

    17
    1
    3
    4
  • 输入#2

    1 0

    输出#2

    1

说明/提示

In the first example, the array AA obtained is [1,2,3,3,4,4][1, 2, 3, 3, 4, 4] . We can see that the array is sortable by doing the following operations:

  • Choose index 55 , then A=[1,2,3,3,6,4]A = [1, 2, 3, 3, 6, 4] .
  • Choose index 66 , then A=[1,2,3,3,6,6]A = [1, 2, 3, 3, 6, 6] .
  • Choose index 44 , then A=[1,2,3,4,6,6]A = [1, 2, 3, 4, 6, 6] .
  • Choose index 66 , then A=[1,2,3,4,6,8]A = [1, 2, 3, 4, 6, 8] .
首页