正式AFO @ 2018-09-16 11:31:45
#include<iostream>
using namespace std;
struct min_sdqueue{
int tail, front;
int z[2000001],p[2000001];
min_sdqueue(){
tail = 0, front = 1;
}
void push(int x, int y){
while(tail >= front && x < z[tail])
tail--;
tail++;
z[tail] = x;
p[tail] = y;
}
int top(){
return z[front];
}
int read(){
return p[front];
}
void move(){
front++;
}
};
int n, m;
int a[2000001];
int ai;
int main(){
min_sdqueue que;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> ai;
if(i == 1){
cout << 0 << endl;
que.push(ai, i);
continue;
}
while(que.read() <= i - m - 1)
que.move();
cout << que.top() << endl;
que.push(ai, i);
}
return 0;
}
by Resonaa @ 2018-09-16 11:38:00
cin
-> scanf
cout
-> printf
by Resonaa @ 2018-09-16 11:39:02
@5743377_2002
endl
-> '\n'
by 正式AFO @ 2018-09-16 11:40:42
why,
by 正式AFO @ 2018-09-16 11:41:10
能少几毫秒?
by djh123 @ 2018-09-20 21:45:39
scanf, printf 比 cin, cout 大约能快七八倍。。
大数据读入还是别用cin, cout了吧
by djh123 @ 2018-09-20 21:45:52
@5743377_2002
by 正式AFO @ 2018-09-20 21:50:05
谢谢。那就能A了