Submission #346612

#TimeUsernameProblemLanguageResultExecution timeMemory
346612PetyArranging Shoes (IOI19_shoes)C++14
100 / 100
133 ms8684 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; int aib[200002], n; void update (int x, int val) { for (int i = x; i <= n; i += (i & -i)) aib[i] += val; } int query (int x) { int sum = 0; for (int i = x; i; i -= (i & -i)) sum += aib[i]; return sum; } int calc (int x) { x++; return x + query(x); } long long count_swaps (vector<int>v) { set<pair<int, int>> s; n = v.size(); long long ans = 0; for (int i = 0; i < v.size(); i++) { int x = v[i]; auto it = s.lower_bound({-x, 0}); if (it != s.end() && (*it).first == -x) { if (x > 0) ans += calc(i) - calc((*it).second) - 1; else ans += calc(i) - calc((*it).second); s.erase(it); update(i + 1, -1); update((*it).second + 1, 1); } else s.insert({x, i}); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int i = 0; i < v.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...