# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
390122 | ioi | Arranging Shoes (IOI19_shoes) | C++14 | 224 ms | 206952 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 "shoes.h"
#include<bits/stdc++.h>
using namespace std ;
const int N = 3e5 ;
int add = 1e5 + 5 ;
queue<int> pos[N];
int done[N] ;
struct BIT{
int sz ;
vector<long long> v;
explicit BIT(int n){
sz = n ;
v.resize(n);
}
long long get(int i){
long long ret = 0 ;
for(i ++ ; i ; i -=(i & -i))
ret += v[i - 1];
return ret ;
}
void update(int i , long long val){
for(i ++ ; i <= sz ; i += (i & -i))
v[i - 1] += val ;
}
long long query(int l , int r){
return get(r) - get(l - 1);
}
};
long long count_swaps(vector<int> s) {
for(int i = 0 ; i < s.size() ; i ++){
pos[s[i] + add].push(i);
}
BIT bit(s.size());
int ans = 0 ;
for(int i = 0 ; i < s.size() ; i ++){
if(done[i])continue ;
int p = pos[-s[i] + add].front();
pos[-s[i] + add].pop();
done[p] ++;
pos[s[i] + add].pop();
// cout << i << " " << p << endl ;
ans += p - i - 1 - bit.query( i, p) + (s[i] > 0 ? 1 : 0);
bit.update(p , 1);
}
return ans;
}
Compilation message (stderr)
# | 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... |