Submission #467818

#TimeUsernameProblemLanguageResultExecution timeMemory
467818jazzupArranging Shoes (IOI19_shoes)C++14
100 / 100
264 ms275516 KiB
#include "shoes.h" #include <deque> #include <algorithm> int Fenwick[400010]; void add(int a,int b){ for(int i=a;i<=400000;i+=(i&(-i))){ Fenwick[i]+=b; } } int query(int a,int b){ if(a!=0){ return query(0,b)-query(0,a); } int ret=0; for(int i=b;i>0;i-=(i&(-i))){ ret+=Fenwick[i]; } return ret; } std::vector<std::pair<int,int> > p; std::deque<int> v[400010]; long long count_swaps(std::vector<int> s) { int n=s.size(); s.insert(s.begin(),0); for(int i=1;i<=n;i++){ if(!v[n-s[i]].empty()){ p.push_back(std::make_pair(v[n-s[i]].front(),i)); v[n-s[i]].pop_front(); } else{ v[n+s[i]].push_back(i); } } for(int i=1;i<=n;i++){ add(i,1); } // for(int i=0;i<p.size();i++){ // printf("%d %d\n",p[i].first,p[i].second); // } long long ans=0; std::sort(p.begin(),p.end()); for(int i=0;i<p.size();i++){ ans+=query(p[i].first,p[i].second-1); if(s[p[i].first]>0)ans++; add(p[i].first,-1); add(p[i].second,-1); // printf("%d %d\n",p[i].first,p[i].second); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:54:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |  for(int i=0;i<p.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...