Submission #143454

#TimeUsernameProblemLanguageResultExecution timeMemory
143454ChrisTArranging Shoes (IOI19_shoes)C++17
100 / 100
414 ms138476 KiB
#include<bits/stdc++.h> #include "shoes.h" using namespace std; typedef long long ll; const int MN = 2e5+2; bool done[MN]; deque<int> inds[MN]; int bit[MN]; void update (int i, int v) { for (i++;i<MN;i+=i&-i) bit[i] += v; } int query (int i) { int ret = 0; for (i++;i>0;i^=(i&-i)) ret += bit[i]; return ret; } ll count_swaps (vector<int> s) { int n = s.size(); ll ret = 0; for (int i = 0; i < n; i++) { inds[s[i]+100000].push_back(i); } for (int i = 0; i < n; i++) if (!done[i]){ int cur = s[i], ind = inds[100000-s[i]].front(); inds[100000-s[i]].pop_front(); inds[s[i]+100000].pop_front(); done[ind] = 1; if (ind == i+1 && s[i] < 0) continue; ret += ind - i - (s[i] < 0) - query(ind) + query(i); update(ind,1); } return ret; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:25:13: warning: unused variable 'cur' [-Wunused-variable]
         int cur = s[i], ind = inds[100000-s[i]].front(); inds[100000-s[i]].pop_front(); inds[s[i]+100000].pop_front();
             ^~~
#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...