为什么会RE?
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
const int N=200005;
int p[N],b[N],ans[N];
vector<int> a[N];
set<int> s;
inline int read(){
int w=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
w=(w<<1)+(w<<3)+(ch-48);
ch=getchar();
}
return w*f;
}
inline int Pow(int a,int b){
int ans=1;
for(;b;b>>=1){
if(b&1) ans=(ans*a)%MOD;
a=(a*a)%MOD;
}
return ans;
}
signed main(){
int n,k,m=0;
n=read();k=read();
for(int i=1;i<=n;i++) p[i]=read();
for(int i=1;i<=n;i++){
auto x=s.lower_bound(p[i]);
if(x==s.end()){
a[++m].push_back(p[i]);
s.insert(p[i]);
b[p[i]]=m;
}
else{
a[b[(*x)]].push_back(p[i]);
s.erase(x);
s.insert(p[i]);
b[p[i]]=b[(*x)]; //Here gonna be RE.why?
}
if((int)(a[b[p[i]]].size())>=k){
s.erase(p[i]);
for(auto u : a[b[p[i]]]) ans[u]=i;
}
}
for(int i=1;i<=n;i++){
if(ans[i]==0) printf("-1\n");
else printf("%lld\n",ans[i]);
}
return 0;
}