CF1452F.Divide Powers

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a multiset of powers of two. More precisely, for each ii from 00 to nn exclusive you have cnticnt_i elements equal to 2i2^i .

In one operation, you can choose any one element 2l>12^l > 1 and divide it into two elements 2l12^{l - 1} .

You should perform qq queries. Each query has one of two types:

  • " 11 pospos valval " — assign cntpos:=valcnt_{pos} := val ;
  • " 22 xx kk " — calculate the minimum number of operations you need to make at least kk elements with value lower or equal to 2x2^x .

Note that all queries of the second type don't change the multiset; that is, you just calculate the minimum number of operations, you don't perform them.

输入格式

The first line contains two integers nn and qq ( 1n301 \le n \le 30 ; 1q21051 \le q \le 2 \cdot 10^5 ) — the size of array cntcnt and the number of queries.

The second line contains nn integers cnt0,cnt1,,cntn1cnt_0, cnt_1, \dots, cnt_{n - 1} ( 0cnti1060 \le cnt_i \le 10^6 ).

Next qq lines contain queries: one per line. Each query has one of two types:

  • " 11 pospos valval " ( 0pos<n0 \le pos < n ; 0val1060 \le val \le 10^6 );
  • " 22 xx kk " ( 0x<n0 \le x < n ; 1k10151 \le k \le 10^{15} ).

It's guaranteed that there is at least one query of the second type.

输出格式

For each query of the second type, print the minimum number of operations you need to make at least kk elements with a value lower or equal to 2x2^x or 1-1 if there is no way to do it.

输入输出样例

  • 输入#1

    6 11
    0 1 0 0 1 0
    2 1 5
    2 4 18
    1 1 0
    2 2 5
    2 0 17
    1 0 3
    2 1 2
    1 1 4
    1 4 0
    1 5 1
    2 2 8

    输出#1

    4
    16
    4
    -1
    0
    1
首页