#P10833. [COTS 2023] 下 Niz

    ID: 12287 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>线段树2023O2优化分治哈希 hashingCOCI(克罗地亚)单调栈

[COTS 2023] 下 Niz

Background

Translated from Izborne Pripreme 2023 (Croatian IOI/CEOI Team Selection) D2T2。1s,0.5G\texttt{1s,0.5G}。

Happy birthday to NaCly_Fish!(2024.7.28)。

Problem Description

Given a sequence aa of length NN, find the number of pairs (l,r)(l,r) that satisfy the following conditions:

  • 1≤l≤r≤N1\le l\le r\le N;
  • al,al+1,⋯ ,ar−1,ara_l,a_{l+1},\cdots,a_{r-1},a_r is a permutation of 1∼r−l+11\sim r-l+1。

Input Format

The first line contains a positive integer NN, representing the length of the sequence.

The second line contains NN positive integers describing the sequence aa。

Output Format

Output one integer in a single line, the number of pairs (l,r)(l,r) that satisfy the conditions.

3
3 1 2 
3
5
3 2 1 2 3
5
7
2 1 3 1 2 3 4
8

Hint

Sample Explanation

Explanation for Sample 33: the pairs (l,r)(l,r) that satisfy the conditions are (2,2),(1,2),(1,3),(4,4),(4,5),(4,6),(4,7),(3,5)(2,2),(1,2),(1,3),(4,4),(4,5),(4,6),(4,7),(3,5)。

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1≤N≤1061\le N\le 10^6;
  • 1≤ai≤N1\le a_i\le N。
Subtask ID Score Constraints
11 1313 Each number appears exactly once in the sequence.
22 2020 N≤5 000N\le 5\, 000
33 3333 N≤50 000N\le 50\, 000
44 3434 No additional constraints.

Translated by ChatGPT 5