Submission #583325

#TimeUsernameProblemLanguageResultExecution timeMemory
583325LucppArranging Shoes (IOI19_shoes)C++17
100 / 100
140 ms140168 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define sz(x) ((int)(x).size()) vector<int> fen; void add(int i, int x){ for(i++; i < sz(fen); i+=i&-i) fen[i] += x; } int qry(int i){ int ans = 0; for(i++; i > 0; i-=i&-i) ans += fen[i]; return ans; } ll count_swaps(vector<int> s) { ll ans = 0; fen.resize(sz(s)+1); vector<queue<int>> vl(sz(s)/2+1), vr(sz(s)/2+1); vector<pair<int, int>> v; for(int i = 0; i < sz(s); i++){ if(s[i] > 0){ if(vl[s[i]].empty()) vr[s[i]].push(i); else{ v.emplace_back(vl[s[i]].front(), i); vl[s[i]].pop(); } } else{ if(vr[-s[i]].empty()) vl[-s[i]].push(i); else{ ans++; v.emplace_back(vr[-s[i]].front(), i); vr[-s[i]].pop(); } } } sort(v.begin(), v.end()); for(auto [i, j] : v){ int L = i+qry(i); int R = j+qry(j); ans += R-L-1; add(i, 1); add(j, -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...