#P15070. [UOI 2024 II Stage] Sequence

    ID: 16999 远端评测题 1500ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP线段树2024UOI(乌克兰)

[UOI 2024 II Stage] Sequence

题目描述

Anton is under pressure --- he has to submit all the assignments. As often happens --- he cannot extend the deadline...

You are given a sequence aa of nn integers, and two integers ll and rr. You need to find the longest subsequence bb of the sequence aa such that lbi+bi+1rl \le b_i + b_{i+1} \le r (1i<b1 \le i < |b|). Here, b|b| denotes the number of elements in the sequence bb. In other words, you need to select a subsequence such that the sum of any two adjacent numbers is not less than ll and not greater than rr.

A subsequence of an array is a sequence that can be obtained by deleting several (possibly none) elements from the original sequence.

输入格式

The first line contains three integers nn, ll, rr (1n51051 \le n \le 5 \cdot 10^5, 1lr10171 \le l \le r \le 10^{17}).

The second line contains nn integers aia_i (1air1 \le a_i \le r) --- the description of the sequence.

输出格式

Output a single integer --- the maximum length of such a subsequence bb.

5 2 6
1 3 4 2 5
3
2 1 1
1 1
1

提示

In the first example, you can select the subsequence [1,3,2][1, 3, 2]. 21+362 \leq 1 + 3 \leq 6. 23+262 \leq 3 + 2 \leq 6.

You can also select [1,4,2][1, 4, 2].

Scoring

  • (11 point): all aia_i are the same;
  • (33 points): ai=ai+2a_i = a_{i+2} for all 1in21 \le i \le n-2;
  • (99 points): n20n \le 20;
  • (88 points): n5000n \le 5000;
  • (99 points): rl10r - l \le 10;
  • (1010 points): l=1,r106l = 1, r \le 10^6;
  • (1313 points): r106r \le 10^6;
  • (1010 points): l=1l = 1;
  • (2424 points): n105n \le 10^5;
  • (1313 points): no additional constraints.