이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#include "shoes.h"
using namespace std;
struct BIT{
int N;
vector<int> arr;
BIT(int N){
this->N = N;
arr = vector<int> (N);
}
int q(int idx){
int s = 0;
while(idx > 0){
s += arr[idx];
idx -= (idx & (-idx));
}
return s;
}
void u(int idx, int val){
while(idx < N){
arr[idx] += val;
idx += (idx & (-idx));
}
}
};
int count_swaps_perm(vector<signed> s, vector<int> indices, vector<int> perm) {
int N = s.size();
BIT bit (N + 1);
map<int,pair<int,vector<int>>> mp;
for(int i = 0; i < N; i++){
mp[s[i]].second.push_back(i);
bit.u(i + 1, i);
if(i < N - 1) bit.u(i + 2, -i);
}
int res = 0;
for(int i = 0; i < N / 2; i++){
int idx1 = indices[perm[i]];
res += bit.q(idx1 + 1);
if(idx1 < N - 1) bit.u(idx1 + 2, -1);
int idx2 = mp[s[idx1] * -1].second[mp[s[idx1] * -1].first++];
res += bit.q(idx2 + 1);
if(idx2 < N - 1) bit.u(idx2 + 2,-1);
}
return res;
}
int count_swaps(vector<signed> s){
int N = s.size();
vector<int> indices;
for(int i = 0; i < N; i++){
if(s[i] < 0) indices.push_back(i);
}
vector<int> temp (N / 2);
for(int i = 0; i < N / 2; i++) temp[i] = i;
return count_swaps_perm(s, indices, temp);
}
# | 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... |