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 "shoes.h"
#include<bits/stdc++.h>
using namespace std;
bool usu[200010];
set<int>zbiory[200010];
const int base = 1<<18;
int tree[2*base];
int odczyt(int x){
x+=base;
int res = 0;
while(x>0){
// printf("%d: %d\n", x, tree[x]);
res+=tree[x];
x/=2;
}
return res;
}
void odejmij(int w, int l, int p, int a, int b){
if(p<a || b<l)return ;
if(a<=l && p<=b){
tree[w]--;
return;
}
odejmij(w*2, l, (l+p)/2, a, b);
odejmij(w*2+1, (l+p)/2+1, p, a, b);
}
long long count_swaps(std::vector<int> s) {
int n = s.size()/2;
for(int i=0;i<2*n;i++){
zbiory[s[i]+n].insert(i);
tree[i+base] = i;
}
long long wynik = 0;
for(int start = 0; start<2*n;start++){
if(usu[start])continue;
int kolor = s[start];
int pierwsza = *zbiory[n-kolor].begin();
// printf("%d %d %d %d\n", start, kolor, pierwsza, odczyt(pierwsza));
if(kolor>0)wynik++;
wynik+=odczyt(pierwsza)-1;
odejmij(1, 0, base-1, start, base-1);
odejmij(1, 0, base-1, pierwsza, base-1);
zbiory[n-kolor].erase(pierwsza);
zbiory[kolor+n].erase(start);
usu[start] = 1;
usu[pierwsza] = 1;
// printf("%d\n", wynik);
}
return wynik;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |