| 比赛 |
2026.3.28 |
评测结果 |
AAAAATTTTTT |
| 题目名称 |
Good Cyclic Shifts |
最终得分 |
45 |
| 用户昵称 |
dbk |
运行时间 |
15.439 s |
| 代码语言 |
C++ |
内存使用 |
3.71 MiB |
| 提交时间 |
2026-03-28 11:26:33 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int t, n, p, k;
int a[N], ans[N], d, c[N];
int lowbit(int x){
return x & -x;
}
void add(int x){
while(x <= n){
c[x] += 1;
x += lowbit(x);
}
}
int query(int x){
int res = 0;
while(x >= 1){
res += c[x];
x -= lowbit(x);
}
return res;
}
int main(){
freopen("Shifts.in", "r", stdin);
freopen("Shifts.out", "w", stdout);
cin >> t;
while(t--){
d = 0;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
for(int i = 0;i < n;i++){
k = 0, p = 0;
if(i){
for(int j = n - 1;j >= 1;j--) swap(a[j + 1], a[j]);
}
for(int j = 1;j <= n;j++){
c[j] = 0;
}
for(int j = 1;j <= n;j++){
p += abs(a[j] - j);
k += (j - query(a[j]) - 1);
add(a[j]);
}
p /= 2;
if(k <= p){
ans[++d] = i;
}
}
cout<<d<<endl;
for(int i = 1;i < d;i++){
cout<<ans[i]<<' ';
}
if(d) cout<<ans[d];
cout<<endl;
}
}