Submission #1045565

#TimeUsernameProblemLanguageResultExecution timeMemory
1045565boyliguanhanArranging Shoes (IOI19_shoes)C++17
100 / 100
157 ms82128 KiB
#include "shoes.h" #include<bits/extc++.h> #include<bits/stdc++.h> using namespace __gnu_pbds; using namespace std; queue<int> otherpos[100100]; long long calc(vector<int>v){ long long ans=0; int K=0; tree<int,null_type,less<>,rb_tree_tag,tree_order_statistics_node_update>st; for(auto i:v) { st.insert(i); ans+=K++-st.order_of_key(i); } return ans; } long long count_swaps(std::vector<int> s) { long long ans=0; int n=s.size()>>1; vector<int>sup; int CC=0; for(int i=0;i<n*2;i++) if(s[i]<0) otherpos[-s[i]].push(i); CC=0; vector<pair<int,int>> thgs; for(int i=0;i<n*2;i++) if(s[i]>0) { int x=otherpos[s[i]].front(); thgs.push_back({x,i}); otherpos[s[i]].pop(); } for(auto&[i,j]:thgs) if(i>j) ans++,swap(i,j); sort(thgs.begin(),thgs.end()); for(auto[i,j]:thgs) sup.push_back(i), sup.push_back(j); return ans+calc(sup); }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:21:9: warning: variable 'CC' set but not used [-Wunused-but-set-variable]
   21 |     int CC=0;
      |         ^~
#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...