제출 #1236418

#제출 시각아이디문제언어결과실행 시간메모리
1236418marizaArranging Shoes (IOI19_shoes)C++20
10 / 100
1101 ms142012 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define MID ((l+r)/2)

long long count_swaps(vector<int> s){
    ll n=s.size()/2;

    queue<ll> l[n+1], r[n+1];
    ll c=0;
    for(ll i=0; i<2*n; i++){
        if(s[i]<0){
            l[-s[i]].push(2*c);
            r[-s[i]].push(2*c+1);
            // cout<<-s[i]<<" "<<2*i<<endl;
            c++;
        }
    }
    // cout<<"ok1"<<endl;

    vector<ll> s2;
    ll pos[2*n];
    for(ll i=0; i<2*n; i++){
        if(s[i]<0){
            s2.push_back(l[-s[i]].front());
            pos[l[-s[i]].front()]=s2.size()-1;
            l[-s[i]].pop();
        }
        else{
            s2.push_back(r[s[i]].front());
            pos[r[s[i]].front()]=s2.size()-1;
            r[s[i]].pop();
        }
    }
    // cout<<"ok2"<<endl;

    ll ans=0;
    for(ll i=0; i<2*n; i++){
        for(ll j=0; j<i; j++){
            if(s2[j]>s2[i]) ans++;
        }
    }
    
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...