Submission #227950

#TimeUsernameProblemLanguageResultExecution timeMemory
227950staniewzkiArranging Shoes (IOI19_shoes)C++17
100 / 100
170 ms14840 KiB
#include<bits/stdc++.h> using namespace std; #include "shoes.h" struct Fenwick { vector<int> tree; Fenwick(int n) : tree(n + 1) {} void update(int pos, int val) { for(pos++; pos < size(tree); pos += (pos & -pos)) tree[pos] += val; } int query(int pos) { int ret = 0; for(pos++; pos > 0; pos -= (pos & -pos)) ret += tree[pos]; return ret; } int query(int l, int r) { return query(r) - query(l - 1); } }; long long count_swaps(vector<int> s) { int m = size(s), n = m / 2; vector<vector<int>> pos(m + 1); for(int i = m - 1; i >= 0; i--) pos[n + s[i]].emplace_back(i); long long ans = 0; Fenwick tree(m); for(int i = 0; i < m; i++) { if(!tree.query(i, i)) { int j = pos[n - s[i]].back(); ans += j - (i + 1) - tree.query(i, j) + (s[i] > 0); tree.update(j, +1); pos[n - s[i]].pop_back(); pos[n + s[i]].pop_back(); } } return ans; }

Compilation message (stderr)

shoes.cpp: In member function 'void Fenwick::update(int, int)':
shoes.cpp:10:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(pos++; pos < size(tree); pos += (pos & -pos))
              ~~~~^~~~~~~~~~~~
#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...