凑_友希那 @ 2018-04-25 22:36:32
rt
#include <bits/stdc++.h>
using namespace std;
/**
* Code by mTx
* time: 2018/4/25
*/
#define f first
#define s second
#define m make_pair
deque<pair<int, int> > lty;
int val[1000010];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%d", &val[i]);
printf("0\n%d\n", val[1]);
lty.push_back(m(val[1], 1));
for(int i = 2; i < n; i++) {
if (lty.empty()) {
lty.push_back(m(val[i], i));
printf("%d\n", lty.front().f);
continue;
}
while (lty.size() && lty.back().f >= val[i]) {
lty.pop_back();
}
lty.push_back(m(val[i], i));
while (lty.front().s <= i - k)
lty.pop_front();
printf("%d\n", lty.front().f);
}
putchar('\n');
return 0;
}
RE两个点
by Siyuan @ 2018-04-25 22:41:54
目测是洛谷的TLE误判为RE了。。。
by 凑_友希那 @ 2018-04-25 22:42:38
可O2也是RE@siyuan
by SeKong @ 2018-04-26 07:54:38
while (lty.front().s <= i - k)
lty.pop_front();
你Que里可能就剩一个数了(前一行push进去的),然而你是while
,每次不check一下Que是否empty的吗?。。@ILLF_mTx
by 凑_友希那 @ 2018-04-26 12:36:19
while (lty.size() && lty.front().s <= i - k)
lty.pop_front();
可是还是RE了 @Skqliao
by SeKong @ 2018-04-26 14:33:35
by 凑_友希那 @ 2018-04-26 21:36:01
这...
by Juanzhang @ 2018-07-25 10:15:35
手写队列好啊