# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
390126 | ioi | Arranging Shoes (IOI19_shoes) | C++14 | 273 ms | 208228 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 ;
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());
for(int i = 0 ;i < s.size() ; i ++)
bit.update(i , 1);
long long 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 += bit.query(i + 1 , p);
bit.update(p , -1);
if(s[i] < 0)ans -- ;
}
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... |