CF707D.Persistent Bookcase

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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 nn shelves, and each shelf has exactly mm positions for books at it. Alina enumerates shelves by integers from 11 to nn and positions at shelves — from 11 to mm . Initially the bookcase is empty, thus there is no book at any position at any shelf in it.

Alina wrote down qq operations, which will be consecutively applied to the bookcase. Each of the operations has one of four types:

  • 11 ii jj — Place a book at position jj at shelf ii if there is no book at it.
  • 22 ii jj — Remove the book from position jj at shelf ii if there is a book at it.
  • 33 ii — Invert book placing at shelf ii . This means that from every position at shelf ii which has a book at it, the book should be removed, and at every position at shelf ii which has not book at it, a book should be placed.
  • 44 kk — Return the books in the bookcase in a state they were after applying kk -th operation. In particular, k=0k=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 nn , mm and qq ( 1<=n,m<=1031<=n,m<=10^{3} , 1<=q<=1051<=q<=10^{5} ) — the bookcase dimensions and the number of operations respectively.

The next qq lines describes operations in chronological order — ii -th of them describes ii -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 kk corresponds to some operation before it or equals to 00 .

输出格式

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.

首页