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>
#define ll long long
using namespace std;
const int maxn=2e5+5;
ll N,niz[maxn],par[maxn];
ll res=0;
map<int,queue<int>> mapa;
ll count_swaps(vector<int> s) {
N=s.size();
for(int i=0;i<N;i++)
niz[i+1]=s[i];
for(int i=1;i<=N;i++){
int sup=-niz[i];
if(mapa[sup].size()!=0){
int x=mapa[sup].front();
mapa[sup].pop();
par[x]=i;
par[i]=x;
continue;
}
mapa[niz[i]].push(i);
}
for(int i=1;i<=N;i++){
if(niz[i]==0)
continue;
if(niz[i]>0) /// Zamena leva-desna na kraju
res++;
for(int j=i+1;j<par[i];j++)
if(niz[j]!=0)
res++;
niz[i]=0;
niz[par[i]]=0;
}
return res;
}
# | 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... |