# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
534794 | makanhulia | Arranging Shoes (IOI19_shoes) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pairll pair<ll,ll>
#define lpairll pair<pairll,ll>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define repp(i,a,b) for(ll i = (a); i <= (b); i++)
#define repm(i, a, b) for (ll i = (a); i >= (b); i--)
#define repz(i, a, b) for (ll i = (a); i < (b); i++)
const ll MOD = 1e9+7, N = 2e5 + 5, M = 4e5+5, C = 1e5;
ll tc = 1, n, m=0, ar[N], tree[M];
string s, ye = "YES", no = "NO";
queue<ll> loc[N];
void fastt(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void input(){
}
void solve(){
}
ll query(ll nw, ll l, ll r, ll x, ll y){
if(l > y || r < x) return 0;
if(l >= x && r <= y) return tree[nw];
ll mid = (l+r)/2;
return query(nw*2,l,mid,x,y) + query(nw*2+1,mid+1,r,x,y);
}
void upd(ll nw, ll l, ll r, ll idx){
if(l == r){
tree[nw] = 1;
return;
}
ll mid = (l+r)/2;
if (idx <= mid) upd(nw*2,l,mid,idx);
else upd (nw*2+1,mid+1,r,idx);
tree[nw] = tree[nw*2] + tree[nw*2+1];
}
ll count_swaps(vector<ll> v){
vector<ll> t;
ll n = v.size();
t.pb(0);
for (auto i : v) t.pb(i);
v = t;
repz(i,1,v.size()){
loc[v[i]+C].push(i);
}
ll ans = 0;
memset(tree,0,sizeof(tree));
repz(i,1,v.size()){
if(loc[v[i]+C].size() <= 0) continue;
ll ed = (v[i] > 0), nx;
nx = loc[C-v[i]].front();
loc[C-v[i]].pop();
loc[C+v[i]].pop();
ed += nx-i-1;
ed -= query(1,1,n,i+1,nx-1);
upd(1,1,n,i);
}
return ans;
}
// int main(){
// // freopen("input.txt", "r", stdin);
// //freopen("output.txt", "w", stdout);
// fastt();
// //cin >> tc;
// while(tc--){
// input();
// solve();
// }
// }
/*
*/