// https://github.com/potato167/po167_library #include #include using namespace std; using ll=long long; const ll ILL=2167167167167167167; const int INF=2100000000; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template using pq_ = priority_queue, greater>; template int LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template int UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,T b){if(b bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} bool yneos(bool a,bool upp=false){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} template void vec_out(vector &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(int)(a&1),a>>=1;}return res;} template T square(T a){return a * a;} namespace po167{ template struct seg_sum{ int n; int seg_size; std::vector seg; T e; //要素数、単位元 typeは+演算が定義されているもの seg_sum(int k,T e_in){ e=e_in; n=k; seg_size=1; while(seg_size &q){ int n=q.size(); po167::seg_sum S(n,0); long long ans=0; for(int i=0;i //pのなかみは、重複ありで内容が同じならおけ //比較ができる必要がある。 long long inversion_vector(std::vector &p){ int n=p.size(); std::vector q(n); for(int i=0;i> t; rep(i, 0, t) solve(); } void solve(){ int N; cin >> N; vector p(N); rep(i, 0, N) cin >> p[i], p[i]--; int st = 0; while (p[st]) st++; int n = N / 2; auto q = p; while (n % 4 == 0 || n % 4 == 1) { vector nx; rep(rp, 0, 2) { vector tmp; int l = rp * n, r = (rp + 1) * n - 1; while (l < r) { nx.push_back(p[l]); tmp.push_back(p[r]); l += 2, r -= 2; } reverse(all(tmp)); for (auto x : tmp) nx.push_back(x); } q = nx; n = (int)q.size() / 2; } if (po167::inversion_vector(q) & 1) { cout << st + 1 << endl; } else { cout << (st + N / 2) % N + 1 << endl; } } /* * 順列を被らないように2つの区間を選んでください的な問題となる * シフトはまあどうでもよくて、円環の二つの区間を選ぶ感じになる * N mod 8 = 4, 6 なら 1 をはじめとした転倒数の偶奇が変わるので簡単 * N mod 16 = 10 も 1 をはじめとした転倒数の偶奇が変わるので簡単 * まあそういう感じで転倒数を抽出すればいい気がする */