이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define forn(j, i, n) for(int i = j; i <= n; ++i)
#define FOR(j, i, n) for(int i = j; i < n; ++i)
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
const int maxn=1e5+10;
int n, fen[maxn];
void upd(int r, int val)
{
for(; r <= n; r = ((r + 1) | r))
{
fen[r] += val;
}
}
int get(int r)
{
int s = 0;
for(; r >= 0; r = ((r + 1) & r) - 1)
{
s += fen[r];
}
return s;
}
long long count_swaps(std::vector<int> S)
{
n = S.size();
map <int, vector <int> > mapp;
vector <int> del(n, 0);
for(int i = n-1; i >= 0; --i)
{
mapp[S[i]].pb(i);
upd(i, 1);
}
ll ans = 0;
FOR(0, i, n)
{
if(del[i]) continue;
int pos = mapp[-S[i]].back();
mapp[-S[i]].pop_back();
ans += get(pos)-get(i) - (S[i] < 0);
del[pos] = 1;
upd(pos, -1);
}
return ans;
}
| # | 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... |