nhphuc's blog

By nhphuc, history, 13 months ago, In English

Link to contest (statement in Vietnamese): https://lqdoj.edu.vn/contest/dhbb23, problem link: https://lqdoj.edu.vn/problem/dhbb23hkdata. (you must virtual join the contest before open the problem)

Summary: Given a array $$$a$$$ with $$$n$$$ elements, the cost of this array is the maximum value of $$$|\sum^{R}_{i = L}\ a_i|$$$ among all pairs $$$1\leq L\leq R\leq n$$$. There are $$$q$$$ $$$\bf {independent}$$$ updates of the form $$$l\ r\ c$$$: increase all elements from $$$l$$$ to $$$r$$$ by $$$c$$$, then calculate the cost of array after the update. $$$n,\ q\leq 10^5,\ |a_i|,\ |c|\leq 10^9$$$.

Thanks for your help and attention, have a good day.

Update: I just solved this problem using a CHT Segment Tree (code here: https://ideone.com/5BWLxX), thanks for all the help!

  • Vote: I like it
  • +12
  • Vote: I do not like it

| Write comment?
»
13 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

If the absolute value sign is eliminated, it should be a simple segment tree problem.

To eliminated the absolute value sign, we could see that

$$$|\sum_{i=L}^R a_i| = max(max_{1 \le L \le R \le n}(\sum_{i=L}^R a_i), -min_{1 \le L \le R \le n}(\sum_{i=L}^R a_i))$$$

Now the problem could be easily solved by a segment tree.

Edit: fixed some grammatical mistakes

»
13 months ago, hide # |
 
Vote: I like it +22 Vote: I do not like it

By looking at prefix sums this is just the difference between maximum and minimum, and the updates add linear functions (also by bijection of prefix sums, this problem is equivalent)

https://judge.yosupo.jp/problem/range_linear_add_range_min

The general idea I know of is to maintain the dynamic upper convex hull $$$(i, A_i)$$$ with a segment tree. This gives in particular the maximum value, and the updates are friendly to it, but the idea is nontrivial. You can read about it here:

https://mirror.codeforces.com/blog/entry/75929

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by nhphuc (previous revision, new revision, compare).