# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
534802 | andecaandeci | Arranging Shoes (IOI19_shoes) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
typedef int 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);
}
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);
ans += ed;
}
//cout << ans << endl;
return ans;
}
// int main(){
// // freopen("input.txt", "r", stdin);
// //freopen("output.txt", "w", stdout);
// fastt();
// //cin >> tc;
// while(tc--){
// cin >> n;
// vector<ll> v;
// while(n--){
// cin >> m;
// v.pb(m);
// }
// count_swaps(v);
// }
// }
/*
*/