이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define re resize
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define all1(x) (x).begin()+1, (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl << flush
template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }
typedef long long ll;
typedef vector<int> vi;
struct bit {
int n;
vi tree;
bit(int n) : n(n), tree(n+1) {};
void add(int pos, int v) {
for(pos++; pos <= n; pos += pos&-pos)
tree[pos] += v;
}
int pref(int pos) {
int res = 0;
for(pos++; pos >= 1; pos -= pos&-pos)
res += tree[pos];
return res;
}
int query(int a, int b) {
assert(a <= b);
return pref(b) - pref(a-1);
}
};
ll count_swaps(vi s) {
int n = s.size()/2;
ll res = 0;
vector<queue<int>> pos(n*2+1);
loop(i, n*2)
pos[n+s[i]].push(i);
bit bt(n*2);
loop(i, n*2) bt.add(i, 1);
loop(i, n*2) if(bt.query(i, i) == 1) {
pos[n+s[i]].pop();
int x = pos[n-s[i]].front();
pos[n-s[i]].pop();
res += bt.query(i+1, x) - 1;
if(s[i] > 0) res++;
bt.add(i, -1);
bt.add(x, -1);
}
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... |