이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |