이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
#include "shoes.h"
using namespace std;
typedef long long ll;
vector<ll> t;
ll getSum(ll idx){
ll sum = 0;
idx++;
while (idx > 0){
sum += t[idx];
idx -= idx & (-idx);
}
return sum;
}
void updateF(ll n, ll idx, ll val){
idx++;
while (idx <= n){
t[idx] += val;
idx += idx & (-idx);
}
}
ll count_swaps(vector<int> s){
ll n = s.size();
t.assign(n + 2, 0);
vector<queue<ll>> cnt1(n + 1, queue<ll> ()), cnt2(n + 1, queue<ll> ());
queue<ll> q;
for (ll i = n - 1; i >= 0; i--){
if (s[i] < 0)
cnt2[-s[i]].push(i);
else
cnt1[s[i]].push(i);
}
vector<bool> koristen(n, false);
ll res = 0;
ll pocetak = n - 2;
for (int i = n - 1; i >= 0; i--){
if (koristen[i])
continue;
ll curr = i;
ll par;
if (s[i] < 0){
res++;
par = cnt1[-s[i]].front();
cnt1[-s[i]].pop();
cnt2[-s[i]].pop();
}
else{
par = cnt2[s[i]].front();
cnt1[s[i]].pop();
cnt2[s[i]].pop();
}
for (int j = 0; j < n; j++)
cout << getSum(j) << " ";
cout << endl;
cout << curr << " " << par << "*";
updateF(n, par + 1, -1);
koristen[i] = true;
koristen[par] = true;
par += getSum(par);
res += pocetak - par;
cout << pocetak + 1 << " " << par << endl;
pocetak -= 2;
}
return res;
}
# | 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... |