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. python 关于每个项目的解释器

    在写程序的时候发现了一个问题,就是我原来import的第三方包,在新建的项目里仍然报错,还需要重新下载一次 发现:原来每建一个新项目,python会默认生成另一个新的解释器和相关虚拟环境,包括第三方包 ...

  2. 10.Servlet简单介绍

    1.什么是Servlet * Servlet是javaweb的三大组件之一,它属于动态资源.Servlet的作用是处理请求,服务器会把接收到的请求交给Servlet来处理,在Servlet种通常需要: ...

  3. C# 创建日志

    public void Log(string message) { try { string logFileName = "c:\\log\\LogName" + DateTime ...

  4. 【8.0.0_r4】AMS架构与流程分析

    AMS主要用来管理应用程序的生命周期,以及其核心组件,包括Activity,Service,Provider,Broadcast,Task等 之前整体架构如下图(O上已经废弃) 新的架构比较直接,简化 ...

  5. .Net Core 使用 Swagger 提供API文档

    1.运行环境 开发工具:Visual Studio 2017 JDK版本:.NET Core 2.0 项目管理工具:nuget 2.GITHUB地址 https://github.com/nbfujx ...

  6. PHP curl_init函数

    curl_init — 初始化一个cURL会话 说明 resource curl_init ([ string $url = NULL ] ) 初始化一个新的会话,返回一个cURL句柄,供curl_s ...

  7. APICloud框架——总结一下最近开发APP遇到的一些问题 (三)

    ajax报错 Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 需要在服务器环境下 ...

  8. ajax 封装(集中 认证、错误、请求loading处理)

    一.为什么要对 ajax 进行封装:    (在使用antd pro 开发项目时,里面默认是把请求进行了封装的,放在 utils/request.js 中.使用起来非常方便   https://pro ...

  9. Linux sudo 详解

    简单的说,sudo 是一种权限管理机制,管理员可以授权于一些普通用户去执行一些 root 执行的操作,而不需要知道 root 的密码.严谨些说,sudo 允许一个已授权用户以超级用户或者其它用户的角色 ...

  10. 关于C++中nothrow的某某某

    前言 在学习C++中new的种种用法时,在operator new的其中一个重载版本中看一个参数nothrow,想弄清楚到底是什么意思?nothrow顾名思义,就是不抛出的意思嘛!不抛出啥,在C++中 ...