This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "shoes.h"//
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int MAXN = 100 * 1000 + 23;
map<int, vector<int>> v;
ordered_set t;
vector<pii> vec;
long long count_swaps(vector<int> s) {
int n = s.size() / 2, cnt = 0, a[MAXN << 1];
long long ans = 0;
for (int i = 0; i < (n << 1); i++) {
v[s[i]].push_back(i);
if (!v[-s[i]].empty()) {
a[i] = cnt++;
a[v[-s[i]].back()] = cnt++;
if (s[i] > 0) swap(a[i], a[v[-s[i]].back()]);
v[s[i]].pop_back();
v[-s[i]].pop_back();
}
}
for (int i = 0; i < (n << 1); i++) {
// cout << a[i] << ' ';
ans += t.size() - t.order_of_key(a[i]);
t.insert(a[i]);
}//cout << endl;
return ans;
}
//int main() {cout << count_swaps({2, 1, -1, -2});}//
# | 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... |