UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196150#2485. 树苗snow_trace100579ms3596kbC++111.5kb2023-10-19 10:02:302023-10-19 12:09:39

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[100005],pos[100005],b[100005];int n;
int tp;
void solve(){
    cin>>n;
    for(int i = 1;i<=n;i++)cin>>a[i];
  // cout<<n<< endl;
    for(int i = 1;i<=n;i++)pos[a[i]] = i;
    if(tp == 0){
        int ans =0;
        for(int i = 1;i<n/2;i++)ans-=2*i;
        ans++;
        for(int i = n/2+2;i<=n;i++)ans+=2*i;
        cout<< ans<<endl;return;
    }
    int ans = n;int tot =0;
    for(int i = 1;i<=n;i++)b[i] = a[i];
    if(b[1]!=n/2+1){
        for(int i = 2;i<=n;i++){
            if(b[i] == n/2+1)tot++,swap(b[i],b[1]);
        }
    }if(b[n]!=n/2){
        for(int i = 1;i<n;i++){
            if(b[i] == n/2)tot++,swap(b[i],b[n]);
        }
    }for(int i= 1;i<=n;i+=2)if(b[i]<=n/2)tot++;
    ans = min(ans,tot);tot =0 ;
   // for(int i = 1;i<=n;i++)cin>>a[i];
   for(int i = 1;i<=n;i++)b[i] = a[i];
    if(b[1]!=n/2){
        for(int i = 2;i<=n;i++){
            if(b[i] == n/2)tot++,swap(b[i],b[1]);
        }
    }if(b[n]!=n/2+1){
        for(int i = 1;i<n;i++){
            if(b[i] == n/2+1)tot++,swap(b[n],b[i]);
        }
    }for(int i =2;i<=n;i+=2)if(b[i]<=n/2)tot++;
    ans = min(ans,tot);
    cout<<ans<<endl;
    return;
}
signed main(){
    ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
    int t;cin >> t >>tp;
    while(t--){
        solve();
    }
}
/*
1 1
46
16 22 11 34 20 29 25 3 26 8 21 19 27 41 15 12 23 35 32 39 46 6 33 37 10 40 13 45 36 5 43 17 42 2 1 7 30 28 44 4 14 9 38 18 31 24
*/

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1252kb

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: 1256kb

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: 0ms
memory: 1284kb

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: 0ms
memory: 1296kb

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: 127ms
memory: 2816kb

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: 130ms
memory: 3596kb

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: 86ms
memory: 3592kb

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: 80ms
memory: 3592kb

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: 75ms
memory: 3596kb

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: 81ms
memory: 3596kb

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