CF593E.Strange Calculation and Cats

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Gosha's universe is a table consisting of nn rows and mm columns. Both the rows and columns are numbered with consecutive integers starting with 11 . We will use (r,c)(r,c) to denote a cell located in the row rr and column cc .

Gosha is often invited somewhere. Every time he gets an invitation, he first calculates the number of ways to get to this place, and only then he goes. Gosha's house is located in the cell (1,1)(1,1) .

At any moment of time, Gosha moves from the cell he is currently located in to a cell adjacent to it (two cells are adjacent if they share a common side). Of course, the movement is possible only if such a cell exists, i.e. Gosha will not go beyond the boundaries of the table. Thus, from the cell (r,c)(r,c) he is able to make a move to one of the cells (r1,c)(r-1,c) , (r,c1)(r,c-1) , (r+1,c)(r+1,c) , (r,c+1)(r,c+1) . Also, Ghosha can skip a move and stay in the current cell (r,c)(r,c) .

Besides the love of strange calculations, Gosha is allergic to cats, so he never goes to the cell that has a cat in it. Gosha knows exactly where and when he will be invited and the schedule of cats travelling along the table. Formally, he has qq records, the ii -th of them has one of the following forms:

  • 11 , xix_{i} , yiy_{i} , tit_{i} — Gosha is invited to come to cell (xi,yi)(x_{i},y_{i}) at the moment of time tit_{i} . It is guaranteed that there is no cat inside cell (xi,yi)(x_{i},y_{i}) at this moment of time.
  • 22 , xix_{i} , yiy_{i} , tit_{i} — at the moment tit_{i} a cat appears in cell (xi,yi)(x_{i},y_{i}) . It is guaranteed that no other cat is located in this cell (xi,yi)(x_{i},y_{i}) at that moment of time.
  • 33 , xix_{i} , yiy_{i} , tit_{i} — at the moment tit_{i} a cat leaves cell (xi,yi)(x_{i},y_{i}) . It is guaranteed that there is cat located in the cell (xi,yi)(x_{i},y_{i}) .

Gosha plans to accept only one invitation, but he has not yet decided, which particular one. In order to make this decision, he asks you to calculate for each of the invitations ii the number of ways to get to the cell (xi,yi)(x_{i},y_{i}) at the moment tit_{i} . For every invitation, assume that Gosha he starts moving from cell (1,1)(1,1) at the moment 11 .

Moving between two neighboring cells takes Gosha exactly one unit of tim. In particular, this means that Gosha can come into the cell only if a cat sitting in it leaves the moment when Gosha begins his movement from the neighboring cell, and if none of the cats comes to the cell at the time when Gosha is in it.

Two ways to go from cell (1,1)(1,1) to cell (x,y)(x,y) at time tt are considered distinct if for at least one moment of time from 11 to tt Gosha's positions are distinct for the two ways at this moment. Note, that during this travel Gosha is allowed to visit both (1,1)(1,1) and (x,y)(x,y) multiple times. Since the number of ways can be quite large, print it modulo 109+710^{9}+7 .

输入格式

The first line of the input contains three positive integers nn , mm and qq ( 1<=nm<=20,1<=q<=100001<=n·m<=20,1<=q<=10000 ) — the number of rows and columns in the table and the number of events respectively.

Next qq lines describe the events, each description contains four integers tpitp_{i} , xix_{i} , yiy_{i} and tit_{i} ( 1<=tp<=3,1<=x<=n,1<=y<=m,2<=t<=1091<=tp<=3,1<=x<=n,1<=y<=m,2<=t<=10^{9} ) — the type of the event ( 11 if Gosha gets an invitation, 22 if a cat comes to the cell and 33 if a cat leaves the cell), the coordinates of the cell where the action takes place and the moment of time at which the action takes place respectively.

It is guaranteed that the queries are given in the chronological order, i.e. t_{i}<t_{i+1} .

输出格式

For each invitation ii (that is, tpi=1tp_{i}=1 ) calculate the number of ways to get to cell (xi,yi)(x_{i},y_{i}) at the moment of time tit_{i} . Respond to the invitations chronologically, that is, in the order they appear in the input.

输入输出样例

  • 输入#1

    1 3 3
    2 1 2 3
    3 1 2 5
    1 1 1 7
    

    输出#1

    5
    
  • 输入#2

    3 3 3
    2 2 2 2
    1 3 3 5
    1 3 3 7
    

    输出#2

    2
    42
    
  • 输入#3

    4 5 5
    2 2 5 3
    2 2 4 6
    3 2 4 9
    1 4 4 13
    1 4 4 15
    

    输出#3

    490902
    10598759
    

说明/提示

Explanation of the first sample. Each picture specifies the number of ways to arrive at the cell at the appropriate time. (X stands for a cell blocked at this particular moment of time)

Time moment 1. Time moment 2. Time moment 3. Time moment 4. Time moment 5. Time moment 6. Time moment 7.

首页