B. Uniqueness

给定一个序列,要求删除一段连续子段,满足删掉子段后每个元素唯一

求最小子段长度

枚举起点,二分子段长度

记得先sort 再unique

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define si signed
#define endl '\n'
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=1;i<=n;i++)scanf("%I64d",&A[i]);
#define P pair<int,int>
#define fi first
#define se second
#define ot(x) cout<<x<<'\n';
#define maxn 10000+5
int A[maxn];
int n,t,x,y,a,b;
vector<int> v;
bool check(int l,int mid)
{
v.clear();
for(int i=;i<=n;i++){
if(i<l)v.push_back(A[i]);
else if(i>mid)v.push_back(A[i]);
else i=mid;
}
sort(v.begin(),v.end());
int n=unique(v.begin(),v.end())-v.begin();
return n==v.size();
}
signed main()
{
sc(n);
for(int i=;i<=n;i++){
sc(A[i]);
v.push_back(A[i]);
}
sort(v.begin(),v.end());
int x=unique(v.begin(),v.end())-v.begin(); if(x==n){
cout<<<<'\n';
return ;
}
int len=n;
for(int i=;i<=n;i++){
int l=i,r=i+len-;
if(!check(i,r))continue;
while(l+<r){
int mid=(l+r)/;
if(check(i,mid)){
r=mid;
}else l=mid+;
}
if(check(i,l)){
len=min(l-i+,len);
}else if(check(i,r)){
len=min(r-i+,len);
}
}
cout<<len<<'\n';
}

B. Uniqueness的更多相关文章

  1. ruby on rails validates uniqueness

    最近在处理一个小功能,每个元素可以有多个图片,每个图片的name表示了它是背景图还是海报图, 需要对每个元素的图片name做一个唯一性验证,一个元素不能添加两个海报图, 需要使用的是validates ...

  2. PowerDesigner Constraint name uniqueness 问题处理(转载)

    使用PowerDesigner生成数据库脚本时报 Constraint name uniqueness 错误: 双击每行错误,发现外键引用的名字有重复的: 惯性去网上找解决办法,找到的主要是两个方法: ...

  3. Theorems for existence and uniqueness of variational problem

    Introduction Among simulation engineers, it is well accepted that the solution of a PDE can be envis ...

  4. PowerDesigner Constraint name uniqueness 错误

    使用PowerDesigner生成数据库脚本时报 Constraint name uniqueness 错误: 双击每行错误,发现外键引用的名字有重复的: 惯性去网上找解决办法,找到的主要是两个方法: ...

  5. PowerDesigner 同名问题解决 Entity Attribute name uniqueness

    选择"Tools -> Model Options"后 "Allow reuse"复选框,建议把这个钩也去掉 Tool->check model.. ...

  6. CodeForces 297C Splitting the Uniqueness (脑补构造题)

    题意 Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指 ...

  7. Codeforces 297C. Splitting the Uniqueness

    C. Splitting the Uniqueness time limit per test:1 second memory limit per test:256 megabytes input:s ...

  8. B. Uniqueness(尺取)

    B. Uniqueness time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. B. Uniqueness 删除最小区间内的元素使得剩余元素唯一

    B. Uniqueness time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. A9-USART2_RX_BUF 串口2收发异常

    a9_send_cmd(); //退出透传模式,和前一次发送时间超过 2 秒,输入+++,就可以退出透传模式 delay_ms(); delay_ms(); delay_ms(); a9_quit_t ...

  2. 【五一qbxt】test1

    (不知道为什么居然爆零了qwq) (全员爆零诶,最高分10分???还是rand出来的???) 我freopen写错了????自闭了 不行不行再写一遍freopen加深印象,不能再写错了 freopen ...

  3. 初识JavaScript(二)

    初识JavaScript(二) 我从上一篇<初识JavaScript(一)>知道和认识JavaScript的词法结构,也开始慢慢接触到了JavaScript的使用方法,是必须按照JavaS ...

  4. linux命令 集合

    ps:查看所有进程 // -e :显示所有进程:-f:代表全格式 ps -ef | grep python :查看后台运行的python程序,| 表示管道,grep表示筛选 & 符号:后台执行 ...

  5. PHP常用代码片段

    /** * 高效判断远程文件是否存在 * @param $file * @return bool 存在返回 true 不存在或者其他原因返回false */ function remoteFileEx ...

  6. 利用lambda和条件表达式构造匿名递归函数

    from operator import sub, mul def make_anonymous_factorial(): """Return the value of ...

  7. 通过yum安装maven

    安装maven wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/y ...

  8. 史上最全的大厂Mysql面试题在这里

    1.MySQL的复制原理以及流程 基本原理流程,3个线程以及之间的关联: 主:binlog线程——记录下所有改变了数据库数据的语句,放进master上的binlog中: 从:io线程——在使用star ...

  9. numpy.random.uniform(记住文档网址)

    http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.uniform.html#numpy.random.uniform h ...

  10. 剑指offer-6:数值整数次方

    一.题目描述 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 二.解题思想 分类讨论,充分考虑每种可能. exponent :0,1,& ...