Kizuna_AI @ 2019-07-25 08:37:48
#include<bits/stdc++.h>
#define N 1000010
using namespace std;
multiset<int> ms;
multiset<int>::iterator it;
multiset<int>::reverse_iterator rit;
int n,k;
int f[N];
int ansmax[N],ansmin[N];
inline int read() {
int s=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9') {
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
s=s*10+ch-'0';
ch=getchar();
}
return s*f;
}
inline void write(int x) {
if(x<0) {
putchar('-');
x=-x;
}
if(x>9) write(x/10);
putchar(x%10+'0');
}
int main() {
n=read();k=read();
for(int i=1;i<=n;i++)
f[i]=read();
for(int i=1;i<=k;i++)
ms.insert(f[i]);
for(int i=k+1;i<=n;i++) {
it=ms.begin();rit=ms.rbegin();
ansmax[i]=*rit;ansmin[i]=*it;
it=ms.find(f[i-k]);
ms.erase(it);
ms.insert(f[i]);
}
it=ms.begin();rit=ms.rbegin();
ansmax[n+1]=*rit;ansmin[n+1]=*it;
for(int i=k+1;i<=n+1;i++) {
write(ansmin[i]);
putchar(' ');
}
putchar('\n');
for(int i=k+1;i<=n+1;i++) {
write(ansmax[i]);
putchar(' ');
}
return 0;
}
开了O2和快读仍过不了评测记录
by Erusel @ 2019-07-25 08:42:56
可以写线段树啊qwq
by Kizuna_AI @ 2019-07-25 08:47:24
@Robinzh %%%,感觉写单调队列应该能过
by Kizuna_AI @ 2019-07-25 08:59:13
单调队列过了