이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll tree[200100];
ll tam;
void update(ll pos,ll val){
while(pos<=tam){
tree[pos]+=val;
pos+=(pos&-pos);
}
}
ll query(ll pos){
ll curr=0;
while(pos>0){
curr+=tree[pos];
pos-=(pos&-pos);
}
return curr;
}
unordered_map<ll,set<ll> > mp;
long long count_swaps(std::vector<int> s) {
tam=s.size();
bool vis[tam];
memset(vis,0,sizeof vis);
for(int i=0;i<tam;i++){
mp[s[i]].insert(i);
}
set<ll>::iterator it,it1;
ll ans=0;
for(int i=0;i<tam-1;i++){
if(vis[i])continue;
vis[i]=1;
mp[s[i]].erase(i);
if(s[i]>0){
it=mp[(s[i]*-1)].begin();
mp[s[i]*-1].erase(it);
ll aux=*it;
ll curr=i+query(i+1ll);
ll curr1=aux+query(aux+1ll);
ll currans=curr1-curr;
vis[aux]=1;
update(i+1,1);
update(aux+1,-1);
ans+=currans;
}
else{
it=mp[s[i]*-1].begin();
mp[s[i]*-1].erase(it);
ll aux=*it;
ll curr=i+query(i+1ll);
ll curr1=aux+query(aux+1ll);
ll currans=curr1-(curr+1);
ans+=currans;
//cout<<currans<<endl;
if(currans!=0){
update(i+2,1);
update(aux,-1);
}
}
}
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... |