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:
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.
Step by step
Solved in 4 steps with 1 images