# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1032018 | boyliguanhan | Bubble Sort 2 (JOI18_bubblesort2) | C++17 | 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<bits/stdc++.h>
using namespace std;
#define N 1<<20
pair<int,int>val[N];
int lz[2*N],vl[2*N],Cc;
int read(){
int x=0;
char c=getchar();
while(c<48||c>57)
c=getchar();
while(c>47&&c<58)
x=x*10+c-48,c=getchar();
return x;
}
void pd(int n){
if(n<N)lz[2*n]+=lz[n],
lz[2*n+1]+=lz[n];
vl[n]+=lz[n]; lz[n]=0;
}
void upd(int i,int l,int r,int ll,int rr,int v){
pd(i);
if(ll>r||l>rr)return;
if(ll<=l&&r<=rr)
return lz[i]+=v,pd(i);
upd(i*2,l,l+r>>1,ll,rr,v);
upd(i*2+1,l+r+2>>1,r,ll,rr,v);
vl[i]=max(vl[i*2],vl[i*2+1]);
}
signed main(){
int n(read()),q(read());
vector<long long>A(n),X(q),V(q);
map<long long,int>mp;
for(auto&i:A)i=read();
for(int i=0;i<q;i++)
X[i]=read(),V[i]=read(),
mp[V[i]*n+X[i]];
for(int i=0;i<n;i++)
mp[i+n*A[i]];
for(auto&i:mp)
i.second=++Cc;
int sz=mp.size();
for(int i=0;i<q;i++)
V[i]=mp[V[i]*n+X[i]];
for(int i=0;i<n;i++) {
A[i]=mp[i+n*A[i]];
upd(1,1,sz,A[i]+1,sz,-1);
upd(1,1,sz,A[i],A[i],i);
}
for(int i=0;i<q;i++){
int k=X[i];
int v=V[i];
upd(1,1,sz,A[k]+1,sz,1),
upd(1,1,sz,A[k],A[k],-k);
A[k]=v;
upd(1,1,sz,A[k]+1,sz,-1),
upd(1,1,sz,A[k],A[k],k);
cout<<vl[1]<<'\n';
}
}