CF1725D.Deducing Sortability
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:512MB
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.
假设帕克·查内克有一个由 N 个正整数组成的数组 A。帕克·查内克将执行若干次操作。在每次操作中,他将执行以下步骤:
- 选择一个下标 p(1≤p≤N);
- 设 c 为在此操作之前已在下标 p 上执行的操作次数;
- 将 Ap 的值减少 2c;
- 将 Ap 的值乘以 2。
每次操作后,数组 A 的所有元素都必须仍为正整数。
当且仅当帕克·查内克能够执行零次或多次操作,使得 A1<A2<A3<A4<…<AN 成立时,称数组 A 是可排序的(sortable)。
帕克·查内克需构造一个长度为 N 的可排序数组 A,使其元素和 A1+A2+A3+A4+…+AN 达到最小可能值。若存在多个满足条件的数组,则帕克·查内克必须从中选出字典序最小的那个。
帕克·查内克需完成以下任务:
- 输出该数组的元素和 A1+A2+A3+A4+…+AN;
- 接下来给出 Q 个询问。对第 i 个询问,给定一个整数 Pi,帕克·查内克需输出 APi 的值。
请帮助帕克·查内克解决该问题。
注:设大小均为 N 的两个数组 B 和 C,若存在某个下标 i,使得 Bi<Ci,且对所有 j<i 均有 Bj=Cj,则称数组 B 字典序小于数组 C。
输入格式
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.
第一行包含两个整数 N 和 Q(1≤N≤109,0≤Q≤min(N,105))—— 分别表示数组 A 所需的长度以及问题的数量。
接下来的 Q 行中,第 i 行包含一个整数 Pi(1≤P1<P2<…<PQ≤N)—— 表示第 i 个问题所询问的下标。
输出格式
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.
输出 Q+1 行。第 1 行包含一个整数,表示 A1+A2+A3+A4+…+AN。对于每个 1≤i≤Q,第 (i+1) 行包含一个整数,表示 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].
在第一个例子中,得到的数组 A 为 [1,2,3,3,4,4]。我们可以看到,通过执行以下操作可将该数组排序:
- 选择下标 5,则 A=[1,2,3,3,6,4]。
- 选择下标 6,则 A=[1,2,3,3,6,6]。
- 选择下标 4,则 A=[1,2,3,4,6,6]。
- 选择下标 6,则 A=[1,2,3,4,6,8]。
输入解题思路,AI测评打分。不知道怎么写?