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. JVM(11)之 G1收集器

    开发十年,就只剩下这套架构体系了! >>>   在前两篇博文中讲解了新生代和年老代的收集器,在本篇博文中介绍一个收集范围涵盖整个堆的收集器--G1收集器.  先讲讲G1收集器的特点, ...

  2. JVM(1)之 JAVA栈

    开发十年,就只剩下这套架构体系了! >>>   若想使自己编写的Java程序高效运行,以及进行正确.高效的异常诊断,JVM是不得不谈的一个话题.本"JVM进阶"专 ...

  3. 【JAVA】java中的length和length()

    参考链接: 你注意到Java中的length和length()了吗?外加一个size() java中的求长度length有时有小括号,有时没有小括号,到底什么时候该加小括号呢? 总结: Java中St ...

  4. Dubbo源码学习总结系列二 dubbo-rpc远程调用模块

    dubbo本质是一个RPC框架,我们首先讨论这个骨干中的骨干,dubbo-rpc模块. 主要讨论一下几部分内容: 一.此模块在dubbo整体框架中的作用: 二.此模块需要完成的需求功能点及接口定义: ...

  5. NVIDIA Jetson™ TX1

    NVIDIA® Jetson TX1 是一台模块式计算机,代表了视觉计算领域近20年的研发成就,其尺寸仅有信用卡大小.Jetson TX1 基于崭新 NVIDIA Maxwell™ 架构,配有256个 ...

  6. ES6 的基础教程

    一.介绍 1.历史 ECMAScript和JavaScript ECMA是标准,JS是实现 类似于HTML5是标准,IE10.Chrome.FF都是实现 换句话说,将来也能有其他XXXScript来实 ...

  7. Go的学习 sort

    1.排序操作主要都在 sort包中,导入就可以使用了 2.sort.Ints对整数进行排序 package main; import ( "fmt" "sort" ...

  8. centos 6.5 配置 DNS

    编辑 vi /etc/resolv.conf 修改 DNS nameserver 202.96.134.133 nameserver 202.96.128.86 nameserver 8.8.8.8 ...

  9. nyoj 600:花儿朵朵(树状数组+坐标离散化)

    http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using name ...

  10. SpringBoot JSON文件读取

    @Componentpublic class StepExecutor implements Runnable { @Value("classpath:menu.json") pr ...