Submission #334298

#TimeUsernameProblemLanguageResultExecution timeMemory
334298nicholaskArranging Shoes (IOI19_shoes)C++14
100 / 100
94 ms11240 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long bit[200005]; void add(int x,int v){ for (int i=x; i<200005; i+=(i&-i)) bit[i]+=v; } int query(int x){ int ans=0; for (int i=x; i; i-=(i&-i)) ans+=bit[i]; return ans; } long long count_swaps(vector <int> s){ int n=(s.size()>>1); long long ans=0; vector <pair <int,int> > shs[100001]; vector <pair <int,int> > q; for (int i=0; i<n+n; i++) shs[abs(s[i])].push_back({s[i],i}); for (int i=1; i<100001; i++){ sort(shs[i].begin(),shs[i].end()); int m=(shs[i].size()>>1); for (int j=0; j<m; j++){ int ff=shs[i][j].second,ss=shs[i][j+m].second; if (ff>ss){ swap(ff,ss); ans++; } q.push_back({ff+1,ss+1}); } } sort(q.begin(),q.end()); for (int i=1; i<=n+n; i++) add(i,1); for (auto&i:q){ ans+=query(i.second-1)-query(i.first); add(i.first,-1); add(i.second,-1); } return ans; }
#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...