Submission #415686

#TimeUsernameProblemLanguageResultExecution timeMemory
415686MlxaArranging Shoes (IOI19_shoes)C++14
100 / 100
336 ms26712 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define mp make_pair #define mt make_tuple #define x first #define y second #include "shoes.h" const int N = 1 << 20; int fen[N]; int f(int x) { // cout << x << endl; int s = 0; for (int i = x; i >= 0; i = (i & (i + 1)) - 1) { s += fen[i]; } for (int i = x; i < N; i |= i + 1) { ++fen[i]; } return s; } ll count_swaps(vector<int> s) { map<int, vector<int>> open, close; vector<pair<int, int>> pairs; for (int i = 0; i < (int)s.size(); ++i) { if (s[i] < 0) { open[abs(s[i])].push_back(i); } else { close[abs(s[i])].push_back(i); } } for (auto xop : open) { const vector<int> &op = xop.y; const vector<int> &cl = close[xop.x]; assert(op.size() == cl.size()); for (int i = 0; i < (int)op.size(); ++i) { pairs.emplace_back(op[i], cl[i]); } } ll answer = 0; for (auto &e : pairs) { if (e.x > e.y) { ++answer; swap(e.x, e.y); } // cout << "# " << e.x << " " << e.y << endl; } sort(all(pairs)); reverse(all(pairs)); for (auto e : pairs) { answer += f(e.y); answer += f(e.x); } return answer; } #ifdef LC #include "grader.cpp" #endif
#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...