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>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <queue>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#ifdef LOCAL
#define show(x) cerr << #x" = " << (x) << "\n"
#else
#define show(x) 0
#endif
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fst first
#define snd second
#define FOR(var, from, to) for(int var = from; var < int(to); ++var)
#define all(x) x.begin(), x.end()
#define rev(x) x.rbegin(), x.rend()
#define sz(x) int(x.size())
#define vec(x) vector<x>
#define INF 2000000000
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// use unique second element of pair to work as multiset
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
const ll mod = 1000000007, mod2 = 998244353;
template<typename T, typename U> ostream &operator<<(ostream &os, pair<T,U> p){os << "(" << p.fst << "," << p.snd << ")"; return os;}
template<typename T, typename U> istream &operator>>(istream &is, pair<T,U> &p){is >> p.fst >> p.snd; return is;}
template<typename T> istream &operator>>(istream &is, vector<T> &v){FOR(i, 0, v.size()) is >> v[i]; return is;}
template<typename T> ostream &operator<<(ostream &os, vector<T> v){for(T x : v) os << x << " "; return os;}
template<typename T> ostream &operator<<(ostream &os, set<T> s){for(T x : s) os << x << " "; return os;}
template<typename T> ostream &operator<<(ostream &os, multiset<T> s){for(T x : s) os << x << " "; return os;}
template<typename T, typename U> ostream &operator<<(ostream &os, map<T,U> m){for(auto x : m) os << x << " "; return os;}
//ostream &operator<<(ostream &os, ordered_set s){for(int x : s) os << x << " "; return os;}
//ostream &operator<<(ostream &os, ordered_multiset s){for(pii x : s) os << x.fst << " "; return os;}
ll mod_pow(ll a, ll b, ll m){ ll sol = 1; while(b){ if(b&1){ sol = (sol*a)%m; b--; }else{ a = (a*a)%m; b/=2; } } return sol;}
ll rem(ll a, ll b){ ll res = a%b; return res < 0 ? res+b : res; }
// 1 -2 3 -1 -3 2
//
// 1 3 2
// -2 -1 -3
long long count_swaps(std::vector<int> s) {
int n = sz(s);
ll ans = 0;
vec(int) pos(n);
FOR(i, 0, n) pos[i] = i;
show(s);
map<int, vec(int)> m;
for(int i = n-1; i >= 0; --i){
m[s[i]].pb(i);
}
show(m);
vec(int) delta(n+1);
vec(int) ft(n+2);
auto ask = [&](int i){
int cur = 0;
for(; i > 0; i -= i&-i){
cur += ft[i];
}
return cur;
};
auto add = [&](int i, int val){
for(; i <= n; i += i&-i){
ft[i] += val;
}
};
auto add_range = [&](int l, int r, int val = 1){
add(l, val);
add(r+1, -val);
};
FOR(i, 0, n){
add_range(i+1, i+1, i);
}
vec(bool) vis(n);
FOR(i, 0, n){
if(vis[i]) continue;
show(m);
show(m[-s[i]]);
show(m[-s[i]].back());
int ii = ask(m[s[i]].back() + 1);
int j = ask(m[-s[i]].back() + 1);
show(j);
vis[m[s[i]].back()] = true;
vis[m[-s[i]].back()] = true;
m[s[i]].pp();
m[-s[i]].pp();
ans += j-ii-1 + (s[i]>0);
add_range(ii+1 + 1, j-1 + 1, 1);
//FOR(j, 0, n) show(ask(j+1));
show(ans);
}
return ans;
}
Compilation message (stderr)
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:17:17: warning: statement has no effect [-Wunused-value]
17 | #define show(x) 0
| ^
shoes.cpp:62:3: note: in expansion of macro 'show'
62 | show(s);
| ^~~~
shoes.cpp:17:17: warning: statement has no effect [-Wunused-value]
17 | #define show(x) 0
| ^
shoes.cpp:67:3: note: in expansion of macro 'show'
67 | show(m);
| ^~~~
shoes.cpp:17:17: warning: statement has no effect [-Wunused-value]
17 | #define show(x) 0
| ^
shoes.cpp:94:5: note: in expansion of macro 'show'
94 | show(m);
| ^~~~
shoes.cpp:17:17: warning: statement has no effect [-Wunused-value]
17 | #define show(x) 0
| ^
shoes.cpp:95:5: note: in expansion of macro 'show'
95 | show(m[-s[i]]);
| ^~~~
shoes.cpp:17:17: warning: statement has no effect [-Wunused-value]
17 | #define show(x) 0
| ^
shoes.cpp:96:5: note: in expansion of macro 'show'
96 | show(m[-s[i]].back());
| ^~~~
shoes.cpp:17:17: warning: statement has no effect [-Wunused-value]
17 | #define show(x) 0
| ^
shoes.cpp:99:5: note: in expansion of macro 'show'
99 | show(j);
| ^~~~
shoes.cpp:17:17: warning: statement has no effect [-Wunused-value]
17 | #define show(x) 0
| ^
shoes.cpp:107:5: note: in expansion of macro 'show'
107 | show(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... |