Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible but he doesn't remember exactly the heights of all trees in the forest. He is sure that he remembers correct heights of all trees except, possibly, one of them.

It is known that the forest consists of n trees staying in a row numbered from left to right with integers from 1 to n. According to Vasya, the height of the i-th tree is equal to hi. The zip-line of length k should hang over k (1 ≤ k ≤ n) trees i1, i2, ..., ik (i1 < i2 < ... < ik) such that their heights form an increasing sequence, that is hi1 < hi2 < ... < hik.

Petya had been in this forest together with Vasya, and he now has q assumptions about the mistake in Vasya's sequence h. His i-th assumption consists of two integers ai and bi indicating that, according to Petya, the height of the tree numbered ai is actually equal to bi. Note that Petya's assumptions are independent from each other.

Your task is to find the maximum length of a zip-line that can be built over the trees under each of the q assumptions.

In this problem the length of a zip line is considered equal to the number of trees that form this zip-line.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 400 000) — the number of the trees in the forest and the number of Petya's assumptions, respectively.

The following line contains n integers hi (1 ≤ hi ≤ 109) — the heights of trees according to Vasya.

Each of the following m lines contains two integers ai and bi (1 ≤ ai ≤ n, 1 ≤ bi ≤ 109).

Output

For each of the Petya's assumptions output one integer, indicating the maximum length of a zip-line that can be built under this assumption.

Examples

Input
4 4
1 2 3 4
1 1
1 4
4 3
4 5
Output
4
3
3
4
Input
4 2
1 3 2 6
3 5
2 4
Output
4
3

题意:给定一个数组,Q次询问,询问之间彼此独立。每次询问改动一个数,问改动后的LIS。

思路:同今年南京(湘潭)的邀请赛J题,当时思路差不多对了,但是想复杂了,我和陈队花了一个半小时还是写WA了。注意到新LIS和原来的LIS最多相差1。也就是max-1,max,max+1三种情况,那么我们分两步去验证即可:

  第一步,考虑没了原来的值:假设原来的LIS一定经过更改点,那么先把ans赋值为max-1;否则赋值ans为max。

第二步,考虑有了新来的值:即用到新的值,那么预处理的时候从前向后后从后向前扫,两遍预处理完,ans=max(ans,f[i]+g[i]-1)。

第二步用线段树或者树状数组即可搞定,常规操作。

第一步,其实也不难想,当时就是这里想复杂了。我们得到LISmax,然后f[i]表示以i为结束的LIS,g[i]表示以i为起点的LIS。如果f[i]+g[i]-1==max,那么种数那么cnt[f[i]]++;   讨论替换i点时,如果cnt[f[i]]==1,则说明原来的LIS必定经过i点。

最新文章

  1. linux mysql-5.6.26 安装
  2. Less环境搭建
  3. 单词游戏-基于SQLite+Qt的C++项目
  4. MotionEvent
  5. 【英语】Bingo口语笔记(3) - 无所谓
  6. 关于Windows环境下安装Android模拟器Genymotion的教程
  7. java log日志的输出。
  8. POJ 2955 括号匹配,区间DP
  9. HTML&amp;CSS基础学习笔记1.4-定义文档类型
  10. asp.net 二级域名session共享
  11. 简易RPC框架-上下文
  12. setInterval计时器延时问题
  13. Java基础--面向对象编程2(封装)
  14. 如何一步一步新建一个Owin项目
  15. 技术的热门度曲线:GHC
  16. 在python中使用正则表达式(二)
  17. react表单事件和取值
  18. 二 random模块
  19. SqlServer 查看备份文件中逻辑文件信息的Sql语句
  20. LSTM简介以及数学推导(FULL BPTT)

热门文章

  1. Python基础(16)_面向对象程序设计(类、继承、派生、组合、接口)
  2. maven 项目打包时无法解析读取properties文件
  3. PAT 天梯赛 L1-034. 点赞 【MAP】
  4. 转:CWebBrowser2去除边框、滚动条、右键菜单
  5. Linux Shell编程 cut、print命令
  6. 【鸟哥的Linux私房菜】笔记2
  7. 主攻ASP.NET.4.5.1 MVC5.0之重生:系统角色与权限(一)
  8. C++学习 之pair
  9. 20145230《java学习笔记》第十周学习总结
  10. 20145231《Java程序设计》第二次实验报告