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

Rikka with Cake

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1682    Accepted Submission(s): 676


Problem Description
Rikka's birthday is on June 12th. The story of this problem happens on that day.

Today is Rikka's birthday. Yuta prepares a big cake for her: the shape of this cake is a rectangular of $n$ centimeters times $m$ centimeters. With the guidance of a grimoire, Rikka is going to cut the cake.

For simplicity, Rikka firstly builds a Cartesian coordinate system on the cake: the coordinate of the left bottom corner is $(0,0)$ while that of the right top corner is $(n,m)$. There are $K$ instructions on the grimoire: The $i$th cut is a ray starting from $(x_i,y_i)$ while the direction is $D_i$. There are four possible directions: L, passes $(x_i-1,y_i)$; R, passes $(x_i+1,y_i)$; U, passes $(x_i,y_i+1)$; D, passes $(x_i,y_i-1)$.

Take advantage of the infinite power of Tyrant's Eye, Rikka finishes all the instructions quickly. Now she wants to count the number of pieces of the cake. However, since a huge number of cuts have been done, the number of pieces can be very large. Therefore, Rikka wants you to finish this task.
 

Input
The first line of the input contains a single integer $T(1 \leq T \leq 100)$, the number of the test cases.

For each test case, the first line contains three positive integers $n,m,K(1 \leq n,m \leq 10^9, 1 \leq K \leq 10^5)$, which represents the shape of the cake and the number of instructions on the grimoire.

Then $K$ lines follow, the $i$th line contains two integers $x_i,y_i(1 \leq x_i < n, 1 \leq y_i <m)$ and a char $D_i \in \{$'L','R','U','D'$\}$, which describes the $i$th cut.

The input guarantees that there are no more than $5$ test cases with $K > 1000$, and no two cuts share the same $x$ coordinate or $y$ coordinate, i.e., $\forall 1 \leq i < j \leq K$, $x_i \neq x_j$ and $y_i \neq y_j$.
 

Output
For each test case, output a single line with a single integer, the number of pieces of the cake.

Hint

The left image and the right image show the results of the first and the second test case in the sample input respectively. Clearly, the answer to the first test case is $3$ while the second one is $5$.

 

Sample Input
2 4 4 3 1 1 U 2 2 L 3 3 L 5 5 4 1 2 R 3 1 U 4 3 L 2 4 D
 

Sample Output
3 5
 

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-03-29 05:52:06, Gzip enabled