# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
469020 | stefantaga | 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"
#define INF 10000000000000000
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
long long nr,n,i,v[500005];
map <pair <long long ,long long > ,long long > m;
long long arb[2000005],lazy[2000005];
void propaga(long long st,long long dr,long long nod)
{
if (st==dr)
{
return;
}
if (lazy[nod]==0)
{
return;
}
lazy[2*nod]+=lazy[nod];
lazy[2*nod+1]+=lazy[nod];
arb[2*nod]+=lazy[nod];
arb[2*nod+1]+=lazy[nod];
lazy[nod]=0;
return;
}
long long max1(long long a,long long b)
{
if (a>b)
{
return a;
}
return b;
}
void update(long long st,long long dr,long long nod,long long ua,long long ub,long long val)
{
if (ua<=st&&dr<=ub)
{
arb[nod]+=val;
lazy[nod]+=val;
return ;
}
propaga(st,dr,nod);
long long mij=(st+dr)/2;
if (ua<=mij)
{
update(st,mij,2*nod,ua,ub,val);
}
if (mij<ub)
{
update(mij+1,dr,2*nod+1,ua,ub,val);
}
arb[nod]=max(arb[2*nod],arb[2*nod+1]);
}
std::vector<long long > countScans(std::vector<long long > A,std::vector<long long > X,std::vector<long long > val){
long long q=X.size();
n=A.size();
for (i=0;i<n;i++)
{
v[i+1]=A[i];
}
for (i=1;i<=n;i++)
{
m[{v[i],i}]=1;
}
for (i=0;i<q;i++)
{
m[{val[i],X[i]+1}]=1;
}
nr=0;
for (auto ind: m)
{
nr++;
m[ind.first]=nr;
}
update(1,nr,1,1,nr,-INF);
for (i=1;i<=n;i++)
{
v[i]=m[{v[i],i}];
update(1,nr,1,v[i],v[i],INF+i);
update(1,nr,1,v[i]+1,nr,-1);
}
long long j;
vector <long long > sol;
for (i=0;i<q;i++)
{
long long poz=X[i]+1;
update(1,nr,1,v[poz],v[poz],-INF-poz);
update(1,nr,1,v[poz]+1,nr,1);
v[poz]=m[{val[i],poz}];
update(1,nr,1,v[poz],v[poz],INF+poz);
update(1,nr,1,v[poz]+1,nr,-1);
sol.push_back(arb[1]-1);
}
return sol;
}