当前位置: 首页 > news >正文

P1638 逛画展

点击查看代码
#include<bits/stdc++.h>using namespace std;const int N=1000010,M=2010;
int n,m;
int ans,cnt,ansl,ansr;
int a[N],b[M];inline void ins(int x)
{if(b[x]==0) cnt++;b[x]++;
}inline void del(int x)
{if(b[x]==1) cnt--;b[x]--;
}int main()
{cin>>n>>m;ans=n;ansl=1,ansr=n;for(int i=1;i<=n;i++) cin>>a[i];for(int r=1,l=1;r<=n;r++){ins(a[r]);while(l<=r){del(a[l]);if(cnt==m) l++;else{ins(a[l]);break;}}if(cnt==m&&r-l+1<ans){ans=r-l+1;ansl=l,ansr=r;}}//要记得初始化ans1和ansr,因为判断条件是r-l+1<ans,最后相等是不会更新的cout<<ansl<<" "<<ansr;return 0;}
滑动窗口双指针,不算难,算是扩展了一种处理方式
http://www.zskr.cn/news/62061.html

相关文章:

  • newDay23
  • 洛谷 P10378:[GESP202403 七级] 交流问题 ← 二分图 + 染色法
  • 每日反思(2025年11月26)
  • Markdown常用语法总结
  • 汉明距离相关应用
  • JUC
  • 基因组共线性分析
  • Ai元人文:引言——悟空与悬鉴
  • Bazaar - 现代化的 GNOME 应用商店
  • 黑马程序员SpringCloud微服务开发与实战-微服务05
  • map用法
  • sprintf用法
  • 订单多到做不完?四步把交期、缺料、进度和插单都解决了
  • 第37天(中等题 数据结构)
  • 2025 KEYDIY KD-MP: Add Keys for MLB MQB – Key Identification, Data, Calculation
  • 把 CLI 搬上 Web:在内网打造“可二开”的 AI IDE,为什么这条路更现实? - 指南
  • freedom of speech
  • 七、设备模型
  • 鼎鉴时代锋芒 智启品牌新章 ——2025品牌智鉴榜荣耀登临
  • Day25综合案例一--CSS精灵--京东服务
  • agentic terminal coding
  • 2025年11月26日
  • Day3 Scrum冲刺博客
  • 贪心专题笔记(从b站左程云老师那上完后的笔记)
  • 做题警醒
  • 微软发布 Godot C# 游戏开发教程:godot-csharp-essentials
  • [KaibaMath]1028 关于[log(m, a)]+1=⌈log(m+1, a)⌉的证明
  • 软件工程学习日志2025.11.26
  • [KaibaMath]1027 关于mn ⇔ m≥n+1(m,n均为整数)的证明
  • Webpack高级之常用配置项