이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<stack<int>>
struct segmentTree {
int n;
vi L;
void set_n(int a) {
n = a;
L.resize(4*n, 0);
}
void update(int p, int l, int r, int x, int v) {
if (l > x || r < x) return;
if (l == r) {
L[p] = v;
return;
}
int m = (l+r)/2;
update(p*2, l, m, x, v);
update(p*2+1, m+1, r, x, v);
L[p] = L[p*2] + L[p*2+1];
}
int query(int p, int l, int r, int x, int y) {
//cerr << p << " " << l << " " << r << " " << x << " " << y << endl;
if (l > y || r < x) return 0;
if (x <= l && r <= y) {
return L[p];
}
int m = (l+r)/2;
return query(p*2, l, m, x, y) + query(p*2+1, m+1, r, x, y);
}
};
ll count_swaps(vector<int> S) {
//cerr << endl;
int n = S.size();
vs L(n*2+5);
for (int i = n-1; i > -1; i--) L[S[i]+n].push(i);
segmentTree T;
T.set_n(n+5);
ll t = 0;
int p = 0;
while (p < n) {
//cerr << p << " " << t << endl;
L[S[p]+n].pop();
if (T.query(1, 0, n, p, p)) {
//cerr << "oink" << endl;
p++; continue;
}
//cerr << "oink" << endl;
int a = L[S[p]*(-1)+n].top();
t += a-p-T.query(1, 0, n, p, a);
if (S[p] < 0) t--;
T.update(1, 0, n, a, 1);
p++;
}
return t;
}
# | 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... |