제출 #888127

#제출 시각아이디문제언어결과실행 시간메모리
888127oblantisArranging Shoes (IOI19_shoes)C++17
100 / 100
295 ms277328 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include "shoes.h"
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9 + 10000;
const int mod = 1e9+7;
const int maxn = 5e5 + 12;

long long count_swaps(vector<int> a) {
	int n = a.size();
	ll ans = 0;
	vector<bool> was(n, 0);
	queue<int> l[n + 1], r[n + 1];
	ordered_set s;
	for(int i = 0; i < n; i++) {
		if(a[i] < 0)l[-a[i]].push(i);
		else r[a[i]].push(i);
	}
	for(int i = 0; i < n; i++){
	    if(was[i]) {
	        s.erase(s.begin());
	        continue;
	    }
	    int j;
	    if(a[i] < 0) {
	         j = r[-a[i]].front();
            ans += j - i - 1 - s.order_of_key(j);
	        s.insert(j);
	        was[j] = 1;
	        r[-a[i]].pop();
	        l[-a[i]].pop();
	    }
	    else {
	         j = l[a[i]].front();
	        ans += j - i - s.order_of_key(j);
	        was[j] = 1;
	        s.insert(j);
	        r[a[i]].pop();
	        l[a[i]].pop();
	    }
	}
	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...