# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
387452 | ismoilov | Arranging Shoes (IOI19_shoes) | C++14 | 1096 ms | 35180 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fv(c) for(int (a) = (1); (a) <= (c); (a)++)
#define fz(c) for(int (a) = (0); (a) < (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
#define pb push_back
#define in insert
#define ss second
#define ff first
struct ftree
{
vector <int> bit;
ftree(int n){
bit = vector<int> (n+1);
}
void add(int k, int x){
k ++;
while(k < (int)bit.size()){
bit[k] += x;
k += k & -k;
}
}
int sum(int k)
{
int ans = 0;
k ++;
while(k){
ans += bit[k];
k -= k & -k;
}
return ans;
}
};
ll count_swaps(vector <int> s)
{
ftree Ftree(s.size());
map<int, vector<int>> m;
set<int> c;
fp(i,0,s.size()){
c.in(i);
m[s[i]].pb(i);
Ftree.add(i, 1);
}
ll ans = 0;
while(!c.empty()){
int x = *c.begin(); c.erase(c.begin());
m[s[x]].erase(m[s[x]].begin());
int y = *m[-s[x]].begin(); m[-s[x]].erase(m[-s[x]].begin());
Ftree.add(x, -1);
Ftree.add(y, -1);
c.erase(y);
int g = Ftree.sum(y);
if(s[x] > 0)
g ++;
ans += g;
}
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... |