#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ar array
const int MOD = 1e9 + 7, N = 2e5 + 5;
long long INF = 1e18;
vector <long long> f;
long long n;
long long get(long long x){
long long res = 0;
for(long long i = x;i >= 0;i = (i & (i + 1)) - 1){
res += f[i];
}
return res;
}
long long getsum(long long l ,long long r){
if(l == 0){
return get(r);
}
return get(r) - get(l - 1);
}
void update(long long x){
// cout<<x<<endl;
for(long long i = x;i < n;i = (i | (i + 1))){
f[i]++;
}
}
long long count_swaps(std::vector<int> s) {
long long n = s.size();
f.clear();
f.resize(n);
map<int, stack <int>> mp;
for(int i = n - 1;i >= 0;i--){
mp[s[i]].push(i);
}
long long 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] > 0 && s[j] == -s[i]){
while(j != i + 1){
swap(s[j] , s[j - 1]);
j--;
ans++;
}
break;
}
}
}
if(s[i] > 0){
for(int j = i + 1;j < n;j++){
if(s[j] < 0 && -s[j] == s[i]){
while(j != i){
swap(s[j] , s[j - 1]);
j--;
ans++;
}
break;
}
}
}
}
// cout<<ans;
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... |