이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define Mp make_pair
#define endl "\n"
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 1e6 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;
int Mat[N], fen[N];
void add(int i, int x)
{
for(i += 3; i < N; i += i & -i)
{
fen[i] += x;
}
}
int ask(int i, int ret = 0)
{
for(i += 3; i; i -= i & -i)
{
ret += fen[i];
}
return ret;
}
ll count_swaps(vector < int > s)
{
int n = SZ(s);
map < int, vector < int > > mp;
for(int i = n - 1; ~i; i --)
{
mp[s[i]].push_back(i);
}
ll tot = 0;
for(int i = 0; i < n; i ++)
{
if(SZ(mp[s[i]]) && mp[s[i]].back() == i)
{
mp[s[i]].pop_back();
int nxt = mp[-s[i]].back();
mp[-s[i]].pop_back();
int dis = abs(nxt - i - 1) - (ask(nxt) - ask(i));
tot += dis;
if(s[i] > 0) tot ++;
add(nxt, 1);
}
}
return tot;
}
# | 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... |