이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long int ll;
int n;
long long count_swaps(std::vector<int> s) {
int n = s.size();
ordered_set <pair<int, int>> st;
ll ans = 0;
map <int, vector <int>> pos_right;
map <int, vector <int>> pos_left;
for (int i = n - 1; i >= 0; i--)
{
st.insert({i, s[i]});
if (s[i] > 0)
pos_right[s[i]].push_back(i);
else
pos_left[s[i]].push_back(i);
}
while(!st.empty()){
pair<int, int> nd = *st.begin();
int value = nd.second;
pair<int, int> find_element;
if (value > 0){
// right
pos_right[value].pop_back();
find_element = {pos_left[-value].back(), -value};
pos_left[-value].pop_back();
}
else{
// left
pos_left[value].pop_back();
find_element = {pos_right[-value].back(), -value};
pos_right[-value].pop_back();
}
ans += st.order_of_key(find_element) - 1;
if (value > 0){
ans++;
}
st.erase(st.begin());
st.erase(find_element);
}
return ans;
}
# | 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... |