#include #include #include #include #include using namespace std; using T = int; T op(T l, T r){ return l+r; } struct SegmentTree { int n; vector tree; T id; SegmentTree(int _n, T _id) : n(_n+1), tree(2 * n, _id), id(_id) { } void update(int i, T val) { ++i; for (tree[i+n] = op(tree[i+n], val), i = (i+n)/2; i > 0; i /= 2) tree[i] = op(tree[2*i], tree[2*i+1]); } T query(int l, int r) { ++l, ++r; T lhs = T(id), rhs = T(id); for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if ( l&1 ) lhs = op(lhs, tree[l++]); if (!(r&1)) rhs = op(tree[r--], rhs); } return op(l == r ? op(lhs, tree[l]) : lhs, rhs); } }; // 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]; }); SegmentTree st(n+1, 0); bool found = false; int right = -1; for(auto i : idx){ auto x = a[i]; // point 2: update all points between here and right if(right > i){ st.update(i+1, 1); st.update(right, -1); } // point 3. right = max(right, i); // point 1. auto v = st.query(0, i); assert(v >= 0); if(st.query(0, i) > 0){ 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; }