Submission #849122

#TimeUsernameProblemLanguageResultExecution timeMemory
849122abcvuitunggioArranging Shoes (IOI19_shoes)C++17
100 / 100
50 ms15444 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; int a[200001],cnt=1,n; long long res,f[200001]; vector <int> pos[200001]; long long count_swaps(vector <int> s){ n=s.size()/2; for (int i=n*2-1;i>=0;i--) pos[s[i]+n].push_back(i); for (int i=0;i<n*2;i++) if (!a[i]){ a[i]=cnt; int j=pos[n-s[i]].back(); a[j]=cnt+1; if (s[i]>0) swap(a[i],a[j]); pos[s[i]+n].pop_back(); pos[n-s[i]].pop_back(); cnt+=2; } for (int i=n*2-1;i>=0;i--){ for (int j=a[i];j;j-=j&(-j)) res+=f[j]; for (int j=a[i];j<=n*2;j+=j&(-j)) f[j]++; } return res; }
#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...