이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <map>
#include <ext/pb_ds/assoc_container.hpp>
#include "shoes.h"
using namespace std;
using namespace __gnu_pbds;
template<typename T, typename Tk>
using os_map = tree<
T, Tk, less<T>, rb_tree_tag, tree_order_statistics_node_update
>;
template<typename T>
using os_set = os_map<T, null_type>;
long long count_swaps(vector<int> S)
{
const size_t n = S.size();
map<int, set<size_t>> pos;
for(size_t i = 0; i < n; i++)
pos[S[i]].insert(i);
os_set<size_t> erased;
size_t mex = 0;
long long result = 0;
while(erased.size() < n)
{
while(erased.find(mex) != erased.end())
mex++;
auto it = pos[-S[mex]].begin();
auto i = *it;
result += i - (mex + 1) - (erased.order_of_key(i) - erased.order_of_key(mex));
if(S[mex] > 0)
result++;
erased.insert(mex); pos[S[mex]].erase(mex);
erased.insert(i); pos[-S[mex]].erase(i);
}
return result;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |