are given a multiset of abilities of two. All the more unequivocally, for every I from 0 to n selective you have cnti components equivalent to 2i.    In one activity, you can pick any one component 2l>1 and partition it into two components 2l−1.    You ought to perform q inquiries. Each inquiry has one of two sorts:

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 19PE
icon
Related questions
Question

Correct answer will be upvoted else Multiple Downvoted. Computer science.

You are given a multiset of abilities of two. All the more unequivocally, for every I from 0 to n selective you have cnti components equivalent to 2i. 

 

In one activity, you can pick any one component 2l>1 and partition it into two components 2l−1. 

 

You ought to perform q inquiries. Each inquiry has one of two sorts: 

 

"1 pos val" — appoint cntpos:=val; 

 

"2 x k" — ascertain the base number of tasks you really want to make basically k components with esteem lower or equivalent to 2x. 

 

Note that all inquiries of the subsequent kind don't change the multiset; that is, you simply work out the base number of activities, you don't perform them. 

 

Input 

 

The principal line contains two integers n and q (1≤n≤30; 1≤q≤2⋅105) — the size of cluster cnt and the number of inquiries. 

 

The subsequent line contains n integers cnt0,cnt1,… ,cntn−1 (0≤cnti≤106). 

 

Next q lines contain inquiries: one for each line. Each question has one of two sorts: 

 

"1 pos val" (0≤pos<n; 0≤val≤106); 

 

"2 x k" (0≤x<n; 1≤k≤1015). 

 

It's surefire that there is something like one inquiry of the subsequent kind. 

 

Output 

 

For each inquiry of the subsequent kind, print the base number of tasks you want to make basically k components with a worth lower or equivalent to 2x or −1 in case it is absolutely impossible to do it.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to classical planning
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage