# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
438733 | CSQ31 | 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 "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz(a) (int)(a.size());
typedef pair<int,int> pii;
vector<int>bit(100000);
int n;
void upd(int pos,int val){
for(int i=pos;i<=n;i+=i&(-i))bit[i]+=val;
}
int query(int pos){
int res = 0;
while(pos){
res+=bit[pos];
pos-=pos&(-pos);
}
return res;
}
vector<int> countScans(vector<int> a,vector<int> x,vector<int>v){
int q=sz(x);
n = sz(a);
vector<int> answer(q);
for (int j=0;j<q;j++) {
for(int i=1;i<=n;i++)bit[i] = 0;
a[x[j]] = v[j];
for(int i=0;i<n;i++){b[i].fi = a[i];b[i].se = i+1;}
sort(b.begin(),b.end());
int mx = 0;
for(int i=n-1;i>=0;i--){
mx = max(query(b[i].se),mx);
upd(b[i].se,1);
}
answer[j] = mx;
}
return answer;
}