제출 #986402

#제출 시각아이디문제언어결과실행 시간메모리
986402PyqeArranging Shoes (IOI19_shoes)C++17
100 / 100
215 ms88744 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long n,a[200069],pst[200069],c=0,z=0,fw[200069],fwp; unordered_map<long long,long long> fq; unordered_map<long long,queue<long long>> q; long long count_swaps(vector<int> v) { long long i,k; n=v.size(); for(i=1;i<=n;i++) { if(fq[-v[i-1]]) { a[i]=q[-v[i-1]].front()*2; q[-v[i-1]].pop(); fq[-v[i-1]]--; } else { c++; a[i]=c*2; q[v[i-1]].push(c); fq[v[i-1]]++; } if(v[i-1]<0) { a[i]--; } } for(i=1;i<=n;i++) { pst[a[i]]=i; } for(i=1;i<=n;i++) { k=0; for(fwp=pst[i]-1;fwp>0;fwp-=fwp&-fwp) { k+=fw[fwp]; } z+=pst[i]-1-k; for(fwp=pst[i];fwp<=200000;fwp+=fwp&-fwp) { fw[fwp]++; } } return z; }
#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...