CF1913C.Game with Multiset

普及-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

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

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

本题中,你初始时会得到一个空的多重集。你需要处理两种类型的查询:

  1. ADD xx — 向多重集中添加一个值为 2x2^{x} 的元素;
  2. GET ww — 判断当前多重集中是否存在某个子集,其元素之和恰好等于 ww。

输入格式

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

Then mm lines follow, each of which contains two integers tit_i, viv_i, denoting the ii-th query. If ti=1t_i = 1, then the ii-th query is ADD viv_i (0≤vi≤290 \le v_i \le 29). If ti=2t_i = 2, then the ii-th query is GET viv_i (0≤vi≤1090 \le v_i \le 10^9).

第一行包含一个整数 mm(1≤m≤1051 \le m \le 10^5)—— 表示查询次数。

接下来是 mm 行,每行包含两个整数 tit_i 和 viv_i,表示第 ii 个查询。若 ti=1t_i = 1,则第 ii 个查询为 ADD viv_i(0≤vi≤290 \le v_i \le 29);若 ti=2t_i = 2,则第 ii 个查询为 GET viv_i(0≤vi≤1090 \le v_i \le 10^9)。

输出格式

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

对于每个 GET 查询,如果能够选择一个子集使其元素和等于 ww,则输出 YES;否则输出 NO。

输入输出样例

  • 输入#1

    5
    1 0
    1 0
    1 0
    2 3
    2 4

    输出#1

    YES
    NO
  • 输入#2

    7
    1 0
    1 1
    1 2
    1 10
    2 4
    2 6
    2 7

    输出#2

    YES
    YES
    YES

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

首页