Submission #804495

#TimeUsernameProblemLanguageResultExecution timeMemory
804495farukArranging Shoes (IOI19_shoes)C++17
45 / 100
41 ms9536 KiB
#include "shoes.h" #include <bits/stdc++.h> #define mp make_pair #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef pair<int, int> pii; struct seggy { int n; vector<ll> t; seggy(ll siz) {n = siz, t.resize(2*n);} ll query(int l, int r) { ll out = 0; for (l += n, r += n+1; l < r; l /= 2, r /= 2) { if (l & 1) out += t[l++]; if (r & 1) out += t[--r]; } return out; } void upd(int idx, int val) { idx += n; while (idx > 0) t[idx] += val, idx /= 2; } }; ll count_inv(vector<ll> perm) { seggy seg(perm.size()); ll out = 0; for (int i = 0; i < perm.size(); i++) { out += seg.query(perm[i], perm.size() - 1); seg.upd(perm[i], 1); } return out; } long long count_swaps(std::vector<int> s) { ll n = s.size(); vector<ll> neww(n); int pnt = 1; for (int i = 0; i < n; i++) if (s[i] > 0) neww[i] = pnt, pnt += 2; pnt = 0; for (int i = 0; i < n; i++) if (s[i] < 0) neww[i] = pnt, pnt += 2; return count_inv(neww); }

Compilation message (stderr)

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