Submission #294895

#TimeUsernameProblemLanguageResultExecution timeMemory
294895ASDF123Arranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms384 KiB
#include "shoes.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int N = (int)2e5 + 5; //int s[N]; ll tree[N * 4]; void upd(int pos, ll val, int v = 0, int tl = 0, int tr = N) { if (tl == tr) { tree[v] += val; return; } int mid = (tl + tr ) >> 1; if (pos <= mid) { upd(pos, val, v + v + 1, tl, mid); } else { upd(pos, val, v + v + 2, mid + 1, tr); } tree[v] = tree[v + v + 1] + tree[v + v + 2]; } ll get(int l, int r, int v = 0, int tl = 0, int tr = N) { if (l <= tl && tr <= r) { return tree[v]; } if (l > tr || tl > r) { return 0; } int mid = (tl + tr) >> 1; return get(l, r, v + v + 1, tl, mid) + get(l, r, v + v + 2, mid + 1, tr); } long long count_swaps(vector<int> s) { int n = (int)s.size() / 2; ll ans = 0; for (int i = 0; i < n * 2; i++) { int pos; if (s[i] > 0) { pos = s[i] * 2 - 1; } else { pos = -s[i] * 2 - 2; } upd(pos, 1); ans += get(pos + 1, 2 * n - 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...