ChengZe @ 2019-03-02 11:31:40
如题十分玄学
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k;cin>>n>>k;
int a[n+1],q[n+1],head=0,tail=0;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<k;i++){
while(head<=tail&&a[q[tail]]>=a[i])--tail;
q[++tail]=i;
}
for(int i=k;i<=n;i++){
while(head<=tail&&a[q[tail]]>=a[i])--tail;
q[++tail]=i;
while(head<=tail&&q[head]<=i-k)++head;
cout<<a[q[head]]<<' ';
}
head=0;tail=0;
cout<<endl;
for(int i=1;i<k;i++){
while(head<=tail&&a[q[tail]]<=a[i])--tail;
q[++tail]=i;
}
for(int i=k;i<=n;i++){
while(head<=tail&&a[q[tail]]<=a[i])--tail;
q[++tail]=i;
while(head<=tail&&q[head]<=i-k)++head;
cout<<a[q[head]]<<' ';
}
cout<<endl;
return 0;
}
by Nobody_Zhang @ 2019-03-02 11:34:43
好像是没有初始化哇
by Nobody_Zhang @ 2019-03-02 11:34:54
我运行直接报错
by ChengZe @ 2019-03-02 11:45:54
@Microsoft_ZGB 感谢巨佬
by Jelly_Goat @ 2019-03-02 11:55:06
@ChengZe
这个题不用树状数组水过去的吗qwq
by Nobody_Zhang @ 2019-03-02 11:59:38
现在应该对了吧?
by Refined_heart @ 2019-03-02 12:12:27
我刚水过这道……
by ChengZe @ 2019-03-02 12:43:15
@Microsoft_ZGB 对了对了