F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Harry And Math Teacher

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1373    Accepted Submission(s): 359


Problem Description
As we all know, Harry Porter learns magic at Hogwarts School. However, learning magical knowledge alone is insufficient to become a great magician. Sometimes, Harry also has to gain knowledge from other certain subjects, such as language, mathematics, English, and even algorithm.
In Hogwarts, there is a tall castle in which all teachers live. The castle is rather special. In every floor there are two doors, behind each of them there existing two stairs to the next floor¡¯s two doors. And if you are at the i-th floor¡¯s j-th door , then you can just go to the next floor from this door. However, something even more interesting (or we can say "magic") can happen to the stairs: sometimes they break into pieces (making it impossible to go to the next floor), and sometimes the fragments can joint together and become the whole stair again. Now suppose Harry is in the a-th floor (you know, Harry is the hero, so he lives in the teachers¡¯ building somehow), and his math teacher b-th floor. Sometimes the math teacher will call Harry to his room. Facing these magic stairs, Harry gets puzzled how he can go to see the math teacher. Can you help Harry figure out how many ways exactly he can choose without going backwards? You can assume that the change of the stairs will not happen when Harry is on his way. Harry can begin at any doors in floor a and he can end at any doors in floor b. And as Harry want to arrive as soon as possible, so he can not go back to the past. And at the beginning all the stairs are intact. And the answer may be too large, you should output the answer mod 1000000007.
 

Input
They are sever test cases, you should process to the end of file.
For each test case, there are two integers n and $m(2 \leq n \leq 50000, 1 \leq m \leq 50000)$ in the first line, indicate the number of the castle¡¯s layers and the number of queries. And the following m lines, each line contains three or four integers. If the first integer op equals 0, there are two integers a and b ($1 \leq a < b \leq n$) follow, indicate the position of Harry and math teacher. Otherwise, there are three integers $x, y, z (1 \leq x < n, 1 \leq y, z \leq 2)$follow, it means that the stair between the $x_{th}$ floor¡¯s $y_{th}$ door and the $(x+1)_{th}$ floor¡¯s z-th door changes its state(if it is intact, then it breaks else it joints).
 

Output
For each query, if op equals 0, you should output one line that contains an integer indicates the number of ways from $a_{th}$ floor to the $b_{th}$ floor.
 

Sample Input
3 1 0 1 3 3 2 1 2 1 1 0 1 3
 

Sample Output
8 6
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-27 12:26:20, Gzip enabled