Submission #783239

#TimeUsernameProblemLanguageResultExecution timeMemory
783239ivazivaArranging Shoes (IOI19_shoes)C++14
0 / 100
1 ms312 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++) { 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); } } 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...