题目大意

题意

分析

题解见ygg

Code

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
int n,m;
int xx,yy;
using pll = pair<int,int>;

int lwb(int x){
return x & -x;
}

int t1[100005],t2[100005];

void upd(int p,int x,int f){
for(int i = p;i <= 100005;i+=lwb(i)){
if(f) t1[i] += 1;
else t2[i] += 1;
}
}


int ask(int p,int f){
int res = 0;
for(int i = p;i;i-=lwb(i)){
if(f) res += t1[i];
else res += t2[i];
}
return res;
}

int g = 0;

int get(vector<pll> t){
sort(t.begin(),t.end());
vector<int>f(t.size()+1);
for(int i = 0;i < t.size();i++){
f[i+1] = t[i].second;
}
vector<int> b(t.size()+1);
b = f;
sort(b.begin()+1,b.end());
for(int i = 1;i <= t.size();i++){
f[i] = lower_bound(b.begin()+1,b.end(),f[i]) - b.begin();
}
int res = 0;
if(!g){
for(int i = 1;i <= t.size();i++){
res += i - ask(f[i],g)-1;
upd(f[i],1,g);
}
}
else{
for(int i = 1;i <= t.size();i++){
res += i - ask(f[i],g)-1;
upd(f[i],1,g);
}
}
g++;
return res;
}
signed main()
{
cin >> n >> m;
cin >> xx >> yy;
int a = 2*(xx+yy);
int b = xx*yy;
vector<pll> x;
vector<pll> y;
while(xx--){
int l,r;cin >> l >> r;
x.push_back({l,r});
}
while(yy--){
int l,r;cin>>l>>r;
y.push_back({l,r});
}
// V - E + F = 2;
// V = a+b E = 3*a+4*b/2 F = mx + 1;
int nx = get(x);
int ny = get(y);
//cout<< nx <<" "<< ny << endl;
b +=nx + ny;
//cout << a <<" " << b << endl;
int res = (a+2*b)/2+1;
cout << res << endl;
return 0;
}