Submission #849120

#TimeUsernameProblemLanguageResultExecution timeMemory
849120abcvuitunggioArranging Shoes (IOI19_shoes)C++17
100 / 100
46 ms16476 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; int a[200001],cnt=1; long long res,f[200001]; vector <int> pos[200001]; long long count_swaps(vector <int> s){ for (int i=s.size()-1;i>=0;i--) pos[s[i]+s.size()/2].push_back(i); for (int i=0;i<s.size();i++) if (!a[i]){ a[i]=cnt; int j=pos[s.size()/2-s[i]].back(); a[j]=cnt+1; if (s[i]>0) swap(a[i],a[j]); pos[s[i]+s.size()/2].pop_back(); pos[s.size()/2-s[i]].pop_back(); cnt+=2; } for (int i=s.size()-1;i>=0;i--){ for (int j=a[i];j;j-=j&(-j)) res+=f[j]; for (int j=a[i];j<=s.size();j+=j&(-j)) f[j]++; } return res; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i=0;i<s.size();i++)
      |                  ~^~~~~~~~~
shoes.cpp:24:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for (int j=a[i];j<=s.size();j+=j&(-j))
      |                         ~^~~~~~~~~~
#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...