Little Sub and Isomorphism Sequences ZOJ - 4089
思路:可以反正 最长重构序列必然符合 此模式 x + { } 与 { } + x
那么 题意转化为了 找两个距离最长的相同的数。eeee 先离散化
然后 开 2e5 个set 可插入可删除的维护 每个数的 出现的位置。
然后 。 如果有set .size > = 2 则可以更新。最值 。最值可用线段树or mulitset 维护
#include<bits/stdc++.h>
using namespace std;
#define maxn 223456
map<int,int>vis;
set<int>val[maxn];
set<int>::iterator it,ib;
int tree[maxn*4],n,ans;
int t,a[maxn],m,cnt,op,x,y;
void up(int root)
{
tree[root]=max(tree[root*2],tree[root*2+1]);
}
void updata(int root,int l,int r,int pos,int ad)
{
if(pos>r||pos<l)return ;
if(l==r)
{
tree[root]=ad;
return;
}
int mid=(l+r)/2;
updata(root*2,l,mid,pos,ad);
updata(root*2+1,mid+1,r,pos,ad);
up(root);
}
int main()
{
scanf("%d",&t);
while(t--)
{
vis.clear();
for(int i=0; i<=cnt; i++)
val[i].clear();
memset(tree,0,sizeof(tree));
cnt=0;
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
if(vis[a[i]]==0)
vis[a[i]]=++cnt;
val[vis[a[i]]].insert(i);
}
for(int i=1; i<=cnt; i++)
{
if(val[i].size()>=2)
{
ib=--(val[i].end());
it=val[i].begin();
int dd=*ib-*it;
updata(1,1,cnt,i,dd);
}
}
while(m--)
{
scanf("%d",&op);
if(op==2)
{
if(tree[1]<1)
printf("-1\n");
else
printf("%d\n",tree[1]);
}
else
{
scanf("%d%d",&x,&y);
val[vis[a[x]]].erase(x);
if(val[vis[a[x]]].size()<2)
updata(1,1,cnt,vis[a[x]],0);
else
{
ib=--(val[vis[a[x]]].end());
it=val[vis[a[x]]].begin();
int dd=*ib-*it;
updata(1,1,cnt,vis[a[x]],dd);
}
a[x]=y;
if(vis[y]==0)
vis[y]=++cnt;
val[vis[y]].insert(x);
if(val[vis[a[x]]].size()<2)
updata(1,1,cnt,vis[a[x]],0);
else
{
ib=--(val[vis[a[x]]].end());
it=val[vis[a[x]]].begin();
int dd=*ib-*it;
updata(1,1,cnt,vis[a[x]],dd);
}
}
}
}
return 0;
}
Little Sub and Isomorphism Sequences ZOJ - 4089的更多相关文章
- ZOJ Monthly, January 2019 Little Sub and Isomorphism Sequences 【离线离散化 + set + multiset】
传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5868 Little Sub and Isomorphism Seque ...
- ZOJ - 4089 :Little Sub and Isomorphism Sequences (同构 set)
Little Sub has a sequence . Now he has a problem for you. Two sequences of length and of length are ...
- ZOJ Monthly, January 2019 I Little Sub and Isomorphism Sequences(set 妙用) ZOJ4089
写这篇博客来证明自己的愚蠢 ...Orz 飞机 题意:给定你个数组,以及一些单点修改,以及询问,每次询问需要求得,最长的字串长度,它在其他位置存在同构 题解:经过一些奇思妙想后 ,你可以发现问题是传 ...
- ZOJ-4089-Little Sub and Isomorphism Sequences
给定你个数组,以及一些单点修改,以及询问,每次询问需要求得,最长的字串长度,它在其他位置存在同构. 当存在两个不相交的区间同构时,如: 1.2.…….n -1.n.n + 1.…….m.m + 1.m ...
- ZOJ Monthly, January 2019
A: Little Sub and Pascal's Triangle Solved. 题意: 求杨辉三角第n行奇数个数 思路: 薛聚聚说找规律,16说Lucas 答案是 $2^p \;\;p 为 n ...
- ZOJ Problem Set - 1338 Up and Down Sequences 解释 ac代码
这道题目我一开始一头雾水,怎么都数不对,参考了下网上的博文,才弄懂. 题意是这样的,如果是上升序列,上升序列的长度不是所有上升数字的,是这么规定的,如果它与前一个数字构成上升,那么这个数字算上长度.所 ...
- ZOJ 3861 - Valid Pattern Lock
3861 - Valid Pattern Lock Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ZOJ 3233 Lucky Number
Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...
随机推荐
- JMeter二次开发环境配置
本文主要介绍如何在Eclipse中配置JMeter开发环境. 一.下载JMeter源码 1.在JMeter官网下载二进制包和源码包: 解压备用: 二进制解压后文件夹名称为“jmeter_release ...
- xin
测试文件 行内公式 y = x 独立公式 limx → 0x = 0
- java 中final关键字
1.final变量,一旦该变量被设定,就不可以再改变该变量的值. final关键字定义的变量必须声明时赋值.一旦一个对象引用被修饰为final后,它只能恒定指向一个对象,一个既是static和fina ...
- JAVA进阶22
1.接口默认方法的使用 ①接口的默认方法可以通过接口实现类对象直接调用. ②接口的默认方法也可以被接口实现类进行覆盖重写 package cn.intcast.demo17; public inter ...
- idea编译错误提示编译版本不对,需要注意的配置
- easyui datagrid使用按钮
$('#datagrid').datagrid({ border:false, fitColumns:true, singleSelect: true, url:url, columns:[[ {fi ...
- 论文学习笔记--无缺陷样本产品表面缺陷检测 A Surface Defect Detection Method Based on Positive Samples
文章下载地址:A Surface Defect Detection Method Based on Positive Samples 第一部分 论文中文翻译 摘要:基于机器视觉的表面缺陷检测和分类可 ...
- Windows 10无法连接远程桌面解决办法(这可能是由于CredSSP加密Oracle修正)
问题描述: 使用windows10 连接远程桌面时出现如下错误: 出现身份验证错误. 要求的函数不受支持. 这可能是由于CredSSP加密Oracle修正. 若要了解详细信息,请访问https://g ...
- 记录一个EF连接查询的异常:the entity or complex type 'x' cannot be constructed in a linq to entities query
问题解决连接:https://stackoverflow.com/questions/5325797/the-entity-cannot-be-constructed-in-a-linq-to-ent ...
- Blocking Cross Origin API request for /api/contents Creating Notebook Failed An error occurred while creating a new notebook.
anacoda安装的jupyter,使用nginx进行了转发,远程访问可以进去,但是创建文件和创建目录都会报错 浏览器页面报错: 第一次使用jupyter创建python时错误:Creating No ...