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. Nmap Windows 版本时区显示乱码

    Nmap 版本 $ nmap --version Nmap version 7.80 ( https://nmap.org ) Platform: i686-pc-windows-windows Co ...

  2. P1115 最大子段和(简单DP)

    题目描述 给出一段序列,选出其中连续且非空的一段使得这段和最大. 输入格式 第一行是一个正整数NN,表示了序列的长度. 第二行包含NN个绝对值不大于1000010000的整数A_iAi​,描述了这段序 ...

  3. HNUST-1047 二叉树的表示

    1047: 二叉树的表示 时间限制: 1 Sec  内存限制: 128 MB提交: 4  解决: 4[提交][状态][讨论版] 题目描述 ​DJ非常痴迷于数据结构,二叉树是他最喜欢的结构模型.这种每个 ...

  4. __next__()

    def f1(n): m=n while True: m+=1 yield m a=f1(5) print(a.__next__()) 结果:6

  5. vsftpd一些常用配置

    常用的全局配置 --设置监听的IP地址 listen_asspress=192.168.4.1 --设置监听FTP服务的端口号 listen_port=21 --是否允许下载文件 download_e ...

  6. wex5 sqllite本地数据库的运用

    http://doc.wex5.com/?p=3774 需要引入包require("cordova!com.brodysoft.sqlitePlugin"); //本地数据库操作 ...

  7. 提取数据xpath,re,css

    XPATH (1)/ 逐层提取 (2)text() 提取标签下面的文本 (3)//标签名 提取所有的标签 (4)//标签名[num>=1] 提取相同标签名的兄弟节点. <tr class= ...

  8. 008-zabbix监控nginx

    (1)agent端配置 1)nginx编译安装需要加上该选项--with-http_stub_status_module 2)修改nginx配置文件 #vim /usr/local/nginx/con ...

  9. PAT Advanced 1041 Be Unique (20 分)

    Being unique is so important to people on Mars that even their lottery is designed in a unique way. ...

  10. Ubuntu16.04下安装httpd+svn+viewVC

    一.安装httpd 1.下载httpd 网址:http://httpd.apache.org/download.cgi#apache24 下载这一条---Source: httpd-2.4.39.ta ...