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 ...
随机推荐
- LeetCode-11. 盛最多水的容器
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...
- DotNet进阶系列
一. 回顾历史 回顾个人发展历程,自2012年初次接触开发至今(2018年)已经有六个年头,这期间陆陆续续学习并掌握了不少技术,C#语言.ORM框架.多线程技术.设计模式.前端技术.MVC.MVVM框 ...
- iptables 防火墙日常
. 检查机目标机器 httpd 服务/etc/init.d/httpd status ========================================================= ...
- Windows Hook技术
0x01 简介 有人称它为“钩子”,有人称它为“挂钩”技术.谈到钩子,很容易让人联想到在钓东西,比如鱼钩就用于钓鱼.编程技术的钩子也是在等待捕获系统中的某个消息或者动作.钩子的应用范围非常广泛,比如输 ...
- go之路
目录 go初识[第一篇]初识 go初识[第二篇]包.变量.函数
- C#调用Bartender打印
BarTender是一款优秀的条形码打印软件,可以支持很多种类型的条形码设计和打印,具体大家可参考他的官网(http://www.seagullscientific.com/aspx/products ...
- springboot中使用kindeditor富文本编辑器实现博客功能
kindeditor在之前已经用过,现在在springboot项目中使用.并且也在里面使用了图片上传以及回显等功能. 其实主要的功能是图片的处理:kindeditor对输入的内容会作为html标签处理 ...
- C语言中 if 和 else if 的区别
先看代码:我们本意是对i不同的值有不同的判断. #include<stdio.h> int main(void) { ; ) { i++; printf("%d\n", ...
- [Kubernetes]PV,PVC,StorageClass之间的关系详解
在Kubernetes中,容器化一个应用比较麻烦的地方莫过于对其"状态"的管理,而最常见的"状态",莫过于存储状态. 在[Kubernetes]深入理解Stat ...
- python input()键盘输入8583报文带有\x单反斜杠自动转义问题解决办法
用input()输入的字符串是8385报文比如:\x30\x30\x30\x30...,但是输入后,代码把8583报文字符串中多加了一个\,类似\\x30. 但是我把input()代码注释掉,把858 ...