探索flutter框架开发的app在移动应用市场的潜力与挑战
623
2022-11-08
Codeforces Round #368 (Div. 2) D. Persistent Bookcase (离线+dfs)
D. Persistent Bookcase
time limit per test
memory limit per test
input
output
Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified.
After reaching home Alina decided to invent her own persistent data structure. Inventing didn't take long: there is a bookcase right behind her bed. Alina thinks that the bookcase is a good choice for a persistent data structure. Initially the bookcase is empty, thus there is no book at any position at any shelf.
The bookcase consists of n shelves, and each shelf has exactly m positions for books at it. Alina enumerates shelves by integers from 1 to n and positions at shelves — from 1 to m. Initially the bookcase is empty, thus there is no book at any position at any shelf in it.
Alina wrote down q
1ij— Place a book at positionjat shelfi2ij— Remove the book from positionjat shelfi3i— Invert book placing at shelfi. This means that from every position at shelfiwhich has a book at it, the book should be removed, and at every position at shelfi4k— Return the books in the bookcase in a state they were after applyingk-th operation. In particular,k= 0
After applying each of operation Alina is interested in the number of books in the bookcase. Alina got 'A' in the school and had no problem finding this values. Will you do so?
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 103, 1 ≤ q ≤ 105) — the bookcase dimensions and the number of operations respectively.
The next q lines describes operations in chronological order — i-th of them describes i-th operation in one of the four formats described in the statement.
It is guaranteed that shelf indices and position indices are correct, and in each of fourth-type operation the number k corresponds to some operation before it or equals to 0.
Output
For each operation, print the number of books in the bookcase after applying it in a separate line. The answers should be printed in chronological order.
Examples
input
2 3 31 1 13 24 0
output
140
input
4 2 63 22 2 23 33 22 2 23 2
output
213324
input
2 2 23 22 2 1
output
21
Note
This image illustrates the second sample case.
题意:给你有n个书架,每个书架有m层。 有四个操作:
1 i j,在第i个书架第j层放一本书。 2 i j,把第i个书架第j层的书扔掉。 3 i,把第三层的所有书的状态取反,有的变没,没的变有。 4 k,回到第k个询问时候的状态。如果k=0,书架全部清空。
题解:离线处理一下,对每个操作按照顺序建一棵树。前3个操作怎么搞都行。第4个操作,我们可以根据询问的顺序建树,然后dfs搞一下就可以啦。
代码:
#pragma comment(linker, "/STACK:102400000,102400000")//#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~