A13898 | Divide Powers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a multiset of powers of two. More precisely, for each $i$ from $0$ to $n$ exclusive you have $cnt_i$ elements equal to $2^i$ .
In one operation, you can choose any one element $2^l > 1$ and divide it into two elements $2^{l - 1}$ .
You should perform $q$ queries. Each query has one of two types:
- " $1$ $pos$ $val$ " — assign $cnt_{pos} := val$ ;
- " $2$ $x$ $k$ " — calculate the minimum number of operations you need to make at least $k$ elements with value lower or equal to $2^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.
In one operation, you can choose any one element $2^l > 1$ and divide it into two elements $2^{l - 1}$ .
You should perform $q$ queries. Each query has one of two types:
- " $1$ $pos$ $val$ " — assign $cnt_{pos} := val$ ;
- " $2$ $x$ $k$ " — calculate the minimum number of operations you need to make at least $k$ elements with value lower or equal to $2^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 $n$ and $q$ ( $1 \le n \le 30$ ; $1 \le q \le 2 \cdot 10^5$ ) — the size of array $cnt$ and the number of queries.
The second line contains $n$ integers $cnt_0, cnt_1, \dots, cnt_{n - 1}$ ( $0 \le cnt_i \le 10^6$ ).
Next $q$ lines contain queries: one per line. Each query has one of two types:
- " $1$ $pos$ $val$ " ( $0 \le pos < n$ ; $0 \le val \le 10^6$ );
- " $2$ $x$ $k$ " ( $0 \le x < n$ ; $1 \le k \le 10^{15}$ ).
It's guaranteed that there is at least one query of the second type.
The second line contains $n$ integers $cnt_0, cnt_1, \dots, cnt_{n - 1}$ ( $0 \le cnt_i \le 10^6$ ).
Next $q$ lines contain queries: one per line. Each query has one of two types:
- " $1$ $pos$ $val$ " ( $0 \le pos < n$ ; $0 \le val \le 10^6$ );
- " $2$ $x$ $k$ " ( $0 \le x < n$ ; $1 \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 $k$ elements with a value lower or equal to $2^x$ or $-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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted