Submission #826775

#TimeUsernameProblemLanguageResultExecution timeMemory
826775kevinsogoArranging Shoes (IOI19_shoes)C++17
10 / 100
748 ms30416 KiB
#include <bits/stdc++.h> using namespace std; #include "shoes.h" using ll = long long; struct Fen { vector<int> c; Fen(int n): c(n + 1) {} void inc(int i, int v = 1) { for (++i; i < c.size(); i += i & -i) c[i] += v; } int sum(int i, int v = 0) { for (; i; i -= i & -i) v += c[i]; return v; } }; ll count_swaps(vector<int> _seq) { vector<int> found(_seq.size() + 5); vector<ll> seq; for (int v : _seq) seq.push_back(ll(v) * _seq.size() + ((v > 0) - (v < 0)) * found[v + _seq.size()]++); unordered_map<ll,int> pos; pos.max_load_factor(0.5); for (int i = 0; i < seq.size(); i++) pos[seq[i]] = i; sort(seq.rbegin(), seq.rend(), [&](ll i, ll j) { int d = min(pos[i], pos[-i]) - min(pos[j], pos[-j]); return d ? d < 0 : i < j; }); for (ll& v : seq) v = pos[v]; ll ans = 0; Fen f(seq.size()); for (ll v : seq) ans += f.sum(v), f.inc(v); return ans; }

Compilation message (stderr)

shoes.cpp: In member function 'void Fen::inc(int, int)':
shoes.cpp:10:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |         for (++i; i < c.size(); i += i & -i) c[i] += v;
      |                   ~~^~~~~~~~~~
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = 0; i < seq.size(); i++) pos[seq[i]] = 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...