제출 #808751

#제출 시각아이디문제언어결과실행 시간메모리
808751KemalKArranging Shoes (IOI19_shoes)C++17
0 / 100
1 ms300 KiB
#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;
		int pos = nd.first;
		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);
		if (value > 0){
			ans++;
		}
		st.erase(st.begin());
		st.erase(find_element);
	}
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:26:7: warning: unused variable 'pos' [-Wunused-variable]
   26 |   int pos = nd.first;
      |       ^~~
#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...