Submission #433195

#TimeUsernameProblemLanguageResultExecution timeMemory
433195kostia244Arranging Shoes (IOI19_shoes)C++17
30 / 100
80 ms6736 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; using ll = long long; #define all(x) begin(x), end(x) long long count_swaps(std::vector<int> s) { int n = s.size()/2; vector<ll> fen(2*n+1); auto add = [&](int x) { for(; x <= 2*n; x += x&-x) fen[x]++; }; auto get = [&](int x) { int res = 0; add(x); for(; x; x -= x&-x) res += fen[x]; return res; }; ll res = 0; map<int, int> tie; for(auto &i : s) i = 2*abs(i) + (i>0); vector<array<int, 3>> b; for(int i = 0; i < 2*n; i++) b.push_back({s[i], tie[s[i]]++, i+1}); sort(all(b), [&](auto x, auto y) { if(x[0]/2 != y[0]/2) return x[0]/2 < y[0]/2; if(x[1] != y[1]) return x[1] < y[1]; return x[0] < y[0]; }); int cur = 0; for(auto [_, __, i] : b) { //cout << _ << " " << __ << " " << i << endl; res += ++cur - get(i); } return res; }
#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...