-
Notifications
You must be signed in to change notification settings - Fork 0
/
812-b.cpp
105 lines (96 loc) · 1.93 KB
/
812-b.cpp
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
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"
using namespace std;
#define A first
#define B second
typedef long long ll;
constexpr int MOD = 1e9 + 7;
bool cmp(pair<int, int>& x, pair<int, int>& y) {
if(x.B < y.B) return true;
else if(x.B == y.B && (x.A < y.A)) return true;
return false;
}
void solve(){
int N, M, K;
cin >> N >> M >> K;
vector<int> X(N), Y(M);
set<int> XP, YP;
for(int i = 0; i < N; i++) {
cin >> X[i];
XP.insert(X[i]);
}
for(int i = 0; i < M; i++) {
cin >> Y[i];
YP.insert(Y[i]);
}
vector<pair<int, int>> P(K);
for(int i = 0; i < K; i++) {
cin >> P[i].A >> P[i].B;
}
sort(P.begin(), P.end());
map<int, map<int, int>> mp;
map<int, int> cnt;
for(int i = 0; i < K; i++) {
int idx = lower_bound(X.begin(), X.end(), P[i].A) - X.begin();
if(P[i].A == X[idx]) continue;
idx--;
mp[idx][P[i].B]++;
cnt[idx]++;
}
ll ans1 = 0;
for(auto x: mp) {
map<int, int> mp2 = x.B;
for(auto y: mp2) {
ll rem = cnt[x.A] - y.B;
ans1 += rem * y.B;
}
}
ll ans = ans1 / 2;
sort(P.begin(), P.end(), cmp);
mp.clear();
cnt.clear();
for(int i = 0; i < K; i++) {
int idx = lower_bound(Y.begin(), Y.end(), P[i].B) - Y.begin();
if(P[i].B == Y[idx]) continue;
idx--;
mp[idx][P[i].A]++;
cnt[idx]++;
}
ll ans2 = 0;
for(auto x: mp) {
map<int, int> mp2 = x.B;
for(auto y: mp2) {
ll rem = cnt[x.A] - y.B;
ans2 += rem * y.B;
}
}
ans += ans2 / 2;
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T;
T = 1;
cin >> T;
while(T--){
solve();
}
}