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 st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pii>;
using ll = long long;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
cerr<<h;
if(sizeof...(t))cerr<<", ";
debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);
const int N=2e5+5;
int tab[N+N];
void add(int v, int c){
for(v+=N; v; v>>=1){
tab[v]+=c;
}
}
int sum(int l, int r){
int ans=0;
for(l+=N, r+=N; l<r; l>>=1, r>>=1){
if(l&1)ans+=tab[l++];
if(r&1)ans+=tab[--r];
}
return ans;
}
ll count_swaps(std::vector<int> s) {
int n=s.size()/2;
vector<vi> L(n), R(n);
for(int i=0; i<n+n; i++){
if(s[i]>0)L[s[i]-1].pb(i);
else R[-1-s[i]].pb(i);
add(i, 1);
}
for(int i=0; i<n; i++){
reverse(all(R[i]));
reverse(all(L[i]));
}
ll ans=0;
for(int i=0; i<n+n; i++){
if(tab[N+i]){
int t=abs(s[i])-1;
if(s[i]>0)ans++;
int k=max(L[t].back(), R[t].back());
add(k, -1);
ans+=sum(i+1,k);
L[t].pp();
R[t].pp();
}
}
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... |