Submission #197352

#TimeUsernameProblemLanguageResultExecution timeMemory
197352hank55663Arranging Shoes (IOI19_shoes)C++14
100 / 100
387 ms148856 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; int S[200005]; void add(int x,int k){ for(int i =x;i<200005;i+=i&-i){ S[i]+=k; } } int query(int x){ int res=0; for(int i=x;i>0;i-=i&-i){ res+=S[i]; } return res; } queue<int> pool[200005]; long long count_swaps(std::vector<int> sh) { //printf("?\n"); set<int> s; queue<int> *m=pool+100002; for(int i = 0;i<sh.size();i++){ add(i+1,1); s.insert(i); m[sh[i]].push(i); } //printf("?\n"); long long ans=0; while(!s.empty()){ int x=*s.begin(); s.erase(s.begin()); m[sh[x]].pop(); add(x+1,-1); int y=m[-sh[x]].front(); m[-sh[x]].pop(); s.erase(y); ans+=query(y); add(y+1,-1); //printf("%d %d\n",x,y); if(sh[x]>0)ans++; } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:22:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<sh.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...