# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335781 | Mo_TOI_I_am_Garbage | Bubble Sort 2 (JOI18_bubblesort2) | C++14 | 0 ms | 0 KiB |
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> countScans(vector<int> A, vector<int> X, vector<int> V)
{
int ans = 0;
for(int i=1; i < (int)A.size(); i ++)
if(A[i] < A[i - 1]) ans ++;
vector<int> res;
for(int i=0; i < (int)X.size(); i ++)
{
if(X[i] > 0 && A[X[i]] < A[X[i] - 1]) ans --;
if(X[i] < (int)A.size() - 1 && A[X[i]] > A[X[i] + 1]) ans --;
A[X[i]] = V[i];
if(X[i] > 0 && A[X[i]] < A[X[i] - 1]) ans ++;
if(X[i] < (int)A.size() - 1 && A[X[i]] > A[X[i] + 1]) ans ++;
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]);
}