Submission #554362

#TimeUsernameProblemLanguageResultExecution timeMemory
554362n0sk1llArranging Shoes (IOI19_shoes)C++14
45 / 100
290 ms27452 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]; map<int,vector<int>> poz; li count_swaps(vector<int> s) { n=s.size()/2; vector<int> pom; for (int i=0;i<2*n;i++) if (s[i]<0) pom.push_back(s[i]),pom.push_back(-s[i]); 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(); } 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; } /* 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...