제출 #411390

#제출 시각아이디문제언어결과실행 시간메모리
411390pliamArranging Shoes (IOI19_shoes)C++14
50 / 100
299 ms49104 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MAXN 100005 int N; map<int,vector<int>> emf; int resp[MAXN];//start position of respective pair bool used[MAXN]; int bit[MAXN]; ll ans; int lsone(int x){ return x&(-x); } void update(int pos){ pos++; for(int x=pos;x<=N;x+=lsone(x)){ bit[x]++; } } int query(int pos){ pos++; int res=0; for(int x=pos;x>0;x-=lsone(x)){ res+=bit[x]; } return res; } long long count_swaps(std::vector<int> s) { N=s.size(); for(int i=N-1;i>=0;i--){ emf[s[i]].push_back(i); } for(int i=0;i<N;i++){ if(used[i]) continue; resp[i]=emf[-s[i]].back(); emf[-s[i]].pop_back(); emf[s[i]].pop_back(); used[i]=true; used[resp[i]]=true; } memset(used,false,sizeof(used)); for(int i=0;i<N;i++){ if(used[i]) continue; ll pos1=i-query(i-1); ll pos2=resp[i]-query(resp[i]-1); ans+=(pos2-pos1+((s[i]<0)?-1:0)); update(i); update(resp[i]); used[i]=true; used[resp[i]]=true; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...