123
heyechen
·
·
个人记录
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
int a[200001];
struct node{
int mx;
node *l,*r;
};
node *build()
{
node *head=new node;
head->mx=0;
head->l=head->r=NULL;
return head;
}
void pushup(node *head)
{
head->mx=max(head->l->mx,head->r->mx);
}
void edit(node *head,int l,int r,int x,int k)
{
if(l==r)
{
head->mx+=k;
return;
}
if(head->l==NULL)
head->l=build();
if(head->r==NULL)
head->r=build();
if(x<=(l+r)/2)
edit(head->l,l,(l+r)/2,x,k);
else
edit(head->r,(l+r)/2+1,r,x,k);
pushup(head);
}
int main()
{
freopen("reorder.in","r",stdin);
freopen("reorder.out","w",stdout);
int n,q,p,x;
node *head;
cin>>n>>q;
head=build();
for(int i=1;i<=n;i++)
{
cin>>a[i];
edit(head,1,inf,a[i],1);
}
cout<<n-head->mx<<endl;
for(int i=1;i<=q;i++)
{
cin>>p>>x;
edit(head,1,inf,a[p],-1);
a[p]=x;
edit(head,1,inf,x,1);
cout<<n-head->mx<<endl;
}
return 0;
}