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 considered isomorphic when they meet all the following two conditions:
- ;
- Define as the number of times integer occur in sequence . For each integer in , always holds.
Now we have operations for . and there are two kinds of operations:
- 1 x y: Change to (, );
- 2: Query for the greatest () that there exist two integers and () and is isomorphic with . Specially, if there is no such , please output "-1" (without quotes) instead.
There are multiple test cases. The first line of the input contains an integer (), indicating the number of test cases. For each test case:
The first line ontains two integers .
The second line contains integers ().
In the following lines, each line contains one operation. The format is described above.
Output
For each operation 2, output one line containing the answer.
Sample Input
1
3 5
1 2 3
2
1 3 2
2
1 1 2
2
Sample Output
-1
1
2
题意:给定你个数组,以及一些单点修改,以及询问,每次询问需要求得,最长的字串长度,它在其他位置存在同构。
思路:最长同构子串对总是会重叠的,然后两个子串不重叠的部分必须是同构。 那么一定有,最优之一就是“x+公共”与“公共+x”这两个同构最长。
这个不难反证。 那么实现就是每种数离散后建立set,然后保存每个set的最远距离即可。
#include<bits/stdc++.h>
#define rep(i,w,v) for(int i=w;i<=v;i++)
using namespace std;
const int maxn=;
int a[maxn],b[maxn],c[maxn],x[maxn],y[maxn],tot;
set<int>s[maxn];
multiset<int>S;
multiset<int>::iterator it;
int main()
{
int T,N,M,ans;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&M); tot=;
rep(i,,N) scanf("%d",&a[i]),b[++tot]=a[i];
rep(i,,M){
scanf("%d",&c[i]);
if(c[i]==) {
scanf("%d%d",&x[i],&y[i]);
b[++tot]=y[i];
}
}
sort(b+,b+tot+);
tot=unique(b+,b+tot+)-(b+);
S.clear(); rep(i,,tot) s[i].clear();
rep(i,,N) {
a[i]=lower_bound(b+,b+tot+,a[i])-b;
s[a[i]].insert(i);
}
rep(i,,tot) if(!s[i].empty())
S.insert(*(--s[i].end())-*s[i].begin());
rep(i,,M){
if(c[i]==){
ans=-;
if(!S.empty()) ans=*(--S.end());
if(ans==) ans=-;
printf("%d\n",ans);
}
else {
it=S.find(*(--s[a[x[i]]].end())-*s[a[x[i]]].begin());
s[a[x[i]]].erase(x[i]);
S.erase(it);
if(!s[a[x[i]]].empty()) S.insert(*(--s[a[x[i]]].end())-*s[a[x[i]]].begin()); y[i]=lower_bound(b+,b+tot+,y[i])-b; a[x[i]]=y[i];
if(!s[y[i]].empty()) S.erase(S.find(*(--s[y[i]].end())-*s[y[i]].begin()));
s[y[i]].insert(x[i]);
S.insert(*(--s[y[i]].end())-*s[y[i]].begin());
}
}
}
return ;
}
ZOJ - 4089 :Little Sub and Isomorphism Sequences (同构 set)的更多相关文章
- Little Sub and Isomorphism Sequences ZOJ - 4089
ZOJ - 4089 思路:可以反正 最长重构序列必然符合 此模式 x + { } 与 { } + x 那么 题意转化为了 找两个距离最长的相同的数.eeee 先离散化 然后 ...
- 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 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 ...
- Isomorphism 同构
小结: 1.两个有限维度的向量空间,在同一数域下,是同构的 等价于 它们维数相等. Isomorphism 同构 0.1.8 Isomorphism. If U and V are vector sp ...
- 【BZOJ4474】isomorphism(树的同构,哈希)
题意:一个无向树的度数为 2的结点称为假结点,其它结点称为真结点.一个无向树的简化树其结点由原树的全体真结点组成,两个真结点之间有边当且仅当它们在原树中有边,或者在原树中有一条联结这两个结点的路,其中 ...
- ZOJ Problem Set - 1338 Up and Down Sequences 解释 ac代码
这道题目我一开始一头雾水,怎么都数不对,参考了下网上的博文,才弄懂. 题意是这样的,如果是上升序列,上升序列的长度不是所有上升数字的,是这么规定的,如果它与前一个数字构成上升,那么这个数字算上长度.所 ...
- Python数据类型之“序列概述与基本序列类型(Basic Sequences)”
序列是指有序的队列,重点在"有序". 一.Python中序列的分类 Python中的序列主要以下几种类型: 3种基本序列类型(Basic Sequence Types):list. ...
随机推荐
- linux定时删除文件脚本
#! /bin/sh # 配置项DEBUG=truefolderDir=/var/www/html/hlsrecord/EXPIRE_DAY=1 # 过期时间和时间戳deadTime=`date -d ...
- linux用户管理 查看用户信息
LINUX系统中用户登录查看命令 W命令 [root@ssgao1987 ~]# w 04:57:01 up 11:50, 2 users, load average: 0.00, 0.00, 0 ...
- Spring MVC之DispatcherServlet初始化详解
Spring作为一个优秀的web框架,其运行是基于Tomcat的.在我们前面的讲解中,Spring的驱动都是使用的ClassPathXmlApplicationContext,并且都是直接在main方 ...
- 为什么IT运维工程师要学习Linux系统
不论你是否知道,其实你每天都在使用Linux.每次你访问微博.百度甚至是一些小电影网站,你的客户端(浏览器)都在与运行在Linux系统上的服务端程序进行通讯,大多数的电子设备,例如数位录像机.飞机.自 ...
- Java单例模式《一》饿汉式
package com.study.mode; /** * 单例模式:饿汉式. 线程安全. * @ClassName: SingleBean * @author BlueLake * @date 20 ...
- 【转载】Qt中图像的显示与基本操作
Qt可显示基本的图像类型,利用QImage.QPxmap类可以实现图像的显示,并且利用类中的方法可以实现图像的基本操作(缩放.旋转). 参考:Qt中图像的显示与基本操作 - ykm0722的专栏 - ...
- ActiveMQ的安装与配置
ActiveMQ的安装与配置详情 (1)ActiveMQ的简介 MQ: (message queue) ,消息队列,也就是用来处理消息的,(处理JMS的).主要用于大型企业内部或与企业之间的传递数据信 ...
- JNA调用DLL(入门):让你一眼就学会
DLL(Dynamic Link Library)文件,是基于C语言的动态链接库文件,就是一些封装好的方法,打成dll格式包,供别人调用 JNA是一种能够使Java语言使调用DLL的一种技术, 首先, ...
- Thêm Một Lần Đau--错错错--IPA--越南语
越南国际天团HKT的名曲.
- vs2013 跳过IE10
安装 VS2013要安装IE10,却安装不了..以下为跳过IE10,直接安装VS2013方法 复制以下代码,保存为bat文件 @ECHO OFF :IE10HACK REG ADD "HKL ...