Submission #530471

#TimeUsernameProblemLanguageResultExecution timeMemory
530471jamezzzArranging Shoes (IOI19_shoes)C++17
100 / 100
126 ms139940 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; int n,m[200005],ft[200005],o=100000; vector<pair<int,int>> v; queue<int> q[200005]; void up(int x,int v){ while(x<=n){ ft[x]+=v,x+=x&-x; } } int qry(int x){ int res=0; while(x)res+=ft[x],x-=x&-x; return res; } long long count_swaps(vector<int> s){ n=(int)s.size(); long long ans=0; for(int i=0;i<n;++i){ if(q[o-s[i]].empty())q[o+s[i]].push(i); else{ int j=q[o-s[i]].front(); q[o-s[i]].pop(); v.push_back({j+1,i+1}); if(s[i]<0)++ans; } } sort(v.begin(),v.end()); for(int i=n/2-1;i>=0;--i){ ans+=qry(v[i].second)-qry(v[i].first-1); up(v[i].first,1);up(v[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...