GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 4 September 2022

[Solution] Deducing Sortability Codeforces Solution


D. Deducing Sortability
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

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:

  1. Choose an index p (1pN).
  2. Let c be the number of operations that have been done on index p before this operation.
  3. Decrease the value of Ap by 2c.
  4. 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.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

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<iBj=Cj.

Input

The first line contains two integers N and Q (1N1090Qmin(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 (1P1<P2<<PQN) — the index asked in the i-th question.

Output

Print Q+1 lines. The 1-st line contains an integer representing A1+A2+A3+A4++AN. For each 1iQ, the (i+1)-th line contains an integer representing 

No comments:

Post a Comment