CF1404C.Fixed Point Removal
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let a1,…,an be an array of n positive integers. In one operation, you can choose an index i such that ai=i , and remove ai from the array (after the removal, the remaining parts are concatenated).
The weight of a is defined as the maximum number of elements you can remove.
You must answer q independent queries (x,y) : after replacing the x first elements of a and the y last elements of a by n+1 (making them impossible to remove), what would be the weight of a ?
输入格式
The first line contains two integers n and q ( 1≤n,q≤3⋅105 ) — the length of the array and the number of queries.
The second line contains n integers a1 , a2 , ..., an ( 1≤ai≤n ) — elements of the array.
The i -th of the next q lines contains two integers x and y ( x,y≥0 and x+y<n ).
输出格式
Print q lines, i -th line should contain a single integer — the answer to the i -th query.
输入输出样例
输入#1
13 5 2 2 3 9 5 4 6 5 7 8 3 11 13 3 1 0 0 2 4 5 0 0 12
输出#1
5 11 6 1 0
输入#2
5 2 1 4 1 2 4 0 0 1 0
输出#2
2 0
说明/提示
Explanation of the first query:
After making first x=3 and last y=1 elements impossible to remove, a becomes [×,×,×,9,5,4,6,5,7,8,3,11,×] (we represent 14 as × for clarity).
Here is a strategy that removes 5 elements (the element removed is colored in red):
- [×,×,×,9,5,4,6,5,7,8,3,11,×]
- [×,×,×,9,4,6,5,7,8,3,11,×]
- [×,×,×,9,4,6,5,7,8,3,×]
- [×,×,×,9,4,5,7,8,3,×]
- [×,×,×,9,4,5,7,3,×]
- [×,×,×,9,4,5,3,×] (final state)
It is impossible to remove more than 5 elements, hence the weight is 5 .