blackc4's blog

By blackc4, history, 19 months ago, In English

EDIT: It's resolved; see comments.

In hurry, I misread the "Good Subarrays" problems in Codeforces Round 825 (Div. 2) resulting in the following problems. The easy version is easier than the original easy, but I don't know if there is an $$$O(n)$$$ or $$$O(n\log n)$$$ algorithm for the corresponding hard version. I appreciate any hints towards $$$O(n)$$$ or $$$O(n\log n)$$$ algorithms.

New good arrays (easy version)

You are given an array $$$a = [a_1, \ldots, a_n]$$$. A position $$$i$$$ is good if $$$a_i \ge i$$$; a subarray $$$[a_{\ell},\ldots,a_r]$$$ is good if all the positions $$$\ell, \ell+1, \ldots, r$$$ are good. Find the number of good subarrays.

Solution idea

New good arrays (harder version)

Now you are, in addition, given $$$q$$$ updates to $$$a$$$, where $$$q \le n$$$. Unlike the original hard version, these updates are adaptive, i.e., they are not independent. Compute the number of good subarrays after each update. I claim that if the updates only increase the number, then again it is possible.

Monotonically increasing case

Full text and comments »

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