CF2184E.Exquisite Array

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

We call an array of numbers kk-exquisite if it has at least two elements and any two adjacent numbers differ by at least kk.

You are given a permutation∗^{\text{∗}} pp of length nn. For each kk from 11 to n−1n - 1, find the number of kk-exquisite subarrays†^{\text{†}}.

∗^{\text{∗}}A permutation of length nn is an array that contains each integer from 11 to nn exactly once, in any order.

†^{\text{†}}A subarray of an array is a sequence of one or more consecutive elements of the array.

我们称一个数字数组为 kk-精致的,如果它至少包含两个元素,且任意两个相邻数字之差的绝对值至少为 kk。

给定一个长度为 nn 的排列∗^{\text{∗}} pp。对每个从 11 到 n−1n - 1 的 kk,求出 pp 中 kk-精致子数组†^{\text{†}} 的个数。

∗^{\text{∗}} 长度为 nn 的排列是指由 11 到 nn 中每个整数恰好出现一次(顺序任意)所构成的数组。

†^{\text{†}} 数组的一个子数组是指该数组中一个或多个连续元素所组成的序列。

输入格式

Each test consists of several test cases. The first line contains a single integer tt (1≤t≤25000)(1 \le t \le 25000) — the number of test cases. The descriptions of the test cases follow.

In the first line of each test case, an integer nn is given — the length of the permutation (2≤n≤105)(2 \le n \le 10^5).

In the second line of each test case, nn integers pip_i are given — the elements of the permutation (1≤pi≤n)(1 \le p_i \le n). It is guaranteed that pip_i are distinct.

It is guaranteed that the sum of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含若干测试用例。第一行包含一个整数 tt(1≤t≤250001 \le t \le 25000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行给出一个整数 nn,表示排列的长度(2≤n≤1052 \le n \le 10^5)。

每个测试用例的第二行给出 nn 个整数 pip_i,表示该排列的元素(1≤pi≤n1 \le p_i \le n)。保证所有 pip_i 互不相同。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output the number of kk-exquisite subarrays for all kk from 11 to n−1n - 1.

对于每个测试用例,输出所有 kk(从 11 到 n−1n - 1)对应的 kk-精致子数组的个数。

输入输出样例

  • 输入#1

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

    输出#1

    10 6 3 1 
    3 0 
    6 2 0

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

首页