Language: C++

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 200000+10;

int cnt[MAXN<<1];
int cover[MAXN<<1];
int array[MAXN<<1];
int res=0;
int N,M;

void check(){
	cout<<"--------------------------------"<<endl;
	
	vector<int>  a(array+1,array+N+1);
	
	sort(a.begin(),a.end());
	
	cout<<"array:\t";
	for(int i=1;i<=N;i++){
		printf("%4d",array[i]);
	}
	cout<<endl;
	
	
	cout<<"sorted:\t";
	for(int i=1;i<=N;i++){
		printf("%4d",a[i-1]);
	}
	cout<<endl;
	
	
	cout<<"===="<<endl;
	
	cout<<"cover:\t";
	for(int i=1;i<=N;i++){
		printf("%3d:%d",i,cover[i]);
	}
	cout<<endl;
	
	cout<<"--------------------------------"<<endl;
}


int main(){
	res=0;
	scanf("%d%d",&N,&M);
	for(int i=1;i<=N;i++){
		scanf("%d",array+i);
		cnt[array[i]]++;
	}
	for(int i=N;i>0;i--){
		int j=cnt[i];
		while(j--){
			if(i>j)	cover[i-j]++;
		}
	}
	for(int i=1;i<=N;i++){
		res+=(cover[i]==0);
	}
	
	int X,Y;
	int num;
	//cout<<res<<endl;
	for(int i=0;i<M;i++){
		scanf("%d%d",&X,&Y);
		num=array[X];
		array[X]=Y;
		cnt[num]--;
		if(num-cnt[num]>0)	--cover[num-cnt[num]];
		if((num-cnt[num]>0)&&(0==cover[num-cnt[num]]))	res++;
		cnt[Y]++;
		if(Y-cnt[Y]+1>0)	++cover[Y-cnt[Y]+1];
		if((Y-cnt[Y]+1>0)&&(1==cover[Y-cnt[Y]+1]))	res--;
		printf("%d\n",res);
		//check();
	}
	return 0;
}

Compiler output:
a.cc: In function 'void check()':
a.cc:15:24: error: reference to 'array' is ambiguous
   15 |         vector<int>  a(array+1,array+N+1);
      |                        ^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:8:5: note:                 'int array [400020]'
    8 | int array[MAXN<<1];
      |     ^~~~~
a.cc:15:32: error: reference to 'array' is ambiguous
   15 |         vector<int>  a(array+1,array+N+1);
      |                                ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:8:5: note:                 'int array [400020]'
    8 | int array[MAXN<<1];
      |     ^~~~~
a.cc:21:30: error: reference to 'array' is ambiguous
   21 |                 printf("%4d",array[i]);
      |                              ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:8:5: note:                 'int array [400020]'
    8 | int array[MAXN<<1];
      |     ^~~~~
a.cc: In function 'int main()':
a.cc:49:28: error: reference to 'array' is ambiguous
   49 |                 scanf("%d",array+i);
      |                            ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:8:5: note:                 'int array [400020]'
    8 | int array[MAXN<<1];
      |     ^~~~~
a.cc:50:21: error: reference to 'array' is ambiguous
   50 |                 cnt[array[i]]++;
      |                     ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:8:5: note:                 'int array [400020]'
    8 | int array[MAXN<<1];
      |     ^~~~~
a.cc:67:21: error: reference to 'array' is ambiguous
   67 |                 num=array[X];
      |                     ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:8:5: note:                 'int array [400020]'
    8 | int array[MAXN<<1];
      |     ^~~~~
a.cc:68:17: error: reference to 'array' is ambiguous
   68 |                 array[X]=Y;
      |                 ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:8:5: note:                 'int array [400020]'
    8 | int array[MAXN<<1];
      |     ^~~~~