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>
using namespace std;
int n;
int a[201010];
int t[801010];
int tAdd[801010];
void build(int v, int vl, int vr) {
if (vl == vr) {
t[v] = vl;
return;
}
int vm = (vl + vr) / 2;
build(2 * v, vl, vm);
build(2 * v + 1, vm + 1, vr);
}
void push(int v, int vl, int vr) {
if (tAdd[v] == 0)return;
if (vl == vr)t[v] += tAdd[v];
else {
tAdd[2 * v] += tAdd[v];
tAdd[2 * v + 1] += tAdd[v];
}
tAdd[v] = 0;
}
void upd(int v, int vl, int vr, int l, int r, int val) {
push(v, vl, vr);
if (l <= vl && vr <= r) {
tAdd[v] += val;
push(v, vl, vr);
return;
}
if (r < vl || vr < l)return;
int vm = (vl + vr) / 2;
upd(2 * v, vl, vm, l, r, val);
upd(2 * v + 1, vm + 1, vr, l, r, val);
}
int get(int v, int vl, int vr, int pos) {
if (vl == vr)return t[v];
int vm = (vl + vr) / 2;
if (pos <= vm)return get(2 * v, vl, vm, pos);
else return get(2 * v + 1, vm + 1, vr, pos);
}
vector<int> g[201010];
int pointer[201010];
int ans = 0;
long long count_swaps(std::vector<int> s) {
n = s.size();
for (int i = 1; i <= n; i++)
a[i] = s[i - 1];
build(1, 1, n);
for (int i = 1; i <= n; i++)
g[a[i] + n + 1].push_back(i);
for (int i = 1; i <= n; i += 2) {
if (a[i] < 0) {
for (int j = i + 1; j <= n; j++) {
swap(a[i + 1], a[j]);
if (a[i + 1] == -a[i])break;
ans++;
}
continue;
}
if (a[i] > 0) {
for (int j = i + 1; j <= n; j++) {
swap(a[i], a[j]);
ans++;
if (a[i + 1] == -a[i])break;
}
continue;
}
}
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... |