이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
const int N = 2e5+5;
deque<int> lft[N], rgt[N];
ll count_swaps(vector<int> S){
int n = S.size();
S.insert(S.begin(), -1);
for (int i = 1; i <= n; i++){
if (S[i] > 0) rgt[S[i]].pb(i);
else lft[-S[i]].pb(i);
}
ll ans = 0;
ordered_set s;
for (int i = 1; i <= n; i++){
if (s.find(i) != s.end()) continue;
int j = 0;
while(s.size() and (*s.begin()) <= i) s.erase(s.begin());
if (S[i] > 0) j = lft[S[i]].front();
else j = rgt[-S[i]].front();
lft[abs(S[i])].pop_front();
rgt[abs(S[i])].pop_front();
ans += (j-i-s.order_of_key(j)-(S[i] < 0));
s.insert(j);
}
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... |