Submission #361843

#TimeUsernameProblemLanguageResultExecution timeMemory
361843Matteo_VerzArranging Shoes (IOI19_shoes)C++17
10 / 100
41 ms6876 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; const int N = 1e5; class Fenwick { private: vector <int> a; int lsb(int i) { return (i & (-i)); } public: Fenwick(int n) { a.resize(1 + n); } void Update(int pos, int val) { for(; pos < a.size(); pos += lsb(pos)) a[pos] += val; } int Query(int pos) { int ans(0); for(; pos > 0; pos -= lsb(pos)) ans += a[pos]; return ans; } }; int rightpos[1 + N]; int lastv[1 + N]; long long count_swaps(vector<int> s) { s.insert(s.begin(), 0); int n = s.size() - 1; Fenwick aib(n); for(int i = 1; i <= n; i++) { int val = abs(s[i]); if(lastv[val] != 0) { rightpos[lastv[val]] = i; rightpos[i] = i; lastv[val] = 0; } else { lastv[val] = i; } aib.Update(i, 1); } long long ans(0); for(int i = 1; i <= n; i++) { int pereche = rightpos[i]; if(pereche != i) { aib.Update(i, -1); aib.Update(pereche, -1); if(s[i] < 0) ans += 1LL * aib.Query(pereche); else ans += 1LL * (aib.Query(pereche) + 1); } } return ans; }

Compilation message (stderr)

shoes.cpp: In member function 'void Fenwick::Update(int, int)':
shoes.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |       for(; pos < a.size(); pos += lsb(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...