Submission #783141

#TimeUsernameProblemLanguageResultExecution timeMemory
783141ivazivaArranging 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]; long long check[MAXN]; pair<long long,long long> par[MAXN]; 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=nn; cout<<sol<<endl; for (long long i=1;i<=nn*2;i++) { niz[i]=s[i-1]; long long x=abs(niz[i]); if (niz[i]<0) par[x].first=i; else par[x].second=i; if (check[x]==0) check[x]=i; else { sol+=(i-check[x]-1-sum(i)+sum(check[x]-1)); update(i); update(check[x]); } } for (long long i=1;i<=nn;i++) { if (par[i].first>par[i].second) sol++; } 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...