# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
877072 | raul2008487 | Arranging Shoes (IOI19_shoes) | C++17 | 1067 ms | 348 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>
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define in insert
using namespace std;
const int sz = 2e5+5;
ll Tree[sz];
void add(ll pos, ll val){
for(ll i = pos; i<sz ; i += (i & (-i))){
Tree[i] += val;
}
}
ll get(ll pos){
ll rx = 0;
for(ll i = pos; i>0; i -= (i & (-i))){
rx += Tree[i];
}
return rx;
}
ll ask(ll l, ll r){
return get(r) - get(l-1);
}
long long count_swaps(vector<int> s) {
ll n = s.size(), i, j, ans = 0;
set<pair<int,int>> c;
for(i=0;i<n;i++){
c.in({s[i], i});
add(i+1, 1);
}
while(c.size()){
auto x = c.begin();
pair<int,int> fr = (*x);
auto f = c.lower_bound({-fr.fi, fr.se});
int pr = (*f).se;
if(pr >= (fr.se + 2)){
ans += ask(fr.se+2, pr);
}
if(fr.fi > 0){
ans++;
}
add(fr.fi+1, -1);
add(pr+1, -1);
c.erase(x);
c.erase(f);
}
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... |