# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
589776 | shrimb | Arranging Shoes (IOI19_shoes) | C++17 | 389 ms | 285348 KiB |
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"bits/stdc++.h"
using namespace std;
#include "shoes.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
long long count_swaps(std::vector<int> s) {
int n = s.size();
int a[n];
int b[n];
int c[n];
int d[n];
memset(d, 0, sizeof d);
queue<int> p[n + 1];
stack<int> p2[n + 1];
for (int i = 0 ; i < n ; i++) {
if (s[i] > 0) p[s[i]].push(i);
else p2[-s[i]].push(i);
}
int cnt = 0, cnt2 = 0;
for (int i = 0 ; i < n ; i++) {
if (s[i] < 0) {
c[cnt] = i;
a[i] = cnt++;
c[cnt] = p[-s[i]].front();
a[p[-s[i]].front()] = cnt++;
p[-s[i]].pop();
}
}
cnt = 0;
for (int i = 0 ; i < n ; i++) {
if (d[i]) continue;
if (a[i] & 1) {
b[i] = cnt + 1;
b[c[a[i] - 1]] = cnt;
cnt += 2;
} else {
b[i] = cnt;
b[c[a[i] + 1]] = cnt + 1;
cnt += 2;
}
}
long long ret = 0;
ordered_set<int> os;
for (int i = n - 1 ; i >= 0 ; i--) {
ret += os.order_of_key(b[i]);
os.insert(b[i]);
}
return ret;
}
Compilation message (stderr)
# | 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... |