Submission #309536

#TimeUsernameProblemLanguageResultExecution timeMemory
309536lucaperjuArranging Shoes (IOI19_shoes)C++14
50 / 100
51 ms7152 KiB
//#include "shoes.h" #include <bits/stdc++.h> using namespace std; int fv[100005],ok[100005]; vector<int>v[100005]; void next (int &j) { ++j; while(ok[j]) ++j; } struct ura { int sum,val; }vc[100005]; bool cmp (ura a, ura b) { return a.sum<b.sum; } int bc[100005]; int aib[200005]; int lsb (int x) { return x&-x; } void update (int pz) { for(int i=pz;i<=200002;i+=lsb(i)) ++aib[i]; } int query (int pz) { int rz=0; for(int i=pz;i>0;i-=lsb(i)) rz+=aib[i]; return rz; } long long count_swaps(std::vector<int> s) { int n=s.size()/2; int i,j,mx=0; for(i=0;i<s.size();++i) { if(s[i]>0) ++fv[s[i]],ok[s[i]]=1; } j=0; next(j); for(i=0;i<s.size();++i) { if(s[i]<0) continue; if(fv[s[i]]>1) { --fv[s[i]]; v[s[i]].push_back(j); s[i]=j; next(j); } else fv[s[i]]=0; } for(i=0;i<s.size();++i) if(s[i]<0 && fv[-s[i]]<v[-s[i]].size()) s[i]=-v[-s[i]][fv[-s[i]]++]; // for(i=0;i<s.size();++i) // cout<<s[i]<<' '; cout<<'\n'; for(i=1;i<=n;++i) fv[i]=0; int rz=0; for(i=0;i<s.size();++i) { int vlc=s[i]; if(vlc<0) vlc=-vlc; vc[vlc].sum+=i; vc[vlc].val=vlc; } sort(vc+1,vc+n+1,cmp); for(i=1;i<=n;++i) { bc[vc[i].val]=i; } for(i=0;i<s.size();++i) { if(s[i]>0) s[i]=bc[s[i]]; else s[i]=-bc[-s[i]]; if(s[i]<0) s[i]=2*(-s[i]-1)+1; else s[i]=2*(s[i]-1)+2; } // for(i=0;i<s.size();++i) // cout<<s[i]<<' '; cout<<'\n'; for(i=s.size()-1;i>=0;--i) { rz+=query(s[i]); update(s[i]); } return rz; } /*int main() { int n,i; cin>>n; vector<int>idk; for(i=1;i<=n;++i) { int a; cin>>a; idk.push_back(a); } cout<<count_swaps(idk); } */

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:42:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for(i=0;i<s.size();++i)
      |          ~^~~~~~~~~
shoes.cpp:49:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(i=0;i<s.size();++i)
      |             ~^~~~~~~~~
shoes.cpp:63:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(i=0;i<s.size();++i)
      |             ~^~~~~~~~~
shoes.cpp:64:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         if(s[i]<0 && fv[-s[i]]<v[-s[i]].size())
      |                      ~~~~~~~~~^~~~~~~~~~~~~~~~
shoes.cpp:72:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(i=0;i<s.size();++i)
      |             ~^~~~~~~~~
shoes.cpp:85:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for(i=0;i<s.size();++i)
      |             ~^~~~~~~~~
shoes.cpp:41:10: warning: unused variable 'mx' [-Wunused-variable]
   41 |  int i,j,mx=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...