1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=200050;
int T;
int n,m,k;
int c[maxn],h[maxn],num,tot;
struct node{
int p,l,r,pos,val;
bool operator<(const node&t) const{
if(pos==t.pos) return p>t.p; return pos<t.pos;
}
}a[maxn];
inline int read()
{
int x=0,t=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')t=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*t;
}
int ha(int x){return lower_bound(h+1,h+tot+1,x)-h;}
int lowbit(int x){return x&-x;}
void add(int x,int p)
{
while(x<=tot)
{
c[x]+=p;
x+=lowbit(x);
}
}
int query(int x)
{
int res=0;
while(x)
{
res+=c[x];
x-=lowbit(x);
}
return res;
}
int main()
{
T=read();
while(T--)
{
memset(c,0,sizeof(c));
num=0,tot=0;
n=read(),m=read(),k=read();
for(int i=1;i<=k;i++)
{
int x,y;x=read(),y=read();
char opt[2];cin>>opt;
if(opt[0]=='U')
{
a[++num]={1,x,y,y,1};
h[++tot]=x;
}
else if(opt[0]=='D')
{
a[++num]={1,x,0,0,1};
a[++num]={1,x,y+1,y+1,-1};
h[++tot]=x;
}
else if(opt[0]=='L')
{
a[++num]={0,0,x,y,0};
h[++tot]=x;
}
else
{
a[++num]={0,x,n,y,0};
h[++tot]=x;
}
//cout<<x<<" "<<y<<endl;
}
h[++tot]=0;h[++tot]=n;
sort(h+1,h+tot+1);
tot=unique(h+1,h+tot+1)-(h+1);
sort(a+1,a+num+1);
int ans=0;
for(int i=1;i<=num;i++)
{
if(a[i].p==1)
{
add(ha(a[i].l),a[i].val);
}
else ans+=query(ha(a[i].r))-query(ha(a[i].l)-1);
}
cout<<ans+1<<endl;
}
return 0;
}
|