CF2165F.Arctic Acquisition
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation∗ a1,a2,…,an of length n.
An interval [l,r] (1≤l≤r≤n) is jagged if and only if it contains a 21435-subsequence; that is, there exist integers i1,i2,i3,i4,i5 such that l≤i1<i2<i3<i4<i5≤r, and ai2<ai1<ai4<ai3<ai5.
Your task is to calculate how many of the 2n(n+1) intervals are jagged.
∗A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
给你一个长度为 n 的排列∗ a1,a2,…,an。
区间 [l,r](其中 1≤l≤r≤n)被称为锯齿形的(jagged),当且仅当它包含一个 21435-子序列;即存在整数 i1,i2,i3,i4,i5,满足 l≤i1<i2<i3<i4<i5≤r,且
ai2<ai1<ai4<ai3<ai5.
你的任务是计算在全部 2n(n+1) 个区间中,有多少个是锯齿形的。
∗ 长度为 n 的排列是指由 1 到 n 中互不相同的 n 个整数以任意顺序组成的数组。例如,[2,3,1,5,4] 是一个排列,但 [1,2,2] 不是排列(数字 2 在数组中出现了两次),[1,3,4] 也不是排列(此时 n=3,但数组中出现了 4)。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤106) — the length of the permutation.
The second line of each test case contains n distinct integers a1,a2,…,an (1≤ai≤n).
It is guaranteed that the sum of n over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤106)—— 表示排列的长度。
每个测试用例的第二行包含 n 个互不相同的整数 a1,a2,…,an(1≤ai≤n)。
保证所有测试用例的 n 值之和不超过 106。
输出格式
For each test case, output the number of jagged subarrays.
对于每个测试用例,输出锯齿形子数组的数量。
输入输出样例
输入#1
5 5 2 1 4 3 5 10 10 3 5 2 1 4 9 8 6 7 15 3 9 15 6 11 10 5 13 12 7 4 8 14 1 2 12 10 7 12 5 4 1 2 9 3 8 6 11 30 22 30 7 17 4 13 26 28 24 20 2 11 27 21 5 19 9 10 23 14 1 25 6 8 3 18 29 12 16 15
输出#1
1 0 28 5 185
说明/提示
In the first test case, the only jagged subarray is [1,5], containing [2,1,4,3,5] as a subsequence.
In the third test case, the subarray [1,8] is jagged because it contains [9,6,11,10,13] as a subsequence, which is a 21435-subsequence.
在第一个测试用例中,唯一的锯齿子数组是 [1,5],它包含 [2,1,4,3,5] 作为其子序列。
在第三个测试用例中,子数组 [1,8] 是锯齿的,因为它包含 [9,6,11,10,13] 作为其子序列,而该子序列是一个 21435-子序列。
输入解题思路,AI测评打分。不知道怎么写?