Submission #262030

#TimeUsernameProblemLanguageResultExecution timeMemory
262030tiberiuArranging Shoes (IOI19_shoes)C++14
100 / 100
89 ms16504 KiB
#include "shoes.h" #include <vector> using namespace std; const int MAX_N = 2e5 + 10; long long aib[MAX_N]; void update(int pos, int val) { pos++; while (pos < MAX_N) { aib[pos] += val; pos += (pos & -pos); } } long long query(int pos) { pos++; long long ans = 0; while (pos > 0) { ans += aib[pos]; pos -= (pos & -pos); } return ans; } long long count_swaps(std::vector<int> s) { int n = s.size() / 2; vector<int>* f = new vector<int>[2 * n + 1]() + n; if (query(2 * n)) return 1 / 0; for (int i = 0; i < 2 * n; i++) f[s[i]].push_back(i); vector<int> p(2 * n); for (int i = 1; i <= n; i++) { int j = 0; while (j < f[i].size()) { p[f[i][j]] = f[-i][j]; p[f[-i][j]] = f[i][j]; j++; } } long long ans = 0; for (int i = 0; i < 2 * n; i++) { if (p[i] < i) continue; if (s[p[i]] < s[i]) ans++; ans += (p[i] - i - 1) - (query(p[i] - 1) - query(i)); update(p[i], +1); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:35:18: warning: division by zero [-Wdiv-by-zero]
         return 1 / 0;
                ~~^~~
shoes.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (j < f[i].size()) {
                ~~^~~~~~~~~~~~~
#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...