Submission #376641

#TimeUsernameProblemLanguageResultExecution timeMemory
376641beingsebiArranging Shoes (IOI19_shoes)C++17
100 / 100
335 ms31224 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll solve(vector<int> &ax) { vector<int> aib(ax.size() + 12); auto qr = [&aib](int poz) { ll rez = 0; while (poz > 0) rez += aib[poz], poz -= poz & -poz; return rez; }; auto upd = [&aib](int poz) { while (poz < aib.size()) aib[poz]++, poz += poz & -poz; }; ll rez = 0; for (int i = 0; i < ax.size(); i++) { rez += qr(ax.size() + 2) - qr(ax[i] - 1); upd(ax[i]); } return rez; } ll count_swaps(vector<int> v) { int n = (int)v.size(); unordered_map<int, int> mn, mp, dat; unordered_map<int, vector<int>> mm; vector<int> ax, rez; ax.reserve(n); for (size_t i = 0; i < v.size(); i++) { mm[v[i]].push_back(i); if (v[i] > 0) { if (mn[v[i]] > mp[v[i]]) mn[v[i]]--; else { mp[v[i]]++; rez.push_back(v[i]); } } else { v[i] = -v[i]; if (mp[v[i]] > mn[v[i]]) mp[v[i]]--; else { mn[v[i]]++; rez.push_back(v[i]); } v[i] = -v[i]; } } for (auto &i : mm) reverse(i.second.begin(), i.second.end()); for (const auto &i : rez) { ax.push_back(mm[-i].back() + 1); ax.push_back(mm[i].back() + 1); mm[-i].pop_back(); mm[i].pop_back(); } return solve(ax); }

Compilation message (stderr)

shoes.cpp: In lambda function:
shoes.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         while (poz < aib.size())
      |                ~~~~^~~~~~~~~~~~
shoes.cpp: In function 'll solve(std::vector<int>&)':
shoes.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < ax.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...