C. Game with Multiset

In this problem, you are initially given an empty multiset. You have to process two types of queries:

  1. ADD x x x — add an element equal to 2 x 2^{x} 2x to the multiset;
  2. GET w w w — say whether it is possible to take the sum of some subset of the current multiset and get a value equal to w w w.

Input

The first line contains one integer m m m ( 1 ≤ m ≤ 1 0 5 1 \le m \le 10^5 1m105) — the number of queries.

Then m m m lines follow, each of which contains two integers t i t_i ti, v i v_i vi, denoting the i i i-th query. If t i = 1 t_i = 1 ti=1, then the i i i-th query is ADD v i v_i vi ( 0 ≤ v i ≤ 29 0 \le v_i \le 29 0vi29). If t i = 2 t_i = 2 ti=2, then the i i i-th query is GET v i v_i vi ( 0 ≤ v i ≤ 1 0 9 0 \le v_i \le 10^9 0vi109).
Output

For each GET query, print YES if it is possible to choose a subset with sum equal to w w w, or NO if it is impossible.

#include<bits/stdc++.h>
using namespace std;
int f[32],cnt[32];
void slove()
{
	int t;
	cin >> t;
	if (t == 1)
	{
		int v;
		cin >> v;
		cnt[v]++;
	}
	else
	{
		int w;
		cin >> w;
		for (int i = 29; i >= 0; i--)
			w -= f[i] * min(w / f[i], cnt[i]);
		cout << (w ? "NO" : "YES") << endl;
	}
}
int main()
{
	int m;
	cin >> m;
	f[0] = 1;
	for (int i = 1; i <= 29; i++)f[i] = f[i - 1] * 2;
	while (m--)
	{
		slove();
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值