#abc321f. F - #(subset sum = K) with Add and Erase
F - #(subset sum = K) with Add and Erase
Score : points
问题描述
我们有一个盒子,最初是空的。 现在按照输入中给出的顺序执行总共 个以下两种类型的操作:
类型 1:将一个写有整数 的球放入盒子。
类型 2:从盒子中移除一个写有整数 的球。 保证在执行该操作之前,盒子里一定包含一个写有整数 的球。
对于每次操作后的盒子,请解决以下问题:
求出(模 )从盒子中取出若干个球,使得这些球上所写的整数之和为 的取法数目。 盒子中的所有球都是可区分的。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a box, which is initially empty. Let us perform a total of operations of the following two types in the order they are given in the input.
Type : Put into the box a ball with the integer written on it.
Type : Remove from the box a ball with the integer written on it. It is guaranteed that the box contains a ball with the integer written on it before the operation.
For the box after each operation, solve the following problem.
Find the number, modulo , to pick up some number of balls from the box so that the integers written on them sum to . All balls in the box are distinguishable.
Constraints
- All input values are integers.
- For each type- operation, .
- All the operations satisfy the condition in the problem statement.
Input
The input is given from Standard Input in the following format, where represents the -th operation:
Output
Print lines. The -th line should contain the answer when the first operations have been done.
Sample Input 1
15 10
+ 5
+ 2
+ 3
- 2
+ 5
+ 10
- 3
+ 1
+ 3
+ 3
- 5
+ 1
+ 7
+ 4
- 3
Sample Output 1
0
0
1
0
1
2
2
2
2
2
1
3
5
8
5
This input contains operations.
After the last operation, the box contains the balls . There are five ways to pick up balls for a sum of :
- (the -st, -rd, -th, -th balls)
- (the -st, -rd, -th balls)
- (the -st, -th, -th balls)
- (the -nd ball)
- (the -th, -th balls)
update @ 2024/3/10 01:41:10