Submission #298260

#TimeUsernameProblemLanguageResultExecution timeMemory
298260emil_physmathArranging Shoes (IOI19_shoes)C++17
45 / 100
97 ms6768 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; using llong = long long; #define BUGO(x) cerr << #x << " = " << x << '\n'; const int maxN = 200'005; int t[maxN * 4]; void Add(int v, int vl, int vr, int i, int val) { if (vl == vr) { t[v] = val; return; } int vm = vl + (vr - vl) / 2; if (i <= vm) Add(v * 2, vl, vm, i, val); else Add(v * 2 + 1, vm + 1, vr, i, val); t[v] = t[v * 2] + t[v * 2 + 1]; } int Count(int v, int vl, int vr, int l, int r) { if (l > vr || vl > r) return 0; if (l <= vl && vr <= r) return t[v]; int vm = vl + (vr - vl) / 2; return Count(v * 2, vl, vm, l, r) + Count(v * 2 + 1, vm + 1, vr, l, r); } long long count_swaps(vector<int> a) { int n = a.size(); llong ans = 0; vector<int> l, r; vector<int> pos(n); for (int i = 0; i < n; ++i) if (a[i] < 0) { pos[i] = l.size() * 2; l.push_back(i); } else { pos[i] = r.size() * 2 + 1; r.push_back(i); } for (int i = 0; i < n; ++i) { ans += Count(1, 0, n - 1, pos[i], n - 1); Add(1, 0, n - 1, pos[i], 1); } return ans; }
#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...