-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathb1.cpp
More file actions
74 lines (71 loc) · 1.61 KB
/
Copy pathb1.cpp
File metadata and controls
74 lines (71 loc) · 1.61 KB
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
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int T, N, A[500000], B[500000], Q, X[500000], Y[500000], MOD = 1e9+7;
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> T;
for(int tc = 1; tc <= T; tc++){
moo << "Case #" << tc << ": ";
eat >> N;
priority_queue<int, vector<int>, greater<int>> xa, xb, ya, yb;
priority_queue<int> xa2, xb2, ya2, yb2;
for(int i = 0; i < N; i++){
eat >> A[i] >> B[i];
xa.push(A[i]);
ya.push(B[i]);
xa2.push(A[i]);
ya2.push(B[i]);
}
eat >> Q;
for(int i = 0; i < Q; i++){
eat >> X[i] >> Y[i];
xb.push(X[i]);
yb.push(Y[i]);
xb2.push(X[i]);
yb2.push(Y[i]);
}
int ans = 0;
for(int swapxy = 0; swapxy < 2; swapxy++){
int x = 0, dx = 0, ddx = 0;
for(int i = 0; i <= 3000; i++){
while(!xa.empty() && xa.top() == i){
dx -= 1;
ddx += 2;
xa.pop();
}
while(!xb.empty() && xb.top() == i){
ans = (ans + x) % MOD;
//moo << x << " " << dx << ' ' << ddx << endl;
xb.pop();
}
//moo << x << ' ' << dx << ' '<< ddx << endl;
dx = (dx + ddx) % MOD;
x = (x + dx) % MOD;
}
x = 0, dx = 0, ddx = 0;
for(int i = 3000; i >= 0; i--){
while(!xa2.empty() && xa2.top() == i){
dx -= 1;
ddx += 2;
xa2.pop();
}
while(!xb2.empty() && xb2.top() == i){
ans = (ans + x) % MOD;
//moo << x << " " << dx << ' ' << ddx << endl;
xb2.pop();
}
dx = (dx + ddx) % MOD;
x = (x + dx) % MOD;
}
swap(xa, ya);
swap(xb, yb);
swap(xa2, ya2);
swap(xb2, yb2);
}
moo << ans << endl;
}
}