Submission #143378

#TimeUsernameProblemLanguageResultExecution timeMemory
143378abekerArranging Shoes (IOI19_shoes)C++17
10 / 100
18 ms14456 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 2e5 + 5; int N; vector <int> lft[MAXN], rig[MAXN], perm[MAXN]; ll inversions(vector <int> v) { reverse(v.begin(), v.end()); int len = v.size(); vector <int> fen(len + 1, 0); ll res = 0; for (auto it : v) { for (int x = it; x; x -= x & -x) res += fen[x]; for (int x = it + 1; x <= len; x += x & -x) fen[x]++; } return res; } ll count_swaps(vector <int> shoes) { N = shoes.size(); for (int i = 0; i < N; i++) { int sz = abs(shoes[i]); if (shoes[i] < 0) { perm[sz].push_back(2 * lft[sz].size()); lft[sz].push_back(i); } else { perm[sz].push_back(2 * rig[sz].size() + 1); rig[sz].push_back(i); } } ll sol = 0; for (int i = 0; i < N; i++) { sol += inversions(perm[i]); for (int j = 0; j < lft[i].size(); j++) sol += abs(lft[i][j] - rig[i][j]) - 1; } return sol; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:42:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < lft[i].size(); j++)
                   ~~^~~~~~~~~~~~~~~
#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...