Nephren_Sakura @ 2021-12-24 23:09:10
求助,复杂度正确O(n),1WA2TLE
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,head,tail;
struct node{
int tim,zhi;
}a[2000005];
signed main(){
cin>>n>>m;
head=1,tail=0;
for(int i=1; i<=n; i++){
int x;
cin>>x;
while(head<=tail&&a[tail].zhi>=x)
tail--;
while(head<=tail&&a[head].tim<i-m)
head++;
if(i==1)
cout<<"0\n";
else
cout<<a[head].zhi<<endl;
a[++tail].zhi=x;
a[tail].tim=i;
}
return 0;
}
by Nephren_Sakura @ 2021-12-24 23:13:41
不是1WA2TLE,只有2TLE
by OldVagrant @ 2021-12-24 23:23:22
@我是傻 你这是写假了,线段树都能过的你这单调数据结构还能TLE……
by Nephren_Sakura @ 2021-12-24 23:24:49
所以我才不知道我哪T了啊
by Nephren_Sakura @ 2021-12-24 23:25:12
本来应该是O(n)的
by Z_301 @ 2021-12-25 09:41:24
@我是傻 cout跑
by Damaxiaoshitou @ 2022-01-12 20:38:58
用printf输出就好了