Submission #467034

#TimeUsernameProblemLanguageResultExecution timeMemory
467034jazzupArranging Shoes (IOI19_shoes)C++14
0 / 100
8 ms9944 KiB
#include "shoes.h" int Fenwick[200010]; void add(int a,int b){ for(int i=a;i<=200000;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::vector<int> v[200010]; 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]].back(),i)); v[n-s[i]].pop_back(); } else{ v[n-s[i]].push_back(i); } } // printf("PRE Fenwick\n"); for(int i=1;i<=n;i++){ add(i,1); } // printf("Initialized Fenwick\n"); long long ans=0; for(int i=0;i<p.size()-1;i++){ ans+=query(p[i].first,p[i].second); add(p[i].first,-1); add(p[i].second,-1); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:49: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]
   49 |  for(int i=0;i<p.size()-1;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...