AtCoder Beginner Contest 452
F
Interval Inversion Count
AtCoder
⌀ 1630
原题
←G →

Interval Inversion CountAI (CI翻译)

Problem Statement

You are given a positive integer $N$ and a permutation $P=(P _ 1,P _ 2,\ldots,P _ N)$ of $(1,2,\ldots,N)$.

You are given an integer $K$. Find the number of pairs of integers $(l,r)$ satisfying the following two conditions.

  • $1\le l\le r\le N$
  • The inversion number of the sequence $(P _ l,P _ {l+1},\ldots,P _ r)$ equals $K$.

Constraints

  • $1\le N\le5\times10 ^ 5$
  • $0\le K\le\dfrac{N(N-1)}2$
  • $1\le P _ i\le N\ (1\le i\le N)$
  • $P _ i\ne P _ j\ (1\le i\lt j\le N)$
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N K
P _ 1 P _ 2 \ldots P _ N

Output

Output the number of pairs of integers $(l,r)$ satisfying the conditions.

{"titleZh":"区间逆序数","bodyZh":"## 题目描述\n\n给定一个正整数 $N$ 和一个 $(1,2,\ldots,N)$ 的排列 $P=(P _ 1,P _ 2,\\ldots,P _ N)$。\n\n给定一个整数 $K$。请找出满足以下两个条件的整数对 $(l,r)$ 的数量。\n\n- $1\\le l\\le r\\le N$\n- 序列 $(P _ l,P _ {l+1},\\ldots,P _ r)$ 的逆序数等于 $K$。\n\n## 约束条件\n\n- $1\\le N\\le5\\times10 ^ 5$\n- $0\\le K\\le\\dfrac{N(N-1)}2$\n- $1\\le P _ i\\le N\\ (1\\le i\\le N)$\n- $P _ i\\ne P _ j\\ (1\\le i\\lt j\\le N)$\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入按以下格式给出:\n\n\nN K\nP _ 1 P _ 2 \\ldots P _ N\n\n\n## 输出格式\n\n输出满足条件的整数对 $(l,r)$ 的数量。"}AI (CI翻译)

样例

Input #1
7 3
6 3 2 1 7 5 4
Output #1
5
For example, the inversion number of the sequence $(P _ 1,P _ 2,P _ 3)=(6,3,2)$ is $3$, so $(l,r)=(1,3)$ satisfies the conditions. The other pairs satisfying the conditions are $(l,r)=(2,4),(2,5),(4,7),(5,7)$, so output `5`.
Input #2
4 1
1 2 3 4
Output #2
0
The inversion number of every contiguous subsequence of $P$ is $0$, so there are no pairs $(l,r)$ satisfying the conditions. Thus, output `0`.
Input #3
25 18
14 19 24 8 12 11 6 5 3 13 22 15 17 2 9 4 7 18 10 25 23 16 1 20 21
Output #3
3
题目信息
题号
abc452_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。