Submission #1073210

#TimeUsernameProblemLanguageResultExecution timeMemory
1073210andrei_iorgulescuArranging Shoes (IOI19_shoes)C++14
100 / 100
38 ms17244 KiB
#include <bits/stdc++.h> #include "shoes.h" #warning That's not FB, that's not FB using namespace std; using ll = long long; ll n; ll a[200005]; vector<int> p[100005], neg[100005]; int per[200005]; int aib[200005]; void update(int pos, int val) { for (int i = pos; i <= 2 * n; i += (i & -i)) aib[i] += val; } int query(int pos) { int rr = 0; for (int i = pos; i > 0; i -= (i & -i)) rr += aib[i]; return rr; } ll count_swaps(vector<int> S) { n = S.size() / 2; for (int i = 1; i <= 2 * n; i++) a[i] = S[i - 1]; for (int i = 1; i <= 2 * n; i++) { if (a[i] > 0) p[a[i]].push_back(i); else neg[-a[i]].push_back(i); } ll ans = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < p[i].size(); j++) { if (p[i][j] < neg[i][j]) ans++, swap(p[i][j], neg[i][j]); per[neg[i][j]] = p[i][j]; } } for (int i = 1; i <= 2 * n; i++) update(i, 1); for (int i = 1; i <= 2 * n; i++) { if (per[i] == 0) continue; ans += query(per[i] - 1) - query(i); update(per[i], -1); } return ans; }

Compilation message (stderr)

shoes.cpp:3:2: warning: #warning That's not FB, that's not FB [-Wcpp]
    3 | #warning That's not FB, that's not FB
      |  ^~~~~~~
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int j = 0; j < p[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...