FZU 2059 MM (并查集+排序插入)
Accept: 109 Submit: 484
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem 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
Sample Input
1 2 3 2 1
1 2
1 3
2 3 1
1 2
1 3
Sample Output
1
1
0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1e9;
const double eps = 1e-;
const int N = ;
int cas = ; struct _node{
int pos,val,ans;
friend bool operator < (const _node &a, const _node &b)
{
return a.val < b.val;
}
};
int n,m;
int fa[N],sum[N],b[N],mxval;
_node a[N]; int find(int x)
{
return fa[x]==x?x:fa[x]=find(fa[x]);
} void un(int u,int v)
{
u=find(u), v=find(v);
fa[u]=v;
sum[v]+=sum[u];
} void pre()
{
memset(sum,,sizeof(sum));
mxval = -INF-;
for(int i=;i<n;i++) fa[i]=i;
for(int i=;i<n;i++)
{
a[i].val=b[i],a[i].pos=i;
if(a[i].val > mxval) mxval = a[i].val;
}
sort(a,a+n);
int mx = ;
for(int i=n-;i>=;i--)
{
sum[a[i].pos]=;
if(sum[a[i].pos-]) un(a[i].pos-,a[i].pos);
if(sum[a[i].pos+]) un(a[i].pos+,a[i].pos);
if(mx < sum[find(a[i].pos)]) mx = sum[fa[a[i].pos]];
a[i].ans = mx;
}
} int solve(int x)
{
_node t;
t.val=x;
int id = lower_bound(a,a+n,t) - a;
return a[id].ans;
} void run()
{
for(int i=;i<n;i++)
scanf("%d",b+i);
pre();
int x,y,op;
while(m--)
{
scanf("%d",&op);
if(op==)
{
scanf("%d",&x);
if(x>mxval) puts("");
else printf("%d\n",solve(x));
}
else
{
scanf("%d%d",&y,&x);
b[y-]=x;
pre();
}
}
} int main()
{
#ifdef LOCAL
freopen("case.txt","r",stdin);
#endif
while(scanf("%d%d",&n,&m)!=EOF)
run();
return ;
}
FZU 2059 MM (并查集+排序插入)的更多相关文章
- SPOJ:Lexicographically Smallest(并查集&排序)
Taplu and Abhishar loved playing scrabble. One day they thought of inventing a new game using alphab ...
- FZU 2059 MM
Description There is a array contain N(1<N<=100000) numbers. Now give you M(1<M<10000) q ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- HDU——1272小希的迷宫(并查集+拓扑排序)
小希的迷宫 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- FZU 2112 并查集、欧拉通路
原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个连通分量,我们可以用一个并查集来维护,假设 ...
- ACM: FZU 2112 Tickets - 欧拉回路 - 并查集
FZU 2112 Tickets Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u P ...
- 拓扑排序 - 并查集 - Rank of Tetris
Description 自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球 ...
- hdu 1811Rank of Tetris (并查集 + 拓扑排序)
/* 题意:这些信息可能有三种情况,分别是"A > B","A = B","A < B",分别表示A的Rating高于B,等于B ...
- ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线
hdu 1811 Rank of Tetris Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
随机推荐
- 九度OJ 1179:阶乘 (循环)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5149 解决:1523 题目描述: 输入n, 求y1=1!+3!+...m!(m是小于等于n的最大奇数) y2=2!+4!+...p!(p是 ...
- UVA - 10305 【拓扑排序】
题意 给出一些任务的优先级别 将这些任务进行的时间 进行先后排序 思路 拓扑排序 将所以有先后关系的任务都连一条边 然后每次 输出 度为0 的任务 每次把 以这个任务为弧的边 都取消 相对应任务的度也 ...
- Android中m、mm、mmm、mma、mmma的区别
m:编译整个安卓系统 makes from the top of the tree mm:编译当前目录下的模块,当前目录下需要有Android.mk这个makefile文件,否则就往上找最近的Andr ...
- Spring Boot2.0之整合事物管理
首先Spring 事务分类 1.声明事务 原理:基于编程事务的 2.编程事务 指定范围 扫包去解决 3.事务原理:AOP技术 通过环绕通知进行了拦截 使用Spring 事务注意事项: 不要tr ...
- c语言学习的第12天
#include <stdio.h> int main(void) { int *p; int i=5; char ch='A'; p=&i; *p=99; printf(&quo ...
- redis持久化的方式RDB 和 AOF
redis持久化的方式RDB 和 AOF 一.对Redis持久化的探讨与理解 目前Redis持久化的方式有两种: RDB 和 AOF 首先,我们应该明确持久化的数据有什么用,答案是用于重启后的数据恢复 ...
- Linux_学习_01_常用命令大全
一.文件目录 1.列出目录 ls -a #显示隐藏文件 -l #显示文件和目录的详细资料 -h -lrt tree #显示文件和目录由根目录开始的树形结构 lstree #显示文件和目录由根目录开始的 ...
- struts2 validate手动验证
我们前面学习struts2知道,struts2通过拦截器实现了一些验证操作. 比如,如果是不能转换的类型在action中接受的话会跳转到错误页面,错误信息中会包含对应的错误信息,例如: 首先我们了解一 ...
- L84
Hospital Noise May Disrupt Patient Improvement Many who need restorative rest the most might not be ...
- Spring笔记03(Spring创建对象的三种方式)
1.创建对象的三种方式和bean的生命周期的验证: Animal接口代码: package cn.pb.dao; /** * 动物接口 */ public interface Animal { //吃 ...