제출 #785159

#제출 시각아이디문제언어결과실행 시간메모리
785159acatmeowmeowArranging Shoes (IOI19_shoes)C++14
0 / 100
4 ms5220 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e5 + 5; vector<int> lef, rig[N]; int tree[2*N]; void update(int n, int k, int v) { for (; k <= n; k += k&-k) tree[k] += v; } int query(int k) { int sum = 0; for (; k; k -= k&-k) sum += tree[k]; return sum; } long long count_swaps(std::vector<signed> s) { ios::sync_with_stdio(false); cin.tie(nullptr); int n = s.size()/2; s.insert(s.begin(), 0); for (int i = 1; i <= 2*n; i++) { if (s[i] < 0) lef.push_back(i); else rig[s[i]].push_back(i); } sort(lef.begin(), lef.end()); for (int i = 1; i <= N; i++) sort(rig[i].begin(), rig[i].end(), greater<int>()); int index = 0, ans = 0; for (auto&i : lef) { index++; int new_i = i + query(2*n) - query(i); ans += new_i - index; update(2*n, i, 1); index++; int j = rig[-s[i]].back(); rig[-s[i]].pop_back(); int new_j = j + query(2*n) - query(j); ans += new_j - index; update(2*n, j, 1); } return ans; } /*signed main() { int n; cin >> n; vector<signed> arr(2*n); for (int i = 0; i < 2*n; i++) cin >> arr[i]; cout << count_swaps(arr) << '\n'; return 0; }*/
#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...