#include using namespace std; using ll = long long; using pll = pair; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; template struct segtree{ int n; vector dat; segtree(int n_){ n = 1; while(n < n_) n*=2; dat.resize(2*n, e()); } void update(int k, T x){ k += n-1; dat[k] = x; while(k > 0){ k = (k-1)/2; dat[k] = op(dat[2*k+1], dat[2*k+2]); } } // the prod element of [a, b) T query(int a, int b){return query_sub(a, b, 0, 0, n);} T query_sub(int a, int b, int k, int l, int r){ if(r <= a || b <= l){ return e(); }else if(a <= l && r <= b){ return dat[k]; }else{ T vl = query_sub(a, b, 2*k+1, l, (l+r)/2); T vr = query_sub(a, b, 2*k+2, (l+r)/2, r); return op(vl, vr); } } }; int op(int a, int b){ return a+b; } int e(){ return 0; } void solve(){ int n; cin >> n; vector p(n), rp(n); for(int i=0; i> p[i]; p[i]--; rp[p[i]] = i; } segtree seg(n); int rinv = 0; for(int i=0; i deq; for(int i=0; i ans(n); for(int i=0; i> T; while(T--) solve(); }