CF1725D.Deducing Sortability

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

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 (1≤p≤N1 \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 \lt A_2 \lt A_3 \lt A_4 \lt \ldots \lt 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 \lt C_i and for each j<ij \lt i, Bj=CjB_j = C_j.

假设帕克·查内克有一个由 NN 个正整数组成的数组 AA。帕克·查内克将执行若干次操作。在每次操作中,他将执行以下步骤:

  1. 选择一个下标 pp(1≤p≤N1 \leq p \leq N);
  2. 设 cc 为在此操作之前已在下标 pp 上执行的操作次数;
  3. 将 ApA_p 的值减少 2c2^c;
  4. 将 ApA_p 的值乘以 22。

每次操作后,数组 AA 的所有元素都必须仍为正整数。

当且仅当帕克·查内克能够执行零次或多次操作,使得 A1<A2<A3<A4<…<ANA_1 \lt A_2 \lt A_3 \lt A_4 \lt \ldots \lt A_N 成立时,称数组 AA 是可排序的(sortable)。

帕克·查内克需构造一个长度为 NN 的可排序数组 AA,使其元素和 A1+A2+A3+A4+…+ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N 达到最小可能值。若存在多个满足条件的数组,则帕克·查内克必须从中选出字典序最小的那个。

帕克·查内克需完成以下任务:

  • 输出该数组的元素和 A1+A2+A3+A4+…+ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N;
  • 接下来给出 QQ 个询问。对第 ii 个询问,给定一个整数 PiP_i,帕克·查内克需输出 APiA_{P_i} 的值。

请帮助帕克·查内克解决该问题。

注:设大小均为 NN 的两个数组 BB 和 CC,若存在某个下标 ii,使得 Bi<CiB_i \lt C_i,且对所有 j<ij \lt i 均有 Bj=CjB_j = C_j,则称数组 BB 字典序小于数组 CC。

输入格式

The first line contains two integers NN and QQ (1≤N≤1091 \leq N \leq 10^9, 0≤Q≤min⁡(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 (1≤P1<P2<…<PQ≤N1 \leq P_1 \lt P_2 \lt \ldots \lt P_Q \leq N) — the index asked in the ii-th question.

第一行包含两个整数 NN 和 QQ(1≤N≤1091 \leq N \leq 10^9,0≤Q≤min⁡(N,105)0 \leq Q \leq \min(N, 10^5))—— 分别表示数组 AA 所需的长度以及问题的数量。

接下来的 QQ 行中,第 ii 行包含一个整数 PiP_i(1≤P1<P2<…<PQ≤N1 \leq P_1 \lt P_2 \lt \ldots \lt P_Q \leq N)—— 表示第 ii 个问题所询问的下标。

输出格式

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 1≤i≤Q1 \leq i \leq Q, the (i+1)(i+1)-th line contains an integer representing APiA_{P_i}.

输出 Q+1Q+1 行。第 11 行包含一个整数,表示 A1+A2+A3+A4+…+ANA_1 + A_2 + A_3 + A_4 + \ldots + A_N。对于每个 1≤i≤Q1 \leq i \leq Q,第 (i+1)(i+1) 行包含一个整数,表示 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].

在第一个例子中,得到的数组 AA 为 [1,2,3,3,4,4][1, 2, 3, 3, 4, 4]。我们可以看到,通过执行以下操作可将该数组排序:

  • 选择下标 55,则 A=[1,2,3,3,6,4]A = [1, 2, 3, 3, 6, 4]。
  • 选择下标 66,则 A=[1,2,3,3,6,6]A = [1, 2, 3, 3, 6, 6]。
  • 选择下标 44,则 A=[1,2,3,4,6,6]A = [1, 2, 3, 4, 6, 6]。
  • 选择下标 66,则 A=[1,2,3,4,6,8]A = [1, 2, 3, 4, 6, 8]。

输入解题思路,AI测评打分。不知道怎么写?

首页