CF1332G.No Monotone Triples

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given a sequence of integers aa of length nn, a tuple (i,j,k)(i,j,k) is called monotone triples if

  • 1≤i<j<k≤n1 \le i \lt j \lt k\le n;
  • ai≤aj≤aka_i \le a_j \le a_k or ai≥aj≥aka_i \ge a_j \ge a_k is satisfied.

For example, a=[5,3,4,5]a=[5,3,4,5], then (2,3,4)(2,3,4) is monotone triples for sequence aa while (1,3,4)(1,3,4) is not.

Bob is given a sequence of integers aa of length nn in a math exam. The exams itself contains questions of form L,RL, R, for each of them he is asked to find any subsequence bb with size greater than 22 (i.e. ∣b∣≥3|b| \ge 3) of sequence aL,aL+1,…,aRa_L, a_{L+1},\ldots, a_{R}.

Recall that an sequence bb is a subsequence of sequence aa if bb can be obtained by deletion of several (possibly zero, or all) elements.

However, he hates monotone stuff, and he wants to find a subsequence free from monotone triples. Besides, he wants to find one subsequence with the largest length among all subsequences free from monotone triples for every query.

Please help Bob find out subsequences meeting the above constraints.

给定一个长度为 nn 的整数序列 aa,若三元组 (i,j,k)(i,j,k) 满足以下条件,则称其为单调三元组(monotone triples):

  • 1≤i<j<k≤n1 \le i \lt j \lt k\le n;
  • 满足 ai≤aj≤aka_i \le a_j \le a_k 或 ai≥aj≥aka_i \ge a_j \ge a_k。

例如,当 a=[5,3,4,5]a=[5,3,4,5] 时,(2,3,4)(2,3,4) 是序列 aa 的一个单调三元组,而 (1,3,4)(1,3,4) 则不是。

鲍勃在一次数学考试中被给定了一个长度为 nn 的整数序列 aa。考试题目包含若干形如 L,RL, R 的询问,对每个询问,他需要在子数组 aL,aL+1,…,aRa_L, a_{L+1},\ldots, a_{R} 中找出一个长度大于 22(即 ∣b∣≥3|b| \ge 3)的子序列 bb。

回顾定义:若序列 bb 可通过从序列 aa 中删除若干(可能为零个、也可能为全部)元素得到,则称 bb 是 aa 的一个子序列。

然而,鲍勃讨厌一切单调性质,因此他希望找到一个不含任何单调三元组的子序列。此外,对于每个询问,他希望找到所有不含单调三元组的子序列中长度最大者。

请帮助鲍勃找出满足上述所有约束条件的子序列。

输入格式

The first line contains two integers nn, qq (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5, 1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the length of sequence aa and the number of queries.

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots, a_n (1≤ai≤1091 \le a_i \le 10^{9}), representing the sequence aa.

Then each of the following qq lines contains two integers LL, RR (1≤L,R≤n1 \le L,R \le n, R−L≥2R-L\ge 2).

第一行包含两个整数 nn、qq(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5,1≤q≤2⋅1051 \le q \le 2 \cdot 10^5)—— 分别表示序列 aa 的长度和查询次数。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots, a_n(1≤ai≤1091 \le a_i \le 10^{9}),表示序列 aa。

接下来的 qq 行中,每行包含两个整数 LL、RR(1≤L,R≤n1 \le L,R \le n,且 R−L≥2R-L\ge 2)。

输出格式

For each query, output 00 if there is no subsequence bb satisfying the constraints mentioned in the legend. You can print the empty line after but that's not mandatory.

Otherwise, output one integer kk (k>2k \gt 2) denoting the length of sequence bb, then output kk integers i1,i2,…,iki_1, i_2, \ldots, i_k (L≤i1<i2<…<ik≤RL \le i_1 \lt i_2 \lt \ldots \lt i_k\le R) satisfying that bj=aijb_j = a_{i_j} for 1≤j≤k1 \le j \le k.

If there are multiple answers with the maximum length, print any of them.

对于每个查询,若不存在满足题面中所述约束条件的子序列 bb,则输出 00。可在其后输出空行,但非必需。

否则,先输出一个整数 kk(k>2k \gt 2),表示序列 bb 的长度;然后输出 kk 个整数 i1,i2,…,iki_1, i_2, \ldots, i_k(满足 L≤i1<i2<…<ik≤RL \le i_1 \lt i_2 \lt \ldots \lt i_k\le R),使得对所有 1≤j≤k1 \le j \le k 均有 bj=aijb_j = a_{i_j}。

若存在多个具有最大长度的答案,输出任意一个即可。

输入输出样例

  • 输入#1

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

    输出#1

    3
    1 2 3 
    0

说明/提示

For the first query, the given sequence itself is monotone triples free.

For the second query, it can be shown that there is no subsequence bb with length greater than 22 such that bb is monotone triples free.

对于第一个查询,给定序列本身不包含单调三元组。

对于第二个查询,可以证明:不存在长度大于 22 的子序列 bb,使得 bb 不包含单调三元组。

输入解题思路,AI测评打分。不知道怎么写?

首页