A10500 | Persistent Bookcase
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ operations, which will be consecutively applied to the bookcase. Each of the operations has one of four types:
- $1$ $i$ $j$ — Place a book at position $j$ at shelf $i$ if there is no book at it.
- $2$ $i$ $j$ — Remove the book from position $j$ at shelf $i$ if there is a book at it.
- $3$ $i$ — Invert book placing at shelf $i$ . This means that from every position at shelf $i$ which has a book at it, the book should be removed, and at every position at shelf $i$ which has not book at it, a book should be placed.
- $4$ $k$ — Return the books in the bookcase in a state they were after applying $k$ -th operation. In particular, $k=0$ means that the bookcase should be in initial state, thus every book in the bookcase should be removed from its position.
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?
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$ operations, which will be consecutively applied to the bookcase. Each of the operations has one of four types:
- $1$ $i$ $j$ — Place a book at position $j$ at shelf $i$ if there is no book at it.
- $2$ $i$ $j$ — Remove the book from position $j$ at shelf $i$ if there is a book at it.
- $3$ $i$ — Invert book placing at shelf $i$ . This means that from every position at shelf $i$ which has a book at it, the book should be removed, and at every position at shelf $i$ which has not book at it, a book should be placed.
- $4$ $k$ — Return the books in the bookcase in a state they were after applying $k$ -th operation. In particular, $k=0$ means that the bookcase should be in initial state, thus every book in the bookcase should be removed from its position.
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?
输入格式
The first line of the input contains three integers $n$ , $m$ and $q$ ( $1<=n,m<=10^{3}$ , $1<=q<=10^{5}$ ) — 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$ .
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$ .
输出格式
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.
输入输出样例
输入 #1
2 3 3 1 1 1 3 2 4 0
输出 #1
1 4 0
输入 #2
4 2 6 3 2 2 2 2 3 3 3 2 2 2 2 3 2
输出 #2
2 1 3 3 2 4
输入 #3
2 2 2 3 2 2 2 1
输出 #3
2 1
This image illustrates the second sample case.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted