This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> pos;
int bit[50050];
void add(int x, int d)
{
	while(x)
	{
		bit[x] += d;
		x -= x & -x;
	}
}
int search(int x)
{
	int res = 0;
	while(x <= pos.size())
	{
		res += bit[x];
		x += x & -x;
	}
	return res;
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V)
{
	for(int x : A) pos.push_back(x);
	for(int x : V) pos.push_back(x);
	pos.push_back(-1e9);
	sort(pos.begin(), pos.end());
	pos.resize(unique(pos.begin(), pos.end()) - pos.begin());
	for(int i=0; i < A.size(); i ++)
	{
		int ind = lower_bound(pos.begin(), pos.end(), A[i]) - pos.begin();
		A[i] = ind;
	}
	for(int i=0; i < V.size(); i ++)
	{
		int ind = lower_bound(pos.begin(), pos.end(), V[i]) - pos.begin();
		V[i] = ind;
	}
	vector<int> res;
	for(int i=0; i < (int)X.size(); i ++)
	{
		memset(bit, 0, sizeof(bit));
		int ans = 0;
		A[X[i]] = V[i];
		for(int j=0; j < (int)A.size(); j ++)
		{
			ans = max(ans, search(A[j] + 1));
			add(A[j], 1);
		}
		res.push_back(ans);
	}
	return res;
}
// int readInt(){
// 	int i;
// 	if(scanf("%d",&i)!=1){
// 		fprintf(stderr,"Error while reading input\n");
// 		exit(1);
// 	}
// 	return i;
// }
// int main(){
// 	int N,Q;
// 	N=readInt();
// 	Q=readInt();
	
// 	std::vector<int> A(N);
// 	for(int i=0;i<N;i++)
// 		A[i]=readInt();
	
// 	std::vector<int> X(Q),V(Q);
// 	for(int j=0;j<Q;j++){
// 		X[j]=readInt();
// 		V[j]=readInt();
// 	}
// 	std::vector<int> res=countScans(A,X,V);
	
// 	for(int j=0;j<int(res.size());j++)
// 		printf("%d\n",res[j]);
// }
Compilation message (stderr)
bubblesort2.cpp: In function 'int search(int)':
bubblesort2.cpp:17:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  while(x <= pos.size())
      |        ~~^~~~~~~~~~~~~
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i=0; i < A.size(); i ++)
      |               ~~^~~~~~~~~~
bubblesort2.cpp:36:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i=0; i < V.size(); i ++)
      |               ~~^~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |