Submission #266467

#TimeUsernameProblemLanguageResultExecution timeMemory
266467wdjpngArranging Shoes (IOI19_shoes)C++17
30 / 100
96 ms23544 KiB
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) #define lint long long using namespace std; vector<int>T; void update(int i, int k, int n){ i++; for(;i <= n;i+=i&-i){ T[i]+=k; } } int get(int i){ i++; int s = 0; for(; i>0; i-=i&-i){ s+=T[i]; } return s; } int getRange(int l, int r){ return get(r) - get(l-1); } lint count_swaps(vector<int> s){ int n = s.size()/2; T.resize(4*n+4); vector<set<int>>set(2*n+1); vector<bool>ignore(2*n); rep(i,2*n){ set[s[i]+n].insert(i); } int sum=0; int curAdd=0; rep(i,2*n){ if(ignore[i]){continue;} int nearest=*set[-s[i]+n].begin(); set[-s[i]+n].erase(set[-s[i]+n].begin()); ignore[nearest]=true; if(s[i]>0){sum++;} sum+=nearest-i-1 - getRange(i, nearest); update(nearest,1, 2*n); } return sum; } /* signed main(){ int n; cin >> n; n*=2; vector<int>s(n); rep(i,n){cin>>s[i];} cout << count_swaps(s); } */

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:38:9: warning: unused variable 'curAdd' [-Wunused-variable]
   38 |     int curAdd=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...