#include #include #include #include #include using namespace std; template struct FenwickTree { // Use 0 based indices. int n; vector tree; FenwickTree(int n_) : n(n_+1) { tree.assign(n + 1, 0); } T query(int r) const { // [0, r] assert(r+1 <= n); T s = 0; for(++r; r > 0; r -= (r & (-r))) s = max(s, tree[r]); return s; } void update(int i, T v) { for(++i; i <= n; i += (i & (-i))) tree[i] = max(tree[i], v); } }; // Find existence of 213 relative permutation in n lg n time. bool solve(){ int n; cin >> n; vector a(n); for(auto &x : a) cin >> x; // Iterate from high to low. vector idx(n); iota(begin(idx), end(idx), 0); sort(begin(idx), end(idx), [&](int i, int j){ return a[i] > a[j]; }); FenwickTree ft(n); bool found = false; int right = -1; for(auto i : idx){ auto x = a[i]; // point 2: update all points to the right of here. ft.update(i, right); // point 3. right = max(right, i); // point 1. if(ft.query(i-1) > i){ found = true; break; } } return found; } int main(){ int ts; cin >> ts; vector ans; for(int t = 1; t <= ts; ++t) if(solve()) ans.push_back(t); cout << ans.size() << endl; for(auto x : ans) cout << x << endl; }