CF1223D

不需要动的一定值域连续

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#define LL long long
using namespace std; const int M = 310001;
int n,m,k,a[M],T,L[M],R[M],l,res,s; int main()
{
scanf("%d",&T);
for(;T;T--)
{
scanf("%d",&n); m=0; res=0x3f3f3f3f; s=0;
for(int i=1;i<=n;i++) L[i]=0x3f3f3f3f, R[i]=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(!R[a[i]]) m++;
L[a[i]]=min(L[a[i]],i);
R[a[i]]=max(R[a[i]],i);
}
int r=0, x=0, y=1; for(int x=1;x<=n;x++) if(R[x])
{
if(s) s--;
if(!s) r=R[x], s++;
y=max(y,x);
while((!R[y+1] || L[y+1]>r) &&y<n)
{
y++;
if(!R[y]) continue;
r=R[y]; s++;
}
res=min(res,m-s);
}
printf("%d\n",res);
}
}

最新文章

  1. 如何快速优化手游性能问题?从UGUI优化说起
  2. HttpClient通过Post上传多个文件
  3. ARM学习篇一 点亮LED
  4. java框架
  5. php扩展的基本安装
  6. Java笔记(十七)&hellip;&hellip;异常
  7. 【UVA】10012 - How Big Is It?(暴力)
  8. linux Nagios监控
  9. 同一张表省市县sql查询
  10. C语言有哪些鲜为人知的特性?
  11. 关于toncat的Invalid character found in the request target.The valid characters are defined in RFC 7230 and RFC3986
  12. Nginx http2.0
  13. Spring MVC基础知识整理➣Spring+SpringMVC+Hibernate整合操作数据库
  14. python接口自动化测试(一)-request模块
  15. 20155207 EXP8 Web基础
  16. CefSharp.OffScreen.Example
  17. mac设置文件权限问题
  18. MapReduce分组
  19. JVM调优(2)
  20. SQL 2008 R2数据库变为REPLICATION,日志不断增长并且不能截断和收缩的解决方式

热门文章

  1. HDU 4886 TIANKENG’s restaurant(Ⅱ) ( 暴力+hash )
  2. 想要成长,总得立个flag
  3. ionic3中使用docker 完成build代码,更新过程记录。
  4. fiddler 4 抓取 https 设置
  5. 24.循环栅栏 CyclicBarrier
  6. 关于Python实现Interface base64加解密方法
  7. vue-cli脚手架快速搭建项目
  8. c++11 中的注意事项
  9. Python深度学习
  10. linux基础知识-目录结构