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>
#include "shoes.h"
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);
queue<int> kanan[121212];
int BIT[121212];
void update(int p) {
for (int i = p; i <= 1e5; i += (i & (-i))) BIT[i]++;
}
int query(int p) {
int cnt = 0;
for (int i = p; i > 0; i -= (i & (-i))) {
cnt += BIT[i];
}
return cnt;
}
long long count_swaps(vector<int> s) {
int n = s.size();
//priority_queue<pair<int, int> > pq;
LL ans = 0;
for (int i = 0; i < n; i += 2) {
if (s[i] < 0) {
for (int j = i + 1; j < n; j++) {
if (s[j] == -s[i]) {
int idx = j;
while (idx != i + 1) {
swap(s[idx], s[idx - 1]);
ans++;
idx--;
}
break;
}
}
} else {
for (int j = i + 1; j < n; j++) {
if (s[j] == -s[i]) {
int idx = j;
while (idx != i) {
swap(s[idx - 1], s[idx]);
ans++;
idx--;
}
break;
}
}
}
}
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... |