제출 #433202

#제출 시각아이디문제언어결과실행 시간메모리
433202kostia244Arranging Shoes (IOI19_shoes)C++17
45 / 100
350 ms27084 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) { for(auto &i : s) i *= -1; 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; vector<int> b(2*n); map<int, vector<int>> ass; for(int i = 0; i < 2*n; i++) ass[s[i]].push_back(i); for(auto &[a, b] : ass) reverse(all(b)); vector<int> v(2*n, -69); for(int j = 0, i = 0; i < 2*n; i++) if(s[i] >= 0) { v[i] = ++j; v[ass[-s[i]].back()] = ++j; ass[-s[i]].pop_back(); } //for(auto &i : v) cout << i << " "; cout << endl; for(int i = 0; i < 2*n; i++) b[v[i]-1] = i+1; int cur = 0; for(auto i : b) { //cout << _ << " " << __ << " " << i << endl; //cout << i << " "; res += ++cur - get(i); //cout << i << " " << res << endl; } 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...