Submission #382424

#TimeUsernameProblemLanguageResultExecution timeMemory
382424mariowongArranging Shoes (IOI19_shoes)C++14
0 / 100
97 ms135020 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; long long n,pos1[100005],now,pos2[100005],pt1,pt2; long long ans1,ans2; queue <long long> v[100005],v2[100005]; vector <long long> ct1,ct2,d1,d2; void cntInv(int l,int r){ if (l == r); else { int mid=(l+r)/2; ct1.clear(); ct2.clear(); d1.clear(); d2.clear(); for (int i=l;i<=mid;i++){ ct1.push_back(pos1[i]); ct2.push_back(pos2[i]); } sort(ct1.begin(),ct1.end()); sort(ct2.begin(),ct2.end()); reverse(ct1.begin(),ct1.end()); reverse(ct2.begin(),ct2.end()); for (int i=mid+1;i<=r;i++){ d1.push_back(pos1[i]); d2.push_back(pos2[i]); } sort(d1.begin(),d1.end()); sort(d2.begin(),d2.end()); reverse(d1.begin(),d1.end()); reverse(d2.begin(),d2.end()); pt1=0; pt2=0; for (int i=0;i<d1.size();i++){ while (pt1 < (int)ct1.size() && ct1[pt1] >= d1[i]) pt1++; while (pt2 < (int)ct2.size() && ct2[pt2] >= d2[i]) pt2++; ans1+=pt1; ans2+=pt2; } cntInv(l,mid); cntInv(mid+1,r); } } long long count_swaps(std::vector<int> s) { n=(long long)s.size(); for (int i=0;i<n;i++){ if(s[i] > 0) v[s[i]].push(i); else v2[-s[i]].push(i); } for (int i=0;i<n;i++){ if (s[i] < 0){ pos1[i]=now; pos1[v[-s[i]].front()]=now+1; v[-s[i]].pop(); now+=2; } } now=0; for (int i=0;i<n;i++){ if (s[i] > 0){ pos2[i]=now+1; pos2[v2[s[i]].front()]=now; v2[s[i]].pop(); now+=2; } } cntInv(0,n-1); cout << min(ans1,ans2) << "\n"; return 1; } /*int r,x; vector <int> ori; int main(){ cin >> r; for (int i=0;i<r;i++){ cin >> x; ori.push_back(x); } count_swaps(ori); }*/

Compilation message (stderr)

shoes.cpp: In function 'void cntInv(int, int)':
shoes.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int i=0;i<d1.size();i++){
      |                ~^~~~~~~~~~
#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...