ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196130 | #2485. 树苗 | wosile | 100 | 492ms | 1968kb | C++11 | 1008b | 2023-10-19 09:43:28 | 2023-10-19 12:09:09 |
answer
#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
int main(){
// freopen("tree.in","r",stdin);
// freopen("tree.out","w",stdout);
int T,n,x;
scanf("%d%d",&T,&x);
while(T--){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
if(x==0){
printf("%lld\n",1LL*n*(n+1)-2LL*(n/2)*(n/2+1)-1);
continue;
}
int p1=0,p2=0;
for(int i=1;i<=n;i++){
if(a[i]==n/2)p1=i;
if(a[i]==n/2+1)p2=i;
}
int o1=p1,o2=p2;
int ans1=0,ans2=0;
//1
for(int i=1;i<=n;i++)b[i]=a[i];
if(p1!=1){
if(b[1]==n/2+1)p2=p1;
swap(b[1],b[p1]);
ans1++;
}
if(p2!=n){
swap(b[n],b[p2]);
ans1++;
}
for(int i=2;i<n;i+=2)if(b[i]<=n/2)ans1++;
//2
p1=o1,p2=o2;
for(int i=1;i<=n;i++)b[i]=a[i];
if(p1!=n){
if(b[n]==n/2+1)p2=p1;
swap(b[n],b[p1]);
ans2++;
}
if(p2!=1){
swap(b[1],b[p2]);
ans2++;
}
for(int i=2;i<n;i+=2)if(b[i]>n/2)ans2++;
//02003
printf("%d\n",min(ans1,ans2));
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
10 1 8 6 3 2 1 7 5 8 4 8 8 3 4 2 6 5 1 7 8 2 6 4 7 5 3 1 8 8 6 4 8 7 1 3 2 5 8 3 1 8 5 6 4 7 2 8 2 1...
output:
2 3 3 2 2 2 3 2 3 2
result:
ok 10 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 1188kb
input:
10 1 16 1 2 10 14 5 15 16 4 12 8 7 6 9 13 11 3 16 13 5 11 1 7 8 15 9 6 14 3 16 12 10 4 2 16 13 1 12 ...
output:
5 5 5 5 6 5 4 5 5 5
result:
ok 10 lines
Test #3:
score: 10
Accepted
time: 1ms
memory: 1204kb
input:
10 0 1500 543 588 100 834 103 24 1404 1021 199 395 1307 992 31 1284 182 1382 1199 399 780 690 1094 4...
output:
1124999 1124999 1124999 1124999 1124999 1124999 1124999 1124999 1124999 1124999
result:
ok 10 lines
Test #4:
score: 10
Accepted
time: 2ms
memory: 1200kb
input:
10 1 1500 1289 1455 1108 966 1151 1194 129 1356 500 194 1313 1311 672 977 1161 989 1365 1454 1367 17...
output:
376 367 374 368 362 366 369 372 364 374
result:
ok 10 lines
Test #5:
score: 10
Accepted
time: 79ms
memory: 1592kb
input:
10 0 100000 13984 27116 76045 29312 31905 23594 52094 94604 88051 98481 70620 77017 87926 61572 6058...
output:
4999999999 4999999999 4999999999 4999999999 4999999999 4999999999 4999999999 4999999999 4999999999 4...
result:
ok 10 lines
Test #6:
score: 10
Accepted
time: 95ms
memory: 1968kb
input:
10 1 100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3...
output:
25002 25002 25002 25002 25002 25002 25002 25002 25002 25002
result:
ok 10 lines
Test #7:
score: 10
Accepted
time: 89ms
memory: 1964kb
input:
10 1 100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3...
output:
25002 25002 25002 25002 25002 25002 25002 25002 25002 25002
result:
ok 10 lines
Test #8:
score: 10
Accepted
time: 75ms
memory: 1964kb
input:
10 1 99808 54440 45174 32316 85631 23195 13230 12272 67712 67047 99679 80872 57285 7545 45417 49656 ...
output:
24854 24856 24934 24920 24814 24936 24939 24980 24900 24903
result:
ok 10 lines
Test #9:
score: 10
Accepted
time: 74ms
memory: 1964kb
input:
10 1 99916 22417 7937 97265 21568 58953 17520 5801 38081 76267 65401 68942 45736 54077 60159 56344 1...
output:
24944 24861 24854 24859 24945 24864 24933 24913 24939 24914
result:
ok 10 lines
Test #10:
score: 10
Accepted
time: 77ms
memory: 1968kb
input:
10 1 100000 28447 33141 26374 48851 21216 33527 12868 62675 20537 9699 86178 50390 81761 8818 32921 ...
output:
25001 24880 24818 24978 24963 24912 24842 24978 24873 24991
result:
ok 10 lines
Extra Test:
score: 0
Extra Test Passed