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