luogu#P10798. 「CZOI-R1」消除威胁

「CZOI-R1」消除威胁

Background

The testdata for this problem has been fixed.

Problem Description

Given a sequence {An}\{A_n\}.

We say an interval [l,r][l,r] in sequence AA is a threat if and only if 1l<rn1 \le l < r \le n and Al=ArA_l = A_r, and i[l,r]\forall i \in [l,r] satisfies AiAl|A_i| \le |A_l|.

You may perform any number of operations on AA. In each operation, choose an AiA_i and change it to Ai-A_i. What is the minimum number of distinct threat intervals in the final sequence AA?

Two intervals [l1,r1][l_1,r_1] and [l2,r2][l_2,r_2] are different if and only if l1l2l_1 \ne l_2 or r1r2r_1 \ne r_2.

Input Format

The first line contains an integer nn, denoting the length of AA.

The second line contains nn integers, denoting {An}\{A_n\}.

Output Format

The first line contains a positive integer, denoting the minimum number of threat intervals.

8
3 2 1 2 3 -1 3 3
2

Hint

Constraints

This problem uses bundled tests.

  • Subtask #1 (10 pts10\text{ pts}): n10n \le 10.
  • Subtask #2 (10 pts10\text{ pts}): n103n \le 10^3.
  • Subtask #3 (10 pts10\text{ pts}): Ai60|A_i| \le 60.
  • Subtask #4 (10 pts10\text{ pts}): all Ai|A_i| are equal.
  • Subtask #5 (20 pts20\text{ pts}): n105n \le 10^5.
  • Subtask #6 (40 pts40\text{ pts}): no special constraints.

For 100%100\% of the testdata, 1n5×1051 \le n \le 5 \times 10^5 and Ai109|A_i| \le 10^9.

Translated by ChatGPT 5