Submission #554443

#TimeUsernameProblemLanguageResultExecution timeMemory
554443n0sk1llArranging Shoes (IOI19_shoes)C++14
45 / 100
352 ms26456 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long int typedef li; int n; int fwt[200005]; void add(int i) { for (;i<=2*n;i+=(i&-i)) fwt[i]++; } int pre(int i) { li ret=0; for (;i;i-=(i&-i)) ret+=fwt[i]; return ret; } int gde[200005]; li invcount(int n) { li ans=0; //for (int i=0;i<2*n;i++) cout<<gde[i]<<" "; cout<<endl; for (int i=0;i<2*n;i++) { ans+=i-pre(gde[i]); //cout<<i<<": "<<pre(gde[i])<<endl; //for (int i=1;i<=2*n;i++) cout<<fwt[i]<<","; cout<<endl<<endl; add(gde[i]); } return ans; } int cnt[100005]; li count_swaps(vector<int> s) { n=s.size()/2; for (int i=0;i<2*n;i++) if (s[i]>0) cnt[s[i]]++; vector<int> pom; map<int,vector<int>> poz; for (int i=0;i<2*n;i++) { int x=abs(s[i]); if (cnt[x]) pom.push_back(-x),pom.push_back(x),cnt[x]--; } for (int i=0;i<2*n;i++) poz[s[i]].push_back(i); for (int i=2*n-1;i>=0;i--) gde[i]=poz[pom[i]].back()+1,poz[pom[i]].pop_back(); return invcount(n); } /* 2 1 2 -1 -2 */
#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...