-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
46 lines (43 loc) · 1.78 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
46 lines (43 loc) · 1.78 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
diff --git a/CodeJam/Main.cpp b/examples/2019/Round1B/C/Main.cpp
index 2150379..6c305b7 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2019/Round1B/C/Main.cpp
@@ -1570,11 +1570,41 @@ void init(){
cin >> T;
}
+ll N, K;
+v(ll) Ci, Di;
+
void readInput(){
+ cin >> N >> K;
+ Ci.cl;
+ Di.cl;
+ forn(i, N){
+ ll t;
+ cin >> t;
+ Ci.pb(t);
+ }
+ forn(i, N){
+ ll t;
+ cin >> t;
+ Di.pb(t);
+ }
}
// write to COMM_TYPE result
void calcFunction() {
+ result = 0;
+ RangeMinMaxTable<ll> lookup_C(Ci, false);
+ RangeMinMaxTable<ll> lookup_D(Di, false);
+ forn(i, N){
+ auto charles_chooses_i_and_is_good_lower = [&](ll l){return Ci[i] >= Di[lookup_D.query(l, i+1)] - K && lookup_C.query(l, i+1) == i;};
+ auto not_charles_chooses_i_and_is_good_upper = [&](ll u){return !(Ci[i] >= Di[lookup_D.query(i, u)] - K && lookup_C.query(i, u) == i);};
+ auto charles_chooses_i_and_is_too_good_lower = [&](ll l){return Ci[i] > Di[lookup_D.query(l, i+1)] + K && lookup_C.query(l, i+1) == i;};
+ auto not_charles_chooses_i_and_is_too_good_upper = [&](ll u){return !(Ci[i] > Di[lookup_D.query(i, u)] + K && lookup_C.query(i, u) == i);};
+ ll low_good_enough = lower_bound_function<ll,bool>(true, charles_chooses_i_and_is_good_lower, i+1);
+ ll low_too_good = lower_bound_function<ll,bool>(true, charles_chooses_i_and_is_too_good_lower, i+1);
+ ll up_good_enough = upper_bound_function<ll,bool>(false, not_charles_chooses_i_and_is_good_upper, N-i, i+1);
+ ll up_too_good = upper_bound_function<ll,bool>(false, not_charles_chooses_i_and_is_too_good_upper, N-i, i+1);
+ result += (i+1-low_good_enough) * (up_good_enough-1-i) - (i+1-low_too_good) * (up_too_good-1-i);
+ }
}
} // namespace task