CF1452F.Divide Powers

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 \gt 1 and divide it into two elements 2l−12^{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.

你被给定一个由 2 的幂组成的多重集。更准确地说,对于每个从 00 到 nn(不包括 nn)的 ii,你有 cnticnt_i 个等于 2i2^i 的元素。

在一次操作中,你可以任选一个满足 2l>12^l \gt 1 的元素,并将其拆分为两个值为 2l−12^{l - 1} 的元素。

你需要执行 qq 个查询。每个查询为以下两种类型之一:

  • “11 pospos valval” —— 将 cntposcnt_{pos} 赋值为 valval;
  • “22 xx kk” —— 计算使得值不超过 2x2^x 的元素个数至少达到 kk 所需的最少操作次数。

注意:所有第二类查询均不改变该多重集;即,你仅计算最少操作次数,而并不实际执行这些操作。

输入格式

The first line contains two integers nn and qq (1≤n≤301 \le n \le 30; 1≤q≤2⋅1051 \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,…,cntn−1cnt_0, cnt_1, \dots, cnt_{n - 1} (0≤cnti≤1060 \le cnt_i \le 10^6).

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

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

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

第一行包含两个整数 nn 和 qq(1≤n≤301 \le n \le 30;1≤q≤2⋅1051 \le q \le 2 \cdot 10^5)——分别表示数组 cntcnt 的大小和查询次数。

第二行包含 nn 个整数 cnt0,cnt1,…,cntn−1cnt_0, cnt_1, \dots, cnt_{n - 1}(0≤cnti≤1060 \le cnt_i \le 10^6)。

接下来 qq 行每行包含一个查询,共两种类型:

  • “11 pospos valval”(0≤pos<n0 \le pos \lt n;0≤val≤1060 \le val \le 10^6);
  • “22 xx kk”(0≤x<n0 \le x \lt n;1≤k≤10151 \le k \le 10^{15})。

保证至少存在一个第二类查询。

输出格式

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.

对于每个第二类查询,输出使至少 kk 个元素的值小于等于 2x2^x 所需的最少操作次数;若无法实现,则输出 −1-1。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页