QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692654#9332. Permutations and Cycles (Maximum Version)lytqwq#AC ✓11ms5280kbC++141.2kb2024-10-31 14:52:282024-10-31 14:52:30

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 14:52:30]
  • 评测
  • 测评结果:AC
  • 用时:11ms
  • 内存:5280kb
  • [2024-10-31 14:52:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int read(){
    int res=0,zf=1;char ch;
    while((ch=getchar())<48||ch>57)if(ch=='-')zf=!zf;res=(ch^48);
    while((ch=getchar())>=48&&ch<=57)res=(res<<3)+(res<<1)+(ch^48);
    return zf?res:(-res);
}
#define N 500010
int a[N];
stack<pair<int,int> >q;
stack<pair<int,int> >g;
int n,m;
int main(){
    int t=read();
    while(t--){
        n=read();m=read();
        int L=1,R=n-1;
        while(!q.empty())q.pop();
        while(!g.empty())g.pop();
     //   puts("?");
        while(L<R){
            q.push(make_pair(L,R));
            L+=2;R-=2;
        }
       // puts("!!!");
        int cnt=0;
        while(!q.empty()){
            int x=q.top().first,y=q.top().second;q.pop();
            if(y+y+1>m){
                g.push(make_pair(x,y));
                cnt++;
            }else{

            }
        }
        printf("%d\n",n-cnt);
        for(int i=1;i<=n;i++)a[i]=i;
        while(!g.empty()){
            int x=g.top().first,y=g.top().second;g.pop();
            a[x]=y;
            a[y]=x;
        }
        for(int i=1;i<=n;i++)printf("%d ",a[i]);
        puts("");
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3692kb

input:

3
2 3
3 4
3 5

output:

2
1 2 
2
2 1 3 
3
1 2 3 

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3984kb

input:

16
5 8
4 5
2 3
7 12
5 8
10 15
7 10
10 14
5 9
2 3
10 17
8 11
8 14
3 4
9 16
5 8

output:

4
4 2 3 1 5 
3
3 2 1 4 
2
1 2 
6
6 2 3 4 5 1 7 
4
4 2 3 1 5 
9
9 2 3 4 5 6 7 8 1 10 
6
6 2 3 4 5 1 7 
8
9 2 7 4 5 6 3 8 1 10 
5
1 2 3 4 5 
2
1 2 
9
9 2 3 4 5 6 7 8 1 10 
7
7 2 3 4 5 6 1 8 
7
7 2 3 4 5 6 1 8 
2
2 1 3 
8
8 2 3 4 5 6 7 1 9 
4
4 2 3 1 5 

result:

ok ok

Test #3:

score: 0
Accepted
time: 5ms
memory: 3784kb

input:

22
539 540
9618 19087
8415 9369
236 471
2103 3286
6124 6125
3792 7583
2164 4327
1012 1013
2916 2917
3609 4447
6177 6178
4550 4953
3477 6953
2467 4933
9318 16901
5467 8084
3516 6584
2128 2129
6427 9233
7272 11558
8673 11944

output:

404
538 2 536 4 534 6 532 8 530 10 528 12 526 14 524 16 522 18 520 20 518 22 516 24 514 26 512 28 510 30 508 32 506 34 504 36 502 38 500 40 498 42 496 44 494 46 492 48 490 50 488 52 486 54 484 56 482 58 480 60 478 62 476 64 474 66 472 68 470 70 468 72 466 74 464 76 462 78 460 80 458 82 456 84 454 86...

result:

ok ok

Test #4:

score: 0
Accepted
time: 5ms
memory: 3720kb

input:

359
100 101
101 201
102 103
103 205
104 207
105 106
106 107
107 108
108 109
109 110
110 111
111 221
112 113
113 114
114 115
115 116
116 117
117 118
118 235
119 120
120 121
121 122
122 123
123 124
124 125
125 249
126 251
127 128
128 255
129 257
130 131
131 132
132 133
133 134
134 267
135 269
136 137
...

output:

75
99 2 97 4 95 6 93 8 91 10 89 12 87 14 85 16 83 18 81 20 79 22 77 24 75 26 73 28 71 30 69 32 67 34 65 36 63 38 61 40 59 42 57 44 55 46 53 48 51 50 49 52 47 54 45 56 43 58 41 60 39 62 37 64 35 66 33 68 31 70 29 72 27 74 25 76 23 78 21 80 19 82 17 84 15 86 13 88 11 90 9 92 7 94 5 96 3 98 1 100 
101
...

result:

ok ok

Test #5:

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

input:

38
5693 10440
5550 6937
5036 7510
5826 7748
4790 4947
5432 9412
5269 10320
5561 8957
5776 7407
5044 9330
5764 7194
5988 8034
5095 5877
5360 5944
5560 10514
5869 7762
5187 7513
5457 8552
5103 7318
5238 7068
5903 11784
5887 8297
5107 6734
5211 5650
5410 6562
5562 8119
4976 6122
5071 8842
5225 8451
498...

output:

5456
5692 2 5690 4 5688 6 5686 8 5684 10 5682 12 5680 14 5678 16 5676 18 5674 20 5672 22 5670 24 5668 26 5666 28 5664 30 5662 32 5660 34 5658 36 5656 38 5654 40 5652 42 5650 44 5648 46 5646 48 5644 50 5642 52 5640 54 5638 56 5636 58 5634 60 5632 62 5630 64 5628 66 5626 68 5624 70 5622 72 5620 74 561...

result:

ok ok

Test #6:

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

input:

1
200000 364465

output:

191116
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #7:

score: 0
Accepted
time: 7ms
memory: 4924kb

input:

1
200000 399999

output:

200000
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

result:

ok ok

Test #8:

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

input:

13
17766 31770
18662 18663
13358 13370
19528 25756
14119 21269
13110 26219
17381 31063
12457 12458
17028 24550
16194 27456
12720 12879
10558 10559
17119 17120

output:

16825
17765 2 17763 4 17761 6 17759 8 17757 10 17755 12 17753 14 17751 16 17749 18 17747 20 17745 22 17743 24 17741 26 17739 28 17737 30 17735 32 17733 34 17731 36 17729 38 17727 40 17725 42 17723 44 17721 46 17719 48 17717 50 17715 52 17713 54 17711 56 17709 58 17707 60 17705 62 17703 64 17701 66 1...

result:

ok ok

Test #9:

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

input:

15
15374 16312
14411 28195
12508 24643
10483 20124
15267 15606
15272 30542
17551 35031
15661 30951
11970 12684
16166 16745
13873 27274
12511 24167
11005 21639
12782 13375
5166 5174

output:

11765
15373 2 15371 4 15369 6 15367 8 15365 10 15363 12 15361 14 15359 16 15357 18 15355 20 15353 22 15351 24 15349 26 15347 28 15345 30 15343 32 15341 34 15339 36 15337 38 15335 40 15333 42 15331 44 15329 46 15327 48 15325 50 15323 52 15321 54 15319 56 15317 58 15315 60 15313 62 15311 64 15309 66 1...

result:

ok ok

Test #10:

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

input:

2
100000 100001
100000 199999

output:

75000
99999 2 99997 4 99995 6 99993 8 99991 10 99989 12 99987 14 99985 16 99983 18 99981 20 99979 22 99977 24 99975 26 99973 28 99971 30 99969 32 99967 34 99965 36 99963 38 99961 40 99959 42 99957 44 99955 46 99953 48 99951 50 99949 52 99947 54 99945 56 99943 58 99941 60 99939 62 99937 64 99935 66 9...

result:

ok ok

Test #11:

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

input:

4
50000 75000
50000 52232
50000 99332
50000 93827

output:

43750
49999 2 49997 4 49995 6 49993 8 49991 10 49989 12 49987 14 49985 16 49983 18 49981 20 49979 22 49977 24 49975 26 49973 28 49971 30 49969 32 49967 34 49965 36 49963 38 49961 40 49959 42 49957 44 49955 46 49953 48 49951 50 49949 52 49947 54 49945 56 49943 58 49941 60 49939 62 49937 64 49935 66 4...

result:

ok ok

Test #12:

score: 0
Accepted
time: 9ms
memory: 3756kb

input:

135
1601 1829
1944 3450
2000 3917
1261 1689
1404 1832
1158 1511
1990 3640
1323 2459
1420 1826
1639 1748
1309 2246
1043 1215
1069 2094
1577 2985
1239 2343
1066 1718
1106 1512
1122 1444
1375 1620
1452 2833
1844 3508
1841 2159
1127 1330
1894 1999
1896 2142
1008 1393
1794 3498
1042 1371
1960 2126
1559 2...

output:

1258
1600 2 1598 4 1596 6 1594 8 1592 10 1590 12 1588 14 1586 16 1584 18 1582 20 1580 22 1578 24 1576 26 1574 28 1572 30 1570 32 1568 34 1566 36 1564 38 1562 40 1560 42 1558 44 1556 46 1554 48 1552 50 1550 52 1548 54 1546 56 1544 58 1542 60 1540 62 1538 64 1536 66 1534 68 1532 70 1530 72 1528 74 152...

result:

ok ok

Test #13:

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

input:

14
18303 18463
10001 10139
12939 13145
13431 26772
14731 29091
19418 38625
18746 37401
10807 21403
15272 30510
15489 15543
18814 37480
13039 13190
13460 13799
5550 10822

output:

13767
18302 2 18300 4 18298 6 18296 8 18294 10 18292 12 18290 14 18288 16 18286 18 18284 20 18282 22 18280 24 18278 26 18276 28 18274 30 18272 32 18270 34 18268 36 18266 38 18264 40 18262 42 18260 44 18258 46 18256 48 18254 50 18252 52 18250 54 18248 56 18246 58 18244 60 18242 62 18240 64 18238 66 1...

result:

ok ok

Test #14:

score: 0
Accepted
time: 11ms
memory: 5208kb

input:

1
200000 390071

output:

197518
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #15:

score: 0
Accepted
time: 7ms
memory: 4920kb

input:

1
200000 390000

output:

197500
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #16:

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

input:

1
200000 299999

output:

175000
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #17:

score: 0
Accepted
time: 11ms
memory: 4980kb

input:

1
200000 300000

output:

175000
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #18:

score: 0
Accepted
time: 11ms
memory: 4980kb

input:

1
200000 219292

output:

154823
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #19:

score: 0
Accepted
time: 11ms
memory: 5172kb

input:

1
200000 398485

output:

199621
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #20:

score: 0
Accepted
time: 3ms
memory: 4864kb

input:

1
200000 200011

output:

150003
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #21:

score: 0
Accepted
time: 11ms
memory: 4980kb

input:

1
200000 364469

output:

191117
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #22:

score: 0
Accepted
time: 11ms
memory: 4940kb

input:

1
200000 200002

output:

150000
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #23:

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

input:

1
200000 386869

output:

196717
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #24:

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

input:

1
200000 398856

output:

199714
199999 2 199997 4 199995 6 199993 8 199991 10 199989 12 199987 14 199985 16 199983 18 199981 20 199979 22 199977 24 199975 26 199973 28 199971 30 199969 32 199967 34 199965 36 199963 38 199961 40 199959 42 199957 44 199955 46 199953 48 199951 50 199949 52 199947 54 199945 56 199943 58 199941 ...

result:

ok ok

Test #25:

score: 0
Accepted
time: 0ms
memory: 3728kb

input:

30
2 3
3 4
3 5
4 5
4 6
4 7
5 6
5 7
5 8
5 9
6 7
6 8
6 9
6 10
6 11
7 8
7 9
7 10
7 11
7 12
7 13
8 9
8 10
8 11
8 12
8 13
8 14
8 15
9 10
9 11

output:

2
1 2 
2
2 1 3 
3
1 2 3 
3
3 2 1 4 
3
3 2 1 4 
4
1 2 3 4 
4
4 2 3 1 5 
4
4 2 3 1 5 
4
4 2 3 1 5 
5
1 2 3 4 5 
5
5 2 3 4 1 6 
5
5 2 3 4 1 6 
5
5 2 3 4 1 6 
5
5 2 3 4 1 6 
6
1 2 3 4 5 6 
5
6 2 4 3 5 1 7 
6
6 2 3 4 5 1 7 
6
6 2 3 4 5 1 7 
6
6 2 3 4 5 1 7 
6
6 2 3 4 5 1 7 
7
1 2 3 4 5 6 7 
6
7 2 5 4 3 6...

result:

ok ok