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;
const int M = 1 << 18, N = M << 1;
bool b[N];
int val[N];
deque<int> pos[N];
int update(int i, int add) {
i += M;
int ans = 0;
while(i > 0) {
val[i] += add;
if(i % 2 == 0)
ans += val[i+1];
i >>= 1;
}
return ans;
}
long long count_swaps(std::vector<int> s) {
long long sum = 0;
int n = (int)s.size();
for(int i = 0; i < n; i++)
pos[s[i] + M].push_back(i);
for(int i = 0; i < n; i++) {
if(!b[i]) {
while(b[pos[M-s[i]][0]]) {
cout << pos[M-s[i]][0] << '\n';
pos[M-s[i]].pop_front();
}
int position1 = i + update(i, 0),
position2 = pos[M-s[i]][0] + update(pos[M-s[i]][0], 1);
sum += position2 - position1;
if(s[i] < 0)
sum--;
b[pos[M-s[i]][0]] = true;
pos[M+s[i]].pop_front();
pos[M-s[i]].pop_front();
}
}
return sum;
}
# | 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... |