제출 #783261

#제출 시각아이디문제언어결과실행 시간메모리
783261ivazivaArranging Shoes (IOI19_shoes)C++14
0 / 100
1 ms212 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; #define MAXN 200010 long long nn; long long niz[MAXN]; long long fenvik[MAXN]; map<long long,vector<long long>> mapa; void update(long long x) { if (x<=2*nn) { fenvik[x]++; x+=x&(-x); } } long long sum(long long x) { long long ans=0; while (x>0) { ans+=fenvik[x]; x-=x&(-x); } return ans; } long long count_swaps(std::vector<int> s) { nn=s.size()/2; long long sol=0; for (long long i=1;i<=2*nn;i++) { cout<<sol<<" "; niz[i]=s[i-1]; if (mapa[-niz[i]].empty()) mapa[niz[i]].push_back(i); else { long long poz=mapa[-niz[i]].back(); sol+=(i-poz-1-sum(i)+sum(poz-1)); mapa[-niz[i]].pop_back(); update(i); update(poz); } cout<<sol<<endl; } return sol; }
#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...