社区讨论
单调队列45分求救
P1638逛画展参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lo2xlyo3
- 此快照首次捕获于
- 2023/10/23 21:26 2 年前
- 此快照最后确认于
- 2023/10/23 21:26 2 年前
CPP
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10 , M = 1e6 + 10;
int n , m , a[N] , q[N] , c[M] , cnt;
int main()
{
cin >> n >> m;
for (int i = 1 ; i <= n ; ++i) cin >> a[i];
int hh = 0 , tt = -1;
for (int i = 1 ; i <= n ; ++i)
{
c[a[i]]++;
if(c[a[i]] == 1) cnt++;
while(hh <= tt && a[q[hh]] == a[i])
{
c[a[q[hh]]] --;
hh++;
}
q[++tt] = i;
if(cnt == m)
{
cout << q[hh] << ' ' << q[tt] << endl;
break;
}
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...