이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
#define ll int
#define x first
#define y second
using namespace std;
ll n;
vector<ll>a;
vector<ll>fn;
void update(ll x, ll y){
ll f = x;
while(f <= n){
fn[f]+=y;
f =f|(f+1);
}
}
ll sum(ll x){
ll num = 0;
ll f = x;
while(f >= 0){
num += fn[f];
f=(f&(f+1))-1;
}
return num;
}
long long count_swaps(vector<int> s)
{
n=s.size();
a.resize(n+1,1);
fn.resize(n+1);
for (int i=0;i<=n;i++)
update(i,1);
map<ll,deque<ll> >mp;
for (int i=0;i<n;i++)
mp[s[i]].push_back(i);
long long ans=0;
for (ll i=0;i<n;i++)
{
if (a[i]==0)
continue;
ll p=mp[-s[i]].front();
mp[-s[i]].pop_front();
mp[s[i]].pop_front();
update(p,-1);
update(i,-1);
a[i]=a[p]=0;
ans+=sum(p)-sum(i);
if (s[i]>0)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... |