| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1026388 | ezzzay | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"shoes.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
int bit[N];
int a[N];
vector<int>v[N];
vector<int>ans;
int n;
const int mxN=2e5;
vector<int> tree(4*mxN);
int cal(int node, int L, int R, int l, int r){
if(L>r||R<l) return 0;
if(L>=l&&R<=r) return tree[node];
return cal(node*2,L,(L+R)/2,l,r)+cal(node*2+1,(L+R)/2+1,R,l,r);
}
void up(int node, int L, int R, int l, int r){
if(L>r||R<l) return;
if(L==R){
tree[node]=1;
return;
}
up(node*2,L,(L+R)/2,l,r);
up(node*2+1,(L+R)/2+1,R,l,r);
tree[node]=tree[node*2]+tree[node*2+1];
}
int find(int idx){
int s=0;
while(idx>0){
s+=bit[idx];
idx-= idx & -idx;
}
return s;
}
void update(int idx, int val){
while(idx<N){
bit[idx]+=val;
idx+= idx & -idx;
}
}
int fun(){
int s=0;
for(int i=1;i<=n;i++){
s+=cal(1,1,n,a[i],n);
up(1,1,n,a[i],a[i]);
}
return s;
}
long long count_swaps(vector<int> s) {
n=s.size();
vector<pair<int,int>>vc;
for(int i=0;i<n;i++){
if(s[i]<0){
vc.pb({i,s[i]});
}
else{
v[s[i]].pb(i);
}
}
for(int i=0;i<3e5;i++){
reverse(v[i].begin(),v[i].end());
}
sort(vc.begin(),vc.end());
for(int i=0;i<n/2;i++){
int h=vc[i].ss*-1;
a[vc[i].ff+1]=i*2+1;
a[v[h].back()+1]=i*2+2;
v[h].pop_back();
}
return fun();
}
