This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "shoes.h"
#include <bits/stdc++.h>
#define F first
#define S seond
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
using namespace std;
typedef long long ll;
const int MAXN = (int)2e5 + 7;
const int MOD = 998244353;
const int INF = (int)1e9 + 7;
int n, m, t, tmp, tmp2, tmp3, u, v, w;
ll ans;
deque<int> vec[2][MAXN];
/* BIT */
ll fen[MAXN];
inline void upd(ll x, ll y) {
for (x++; x<MAXN; x+=x&-x) fen[x] += y;
}
inline ll get(ll x) {
ll res = 0;
for (x++; x>0; x-=x&-x) res += fen[x];
return res;
}
/* BIT */
ll count_swaps(vector<int> s) {
n = s.size()/2;
for (int i=0; i<2*n; i++) {
upd(i, 1);
if (s[i] < 0) vec[0][0-s[i]].pb(i);
else vec[1][s[i]].pb(i);
}
for (int j=0; j<2*n; j++) {
if (get(j)-get(j-1) == 0) continue;
if (s[j] < 0) {
tmp2 = vec[1][0-s[j]].front(); vec[1][0-s[j]].pop_front(); vec[0][0-s[j]].pop_front();
ans += get(tmp2-1)-get(j); upd(tmp2, -1);
} else {
tmp2 = vec[0][s[j]].front(); vec[1][s[j]].pop_front(); vec[0][s[j]].pop_front();
ans += get(tmp2)-get(j); upd(tmp2, -1);
}
upd(j, -1);
}
return ans;
}
// int main() {
// int n;
// assert(1 == scanf("%d", &n));
// vector<int> S(2 * n);
// for (int i = 0; i < 2 * n; i++)
// assert(1 == scanf("%d", &S[i]));
// fclose(stdin);
// long long result = count_swaps(S);
// printf("%lld\n", result);
// fclose(stdout);
// return 0;
// }
# | 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... |