제출 #1019469

#제출 시각아이디문제언어결과실행 시간메모리
1019469NicolaikrobArranging Shoes (IOI19_shoes)C++17
100 / 100
323 ms158248 KiB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

ll count_swaps(vector<int> S) {
    ll n = S.size(), ans = 0;
    tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> T;
    unordered_map<int, deque<int>> M; M.reserve(n);
    for(int i = 0; i < n; i++) M[S[i]].push_back(i);
    for(int i = 0; i < n; i++) T.insert({i,S[i]});
    for(int i = 0; i < n/2; i++) {
        auto itr = T.find_by_order(0);
        int val = -(*itr).second;
        ans += (ll)T.order_of_key({M[val].front(), val});
        if(val > 0) ans -= 1LL;
        T.erase(itr);
        T.erase(T.find({M[val].front(), val}));
        M[val].pop_front();
        M[-val].pop_front();
    }
    return ans;
}
/*
int main() {
    int t;
    vector<int> Q;
    while(cin>>t) Q.push_back(t);
    cout << count_swaps(Q);
}
*/
#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...