#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
vll countScans(vll a,vll x,vll v){
ll n=a.size(),q=x.size();
if(n>8000)return a;
vll fans;
ll ans=0;
rep(i,n)rep(j,i)if(a[j]>a[i])ans++;
rep(k,q){
ll id=x[k];
for(int i=0;i<id;i++){
if(a[i]>a[id])ans--;
if(a[i]>v[k])ans++;
}
for(int i=id+1;i<n;i++){
if(a[i]<a[id])ans--;
if(a[i]<v[k])ans++;
}
fans.push_back(ans);
}
return fans;
}
int main(){
ll n,q;
cin>>n>>q;
vll a(n),x(q),v(q);
rep(i,n)cin>>a[i];
rep(i,q)cin>>x[i]>>v[i];
vll res=countScans(a,x,v);
for(auto t:res)cout<<t<<endl;
}
Compilation message
/tmp/ccFedXOL.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccitlDsQ.o:bubblesort2.cpp:(.text.startup+0x0): first defined here
/tmp/ccFedXOL.o: In function `main':
grader.cpp:(.text.startup+0x12b): undefined reference to `countScans(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status