Skip to content

Commit 58f8fe1

Browse files
committed
regular update
1 parent 3610301 commit 58f8fe1

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

Codeforces/150C_107.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ qtype query (int u, int x, int y) {
5353
qtype a = {-1e20, -1e20, -1e20}, b = {-1e20, -1e20, -1e20}, ret;
5454
if (x <= mid) a = query (u<<1, x, y);
5555
if (y > mid) b = query (u<<1|1, x, y);
56-
ret.ma = max(a.ma, b.ma);
57-
if (x <= mid && y > mid) {
58-
ret.ma = max (ret.ma, a.mr + b.ml);
59-
}
56+
ret.ma = max (max (a.ma, b.ma), a.mr + b.ml);
6057
ret.ml = a.ml;
6158
if (x <= L[u] && y > mid)
6259
ret.ml = max (ret.ml, sum[u<<1] + b.ml);

Codeforces/150C_107.ml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
let ( |> ) v f = f v
2+
let ( <| ) f v = f v
3+
let foi = float_of_int
4+
let iof = int_of_float
5+
6+
let next_int () = Scanf.scanf "%d%c" (fun x _ -> x)
7+
let next_flt () = Scanf.scanf "%f%c" (fun x _ -> x)
8+
9+
let rec show_flt_list a =
10+
match a with
11+
[] -> print_newline ()
12+
| x::xs -> print_float x; print_string " "; show_flt_list xs
13+
14+
15+
let rec loop n f acc =
16+
if n = 0 then List.rev acc
17+
else loop (n - 1) f ( (f n) :: acc)
18+
19+
20+
type data = {ma : float; lv : float; rv : float; sum : float}
21+
type range = {l: int; r : int}
22+
23+
type seg_tree =
24+
Leaf of data
25+
| Node of int * int * data * seg_tree * seg_tree
26+
27+
28+
let get_data tr =
29+
match tr with
30+
Leaf d
31+
| Node (_, _, d, _, _) -> d
32+
33+
34+
let update dlc drc =
35+
let s = dlc.sum +. drc.sum in
36+
let l = max dlc.lv (dlc.sum +. drc.lv) in
37+
let r = max drc.rv (drc.sum +. dlc.rv) in
38+
let m = max (max dlc.ma drc.ma) (dlc.rv +. drc.lv) in
39+
{ma = m; lv = l; rv = r; sum = s;}
40+
;;
41+
42+
let n = next_int ()
43+
let m = next_int ()
44+
let c = next_flt ()
45+
46+
let d = loop n (fun _ -> next_flt ()) []
47+
let p = loop (n - 1) (fun _ -> ((next_flt ()) /. 100.0)) []
48+
49+
let v = List.map (fun (a, b) -> a -. b) (List.combine (List.tl d) (List.rev (List.tl (List.rev d))))
50+
let a = Array.of_list <| List.map (fun (a, b) -> a /. 2.0 -. b *. c) (List.combine v p)
51+
52+
53+
let rec build x y =
54+
if x = y then Leaf ({ma = max (foi 0) a.(x); lv = a.(x); rv = a.(x); sum = a.(x)})
55+
else begin
56+
let mid = (x + y) / 2 in
57+
let lc = build x mid in
58+
let rc = build (mid+1) y in
59+
Node (x, y, (update (get_data lc) (get_data rc)), lc, rc)
60+
end
61+
62+
let rec query tr x y =
63+
match tr with
64+
Leaf d -> d
65+
| Node (l, r, d, lc, rc) -> begin
66+
if x <= l && y >= r then d
67+
else
68+
let mid = (l + r) / 2 in
69+
let snt = {ma = -1e20; lv = -1e20; rv = -1e20; sum = -1e20} in
70+
let qlc = if x <= mid then query lc x y else snt in
71+
let qrc = if y > mid then query rc x y else snt in
72+
update qlc qrc
73+
end
74+
75+
let tr = build 0 (n - 2)
76+
77+
let () =
78+
loop m (fun _ -> (let a = next_int() in
79+
let b = next_int() in
80+
query tr (a - 1) (b - 2)).ma) []
81+
|> List.fold_left (+.) (foi 0)
82+
|> print_float
83+
84+
85+

0 commit comments

Comments
 (0)