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 i from 0 to n exclusive you have cnti elements equal to 2i.
In one operation, you can choose any one element 2l>1 and divide it into two elements 2l−1.
You should perform q queries. Each query has one of two types:
- "1 pos val" — assign cntpos:=val;
- "2 x k" — calculate the minimum number of operations you need to make at least k elements with value lower or equal to 2x.
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 的幂组成的多重集。更准确地说,对于每个从 0 到 n(不包括 n)的 i,你有 cnti 个等于 2i 的元素。
在一次操作中,你可以任选一个满足 2l>1 的元素,并将其拆分为两个值为 2l−1 的元素。
你需要执行 q 个查询。每个查询为以下两种类型之一:
- “1 pos val” —— 将 cntpos 赋值为 val;
- “2 x k” —— 计算使得值不超过 2x 的元素个数至少达到 k 所需的最少操作次数。
注意:所有第二类查询均不改变该多重集;即,你仅计算最少操作次数,而并不实际执行这些操作。
输入格式
The first line contains two integers n and q (1≤n≤30; 1≤q≤2⋅105) — the size of array cnt and the number of queries.
The second line contains n integers cnt0,cnt1,…,cntn−1 (0≤cnti≤106).
Next q lines contain queries: one per line. Each query has one of two types:
- "1 pos val" (0≤pos<n; 0≤val≤106);
- "2 x k" (0≤x<n; 1≤k≤1015).
It's guaranteed that there is at least one query of the second type.
第一行包含两个整数 n 和 q(1≤n≤30;1≤q≤2⋅105)——分别表示数组 cnt 的大小和查询次数。
第二行包含 n 个整数 cnt0,cnt1,…,cntn−1(0≤cnti≤106)。
接下来 q 行每行包含一个查询,共两种类型:
- “1 pos val”(0≤pos<n;0≤val≤106);
- “2 x k”(0≤x<n;1≤k≤1015)。
保证至少存在一个第二类查询。
输出格式
For each query of the second type, print the minimum number of operations you need to make at least k elements with a value lower or equal to 2x or −1 if there is no way to do it.
对于每个第二类查询,输出使至少 k 个元素的值小于等于 2x 所需的最少操作次数;若无法实现,则输出 −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测评打分。不知道怎么写?