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 & % ...
随机推荐
- 【BZOJ2626】JZPFAR kd-tree+堆
[BZOJ2626]JZPFAR Description 平面上有n个点.现在有m次询问,每次给定一个点(px, py)和一个整数k,输出n个点中离(px, py)的距离第k大的点的标号.如果有两个( ...
- slide.js
define(['jquery'], function (jquery) { function buildSmooth(config, motivateCallBack) { var timer = ...
- 【题解】CF989C A Mist of Florescence
[题解]CF989C A Mist of Florescence 题目大意: 让你构造一个\(n∗m\)矩阵,这个矩阵由4种字符填充构成,给定4个整数,即矩阵中每种字符构成的四联通块个数,\(n,m\ ...
- 题解 P1001 【A+B Problem】
#include<iostream> using namespace std; #define I int a,b; #define AK cin>>a>>b; # ...
- 微软Azure区块链开发工具包三大功能详解
2018年11月15日,微软宣布了Azure区块链开发工具包,它基于微软的无服务器技术构建,并且利用微软和第三方SaaS,完美集成了区块链.该工具包扩展了微软的区块链开发模板和Azure Blockc ...
- Java for LeetCode 131 Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- jQuery 网页禁止复制
<script type="text/javascript"> $(document).ready(function(){ $('#文本框id') ...
- pkg-config设置
pkg-config在一些源码管理中会被使用到. 介绍 上网查资料,知道了pkg-config这个东西,下面简单介绍一下. pkg-config提供了下面几个功能: 检查库的版本号.如果所需要的库的版 ...
- hadoop —— teragen & terasort
这两个类所在目录: hadoop-examples-0.20.2-cdh3u6.jar 中: 代码: TeraGen.java: /** * Licensed to the Apache Softwa ...
- 关于RabbitMQ简介
RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue )的开源实现.AMQP 的出现其实也是应了广大人民群众的需求,虽然在同步消息通讯的世界里有很多公开标准 ...