-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
65 lines (62 loc) · 1.62 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
65 lines (62 loc) · 1.62 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
diff --git a/CodeJam/Main.cpp b/examples/2019/KS_G/C/Main.cpp
index 2150379..fe56c14 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2019/KS_G/C/Main.cpp
@@ -1570,11 +1570,60 @@ void init(){
cin >> T;
}
+ll N, H;
+v(ll) Ai, Bi;
+
void readInput(){
+ cin >> N >> H;
+ Ai.cl;
+ Bi.cl;
+ ll t;
+ forn(i, N){
+ cin >> t;
+ Ai.pb(t);
+ }
+ forn(i, N){
+ cin >> t;
+ Bi.pb(t);
+ }
+}
+
+void recur(ll i, ll limit, ll AH, ll BH, v(v(ll))& possible_pairs){
+ if(i==limit){
+ possible_pairs[0].pb(AH);
+ possible_pairs[1].pb(BH);
+ return;
+ }
+ recur(i+1, limit, AH + Ai[i], BH, possible_pairs);
+ recur(i+1, limit, AH, BH + Bi[i], possible_pairs);
+ recur(i+1, limit, AH + Ai[i], BH + Bi[i], possible_pairs);
}
// write to COMM_TYPE result
void calcFunction() {
+ llog("computing poss pairs");
+ v(v(ll)) poss_pairs_half1(2);
+ v(v(ll)) poss_pairs_half2(2);
+ ll split = N/2;
+ recur(0, split, 0, 0, poss_pairs_half1);
+ recur(split, N, 0, 0, poss_pairs_half2);
+
+ BalancedRangeTree<ll> rt = BalancedRangeTree<ll>(poss_pairs_half2);
+ llog("finished constructing range tree");
+
+ result = 0;
+
+ forn(i, poss_pairs_half1[0].sz){
+ v(ll) low_limit;
+ v(ll) up_limit;
+ low_limit.pb(H-poss_pairs_half1[0][i]);
+ low_limit.pb(H-poss_pairs_half1[1][i]);
+ up_limit.pb(INF);
+ up_limit.pb(INF);
+ ll range_result = rt.get_range_count(low_limit, up_limit);
+ llog("range request:", i+1, "/", poss_pairs_half1[0].sz);
+ result += range_result;
+ }
}
} // namespace task