社区讨论
求助,deque怎么看怎么对,下了样例也没看出错哪了,QWQ
P2032扫描参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @lo24hmh0
- 此快照首次捕获于
- 2023/10/23 07:51 2 年前
- 此快照最后确认于
- 2023/11/03 08:10 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
deque <int> a;
int main()
{
int n,k;
cin >> n >> k;
int cnt = 0;
for(int i = 1;i<=n;i++)
{
int x;
if(a.empty() == 0)
{
cnt++;
if(cnt == k)
{
cnt = 0;
a.pop_front();
}
cin >> x;
while(a.empty() == 0 && x > a.back())
{
if(a.size() == 1)
{
cnt = 0;
}
a.pop_back();
}
a.push_back(x);
if(i >= k)
{
cout << a.front() << '\n';
}
}
else
{
cin >> x;
a.push_back(x);
if(i >= k)
{
cout << a.front() << '\n';
}
}
}
return 0;
}
实在找不到问题
回复
共 2 条回复,欢迎继续交流。
正在加载回复...