제출 #769392

#제출 시각아이디문제언어결과실행 시간메모리
769392nninArranging Shoes (IOI19_shoes)C++14
10 / 100
62 ms134928 KiB
#include<bits/stdc++.h>
using namespace std;

queue<int> posi[200002];
int n;

int fenwick[200002];
void update(int x, int k) {
    while(x<=n) {
        fenwick[x] += k;
        x += (x & -x);
    }
}
int query(int x) {
    int ret = 0;
    while(x>0) {
        ret += fenwick[x];
        x -= (x & -x);
    }
    return ret;
}

long long count_swaps(vector<int> S) {
    n = S.size()/2;
    long long ans = 0;
    for(int i=0;i<2*n;i++) {
        if(!posi[n-S[i]].empty()) {
            ans += i-posi[n-S[i]].front()-query(i+1)+query(posi[n-S[i]].front())+(S[i]<0);
            update(posi[n-S[i]].front(), 1);
            update(i+1, -1);
            posi[n-S[i]].pop();
        } else {
            posi[n+S[i]].push(i+1);
        }
    }
    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...