CF1500E.Subset Trick

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Vanya invented an interesting trick with a set of integers.

Let an illusionist have a set of positive integers SS. He names a positive integer xx. Then an audience volunteer must choose some subset (possibly, empty) of SS without disclosing it to the illusionist. The volunteer tells the illusionist the size of the chosen subset. And here comes the trick: the illusionist guesses whether the sum of the subset elements does not exceed xx. The sum of elements of an empty subset is considered to be 00.

Vanya wants to prepare the trick for a public performance. He prepared some set of distinct positive integers SS. Vasya wants the trick to be successful. He calls a positive number xx unsuitable, if he can't be sure that the trick would be successful for every subset a viewer can choose.

Vanya wants to count the number of unsuitable integers for the chosen set SS.

Vanya plans to try different sets SS. He wants you to write a program that finds the number of unsuitable integers for the initial set SS, and after each change to the set SS. Vanya will make qq changes to the set, and each change is one of the following two types:

  • add a new integer aa to the set SS, or
  • remove some integer aa from the set SS.

万尼亚发明了一个关于整数集合的有趣魔术。

假设一位魔术师拥有一个正整数集合 SS。他宣布一个正整数 xx。接着,一名观众志愿者需在不向魔术师透露的前提下,从 SS 中任选一个子集(可以为空)。志愿者仅告诉魔术师所选子集的大小(即元素个数)。此时魔术的关键环节来了:魔术师需判断该子集所有元素之和是否不超过 xx。空子集的元素和定义为 00。

万尼亚打算为一场公开演出准备这个魔术。他已预先准备了一个由互异正整数构成的集合 SS。瓦夏希望该魔术总能成功。他将一个正整数 xx 称为不合适的,当且仅当他无法保证:对观众可能选择的任意子集,该魔术均能成功。

万尼亚希望统计出对于给定集合 SS,有多少个正整数是不合适的。

万尼亚计划尝试不同的集合 SS。他要求你编写一个程序:首先计算初始集合 SS 对应的不合适整数的个数;随后,在每次对集合 SS 进行修改后,再次计算该个数。万尼亚总共会执行 qq 次修改操作,每次操作为以下两种类型之一:

  • 向集合 SS 中添加一个新整数 aa,或
  • 从集合 SS 中删除某个整数 aa。

输入格式

The first line contains two integers nn, qq (1≤n,q≤200 0001 \leq n, q \leq 200\,000) — the size of the initial set SS and the number of changes.

The next line contains nn distinct integers s1,s2,…,sns_1, s_2, \ldots, s_n (1≤si≤10131 \leq s_i \leq 10^{13}) — the initial elements of SS.

Each of the following qq lines contain two integers tit_i, aia_i (1≤ti≤21 \leq t_i \leq 2, 1≤ai≤10131 \leq a_i \leq 10^{13}), describing a change:

  • If ti=1t_i = 1, then an integer aia_i is added to the set SS. It is guaranteed that this integer is not present in SS before this operation.
  • If ti=2t_i = 2, then an integer aia_i is removed from the set SS. In is guaranteed that this integer is present in SS before this operation.

第一行包含两个整数 nn、qq(1≤n,q≤200 0001 \leq n, q \leq 200\,000)—— 分别表示初始集合 SS 的大小以及变化操作的次数。

第二行包含 nn 个互不相同的整数 s1,s2,…,sns_1, s_2, \ldots, s_n(1≤si≤10131 \leq s_i \leq 10^{13})—— 表示集合 SS 的初始元素。

接下来的 qq 行,每行包含两个整数 tit_i、aia_i(1≤ti≤21 \leq t_i \leq 2,1≤ai≤10131 \leq a_i \leq 10^{13}),描述一次变化操作:

  • 若 ti=1t_i = 1,则将整数 aia_i 加入集合 SS。保证该整数在本次操作前不在 SS 中。
  • 若 ti=2t_i = 2,则将整数 aia_i 从集合 SS 中移除。保证该整数在本次操作前存在于 SS 中。

输出格式

Print q+1q + 1 lines.

In the first line print the number of unsuitable integers for the initial set SS. In the next qq lines print the number of unsuitable integers for SS after each change.

输出 q+1q + 1 行。

第一行输出初始集合 SS 中不合适的整数的个数。接下来的 qq 行,每行输出每次修改后集合 SS 中不合适的整数的个数。

输入输出样例

  • 输入#1

    3 11
    1 2 3
    2 1
    1 5
    1 6
    1 7
    2 6
    2 2
    2 3
    1 10
    2 5
    2 7
    2 10

    输出#1

    4
    1
    6
    12
    19
    13
    8
    2
    10
    3
    0
    0

说明/提示

In the first example the initial set is S=1,2,3S = {1, 2, 3}. For this set the trick can be unsuccessful for x∈1,2,3,4x \in {1, 2, 3, 4}. For example, if x=4x = 4, the volunteer can choose the subset 1,2{1, 2} with sum 3≤x3 \leq x, and can choose the subset 2,3{2, 3} with sum 5>x5 \gt x. However, in both cases the illusionist only know the same size of the subset (22), so he can't be sure answering making a guess. Since there is only one subset of size 33, and the sum of each subset of smaller size does not exceed 55, all x≥5x \ge 5 are suitable.

在第一个例子中,初始集合为 S={1,2,3}S = \{1, 2, 3\}。对于该集合,该魔术可能对 x∈{1,2,3,4}x \in \{1, 2, 3, 4\} 失败。例如,若 x=4x = 4,助手可选择子集 {1,2}\{1, 2\}(其和为 3≤x3 \leq x),也可选择子集 {2,3}\{2, 3\}(其和为 5>x5 > x)。然而,在这两种情况下,魔术师仅知道子集的大小相同(均为 22),因此无法通过猜测确定答案。由于大小为 33 的子集只有一个,且所有更小规模子集的和均不超过 55,故所有 x≥5x \ge 5 均为可行的取值。

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

首页