#P11494. [2023省队模拟]卡牌

[2023省队模拟]卡牌

题目描述

HearthstoneHearthstone 是一个知名的网络游戏,请仔细阅读其规则:

nn 种卡牌,编号为 1n1\sim n 。游戏中会发生如下两种事件:

  • add\texttt{add} :往 hero zonehero\ zone 中添加一张未知的卡牌,保证此后 hero zonehero\ zone 中不存在两张卡牌编号相同。
  • test x y\texttt{test x y} :测试 hero zonehero\ zone 中是否存在牌 xx 。如果存在牌 xxy=1y=1 ,然后将 xx 移除;否则, y=0y=0 。请注意,经过 test x y\texttt{test x y} 后, xx 一定不存在于 hero zonehero\ zone 中。

给定事件序列 E=[e1,,em]E=[e_1,\ldots,e_m] ,称事件序列是合法的,当且仅当,存在一种 add\texttt{add} 牌的方案,使得:

  • add\texttt{add} 一张牌前,这张牌不存在于 hero zonehero\ zone 中。
  • test x 0\texttt{test x 0} 时,牌 xx 不存在于 hero zonehero\ zone 中。
  • test x 1\texttt{test x 1} 时,牌 xx 存在于 hero zonehero\ zone 中。

给定 qq 个事件 e1,e2,,eqe_1,e_2,\ldots,e_q ,你需要维护一个事件序列 EE 。一开始, E=0|E|=0 。依次对于每个 i=1,2,,qi=1,2,\cdots,q ,尝试将 eie_i 插入 EE 的末尾。如果 EE 是不合法的,移除事件 eie_i 并报告一个 " bugbug ";否则,报告必须存在于 hero zonehero\ zone 中的牌的数量,和必须不存在于 hero zonehero\ zone 中的牌的数量。

注意:不一定存在于 hero zonehero\ zone 中和一定不存在于 hero zonehero\ zone 中的牌,是有区别的。

输入格式

本题多组测试。输入的第一行包含一个整数 TT ,表示数据组数。对于每组数据:

第一行包括两个整数 n,qn,q ,表示牌的种类数和事件的数量。

接下来每行包括一个事件:

add\texttt{add} :表示向 hero zonehero\ zone 添加一个卡牌。

test x y\texttt{test x y} :表示对卡牌 xx 进行一个 testtest 并移除卡牌 xx 。保证 x[1,n],y[0,1]x\in [1,n],y\in [0,1]

输出格式

对于每组数据:

对于每个事件,如果它可以被插入到序列末尾,则输出两个以一个空格隔开的整数,表示一定存在于 hero zonehero\ zone 中的牌的数量和一定不存在于 hero zonehero\ zone 中的牌的数量;否则,输出一行一个字符串 " bugbug "。

数据范围

对于 5%5\% 的数据: n,q10\sum n,q\le 10
对于 10%10\% 的数据: n,q100\sum n,q\le 100
对于 20%20\% 的数据: n,q2000\sum n,q\le 2000
对于 25%25\% 的数据: n,q5000\sum n,q\le 5000
另有 10%10\% 的数据:没有 test x 0\texttt{test x 0}
另有 10%10\% 的数据:没有 test x 1\texttt{test x 1}
另有 5%5\% 的数据, add\texttt{add} 都在 test\texttt{test} 前。
对于 100%100\% 的数据: 1T1051\le T\le 10^51n,q1051\le \sum n,\sum q\le 10^5

输入样例 1

2
1 8
test 1 0
test 1 1
add
test 1 0
test 1 1
add
test 1 1
test 1 0
2 10
add
add
add
test 1 1
test 1 1
add
add
add
test 2 1
test 2 1

输出样例 1

0 1
bug
1 0
bug
0 1
1 0
0 1
0 1
0 0
2 0
bug
1 1
bug
2 0
bug
bug
1 1
bug

输入样例 2

1
4 7
add
add
test 3 0
test 4 0
add
test 1 1
test 3 1

输出样例 2

0 0
0 0
0 1
2 2
2 0
1 1
1 3