Description

There is a array contain N(1<N<=100000) numbers. Now give you M(1<M<10000) query.

Every query will be:

1 x : ask longest substring which every number no less than x

2 y x : change the A[y] to x. there are at most change 10 times.

For each ask can you tell me the length of longest substring.

Input

There are multiple tests.

each test first line contain two integer numbers N M,second line contain N integer numbers.

Next M lines each line will be:

1 x : ask longest substring which every number no less than x

2 y x : change the A[y] to x. there are at most change 10 times.

0 < N <= 100000, 0 < M <= 10000, -1000000000 <= A[i] <= 1000000000

Output

Each ask output the length of longest substring .

Sample Input

5 5
1 2 3 2 1
1 2
1 3
2 3 1
1 2
1 3

Sample Output

3
1
1
0
 
 
预处理出N个数值能到达的最大长度 。
按照数值从大到小插入。
然后记录一个 vis[i] ,  l[i] , r[i] 。
表示这个数据是否插入 , 向左能到达最远哪里 , 向右能到达最远哪里 。
操作1就直接2分答案。
操作2因为最多10个,就直接暴力来一次
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm> using namespace std; typedef long long LL;
typedef pair<int,int> pii;
const int mod = 1e9+;
const int N = ;
#define X first
#define Y second int n , q , a[N] ; struct OK {
int vis[N] , l[N] , r[N] ;
void init() {
memset( vis , false , sizeof vis ) ;
for( int i = ; i <= n ; ++i ) l[i] = r[i] = i ;
}
int GetLen( int i ) {
return r[i] - l[i] + ;
}
void Relax( int i ) {
if( vis[i+] ) r[i] = r[i+];
if( vis[i-] ) l[i] = l[i-] , r[l[i-]] = r[i] ;
if( vis[i+] ) l[r[i+]] = l[i];
}
}e;
struct node{
int x , res , id ;
bool operator < ( const node &a ) const {
return x < a.x ;
}
}p[N]; void test() {
for( int i = ; i <= n ; ++i ) cout << e.l[i] << ' ' ; cout << endl ;
for( int i = ; i <= n ; ++i ) cout << e.r[i] << ' ' ; cout << endl ;
for( int i = ; i <= n ; ++i )
cout << p[i].x << ' ' << p[i].res << endl ;
} void Solve() {
for( int i = ; i <= n ; ++i ) {
p[i].x = a[i] , p[i].id = i ;
}
sort( p + , p + n + ) ;
e.init(); p[n+].res = ;
for( int i = n ; i > ; --i ) {
int id = p[i].id ;
e.vis[id] = true ;
e.Relax(id);
p[i].res = max( p[i+].res , e.GetLen( p[i].id ));
}
} int Find( int num ) { int l = , r = n , pos = ;
if( num > p[n].x ) return ;
while( l <= r ) {
int mid = (l+r)>>;
if( p[mid].x < num )
l = mid + ;
else
pos = mid , r = mid - ;
}
return p[pos].res;
} void Run() {
for( int i = ; i <= n ; ++i ) {
scanf("%d",&a[i]);
}
Solve();
// test();
while(q--){
int op , x , y ;
scanf("%d%d",&op,&x);
if( op == ){
printf("%d\n",Find(x));
}
else {
scanf("%d",&y);
a[x] = y ; Solve();
// test();
}
}
} int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
while( scanf("%d%d",&n,&q)!=EOF )Run();
}

FZU 2059 MM的更多相关文章

  1. FZU 2059 MM (并查集+排序插入)

    Problem 2059 MM Accept: 109    Submit: 484Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem ...

  2. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  3. FZU 2165 v11(最小重复覆盖)+ codeforces 417D Cunning Gena

    告诉你若干个(<=100)武器的花费以及武器能消灭的怪物编号,问消灭所有怪物(<=100)的最小花费...当然每个武器可以无限次使用,不然这题就太水了╮(╯▽╰)╭ 这题当时比赛的时候连题 ...

  4. FZU Problem 2171 防守阵地 II (线段树区间更新模板题)

    http://acm.fzu.edu.cn/problem.php?pid=2171 成段增减,区间求和.add累加更新的次数. #include <iostream> #include ...

  5. 用pyspider爬淘宝MM照片

    #!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2016-12-09 15:24:54 # Project: taobaomm ...

  6. FZU 2137 奇异字符串 后缀树组+RMQ

    题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...

  7. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式

    java日期格式大全 format SimpleDateFormat(转) SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH ...

  8. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

  9. Allegro之测量时显示两种单位(mil & mm)

    首先确认你工程默认的单位是mil还是mm 例子为mils 在下面的选项中选择另外一项mm即可(如本身是mm,这里选择mils) 点击Apply,然后OK,操作测量功能,如下图所以效果:

随机推荐

  1. Linux关闭重启系统

    reboot:重启系统 - 需要root权限 halt:关机 - 需要root权限 poweroff:关机 - 可直接运行

  2. python常用函数 I

    iter(iterable) 可以生成一个迭代器. 例子: islice(iterator, int, int) itertools的islice方法为迭代器生成器提供切片操作. 例子: izip_l ...

  3. mysql的锁

    前言 mysql锁的概念参考如下连接: 1.http://blog.csdn.net/u013063153/article/details/53432468 2.http://www.yesky.co ...

  4. springboot打包成jar文件无法正常运行,解决办法已经找到

    1.用intellij idea 创建了一个springboot的项目,前期都运行的好好的,在ide中可以正常运行,但是打包成Jar运行却一直报错. 2.经过不懈探索,终于找到解决办法 3.首先,找到 ...

  5. .net core webapi添加swagger

    依赖项——右键——管理NuGet程序包——浏览——输入以下内容 Install-Package Swashbuckle.AspNetCore -Pre 双击Properties——点击生成——勾选XM ...

  6. javascaipt中数组元素删除方法delete和splice

    一.用delete 删除数组中元素(少用) 说明:delete: 只是被删除的元素变成了 undefined ,即数组长度不变 //定义数组 var array=["aa",&qu ...

  7. restful风格接口和spring的运用

    Restful风格的API是一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机 ...

  8. ps示例

    博客PS示例 一显示指定真正用户名(RUID)或用户ID的进程 打开另外一个终端 [root@centos72 ~]# id wang uid=1000(wang) gid=1000(wang) gr ...

  9. springboot实战(汪云飞)学习-1-1

    java EE开发的颠覆者 spring boot 实战 随书学习-1 1.学习案例都是maven项目,首先要在eclipse 中配置 maven,主要修改maven的配置文件:配置文件下载链接: h ...

  10. MyEclipse使用过程中的问题及对应设置的总结

    1.关闭 Javaweb项目中的updating index : Window => Preferences => Myeclipse Enterprise Workbench => ...