QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#343780#1817. AND PermutationLaStataleBlueRE 2486ms126528kbC++234.8kb2024-03-03 01:45:332024-03-03 01:45:33

Judging History

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

  • [2024-03-03 01:45:33]
  • 评测
  • 测评结果:RE
  • 用时:2486ms
  • 内存:126528kb
  • [2024-03-03 01:45:33]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double db;

#define TESTCASE 0

static void solve([[maybe_unused]] int tc) {
    int n;
    cin >> n;
    vector<long long> a(n);
    
    for (int i = 0; i < n; i++)cin >> a[i];
    
    /*
    set<int> ds;
    vector<long long> a;
    
    for(int i=0;i<3;i++){
        int x=rand()%128;
        for(int j=0;j<128;j++)if((x&j)==j)ds.insert(j);
    }
    for(auto i : ds)a.push_back(i);
    int n=a.size();
    
    cout<<n<<"\n";
    for(auto i : a)cout<<i<<" ";
    cout<<"\n";
    */
    if (n == 1) {
        cout << "0\n";
        return;
    }
    
    auto solve = [&](auto &solve, int pos, vector<long long> v) -> map<long long, long long> {
        if (v.size() == 0) {
            return map<long long, long long>();
        }
        if (v.size() == 2) {
            return map<long long, long long>{{v[0], v[1]},
                {v[1], v[0]}};
        }
        if (v.size() == 1) {
            return map<long long, long long>{{v[0], v[0]}};
        }
        
        //cout<<pos<<" bit\n";
        //for(auto i : v)cout<<i<<" ";
        //cout<<"\n";
        
        map<long long, long long> res;
        
        vector<long long> v0, v1;
        for (auto i: v) {
            if (i & (1ll << pos))v1.push_back(i);
            else v0.push_back(i);
        }
        
        map<long long, long long> sol0, sol1;
        sol0 = solve(solve, pos - 1, v0);
        sol1 = solve(solve, pos - 1, v1);
        
        //cout<<pos<<" bit ritorno\n";
        //for(auto i : v)cout<<i<<" ";
        //cout<<"\n";
        
        
        //cout<<"sol0 \n";
        //for(auto [i,j] : sol0)cout<<i<<" "<<j<<"\n";
        //cout<<"sol1 \n";
        //for(auto [i,j] : sol1)cout<<i<<" "<<j<<"\n";
        
        map<long long, int> col;
        auto dfs = [&](auto &dfs, long long nodo, int mode) -> void {
            
            if (col.find(nodo) != col.end())return;
            
            //cout << pos << " "<<mode<<" dfs\n";
            col[nodo] = mode;
            
            dfs(dfs, sol1[nodo], mode ^ 1);
            
            //cout<<"da "<<pos<<"check "<<(pos ^ (1ll << pos))<<"\n";
            if (sol0.find(nodo ^ (1ll << pos)) != sol0.end())
                if (sol1.find(sol0[nodo ^ (1ll << pos)] ^ (1ll << pos)) != sol1.end()) {
                dfs(dfs, sol0[nodo ^ (1ll << pos)] ^ (1ll << pos), mode ^ 1);
            }
        };
        
        int loop0 = -1, loop1 = -1;
        int cont0=0;
        int cont1=0;
        
        for (auto [i, j]: sol0) {
            if (i == j)loop0 = i,cont0++;
        }
        for (auto [i, j]: sol1) {
            if (i == j)loop1 = i,cont1++;
        }
        //assert(cont0<=1 && cont1<=1);
        
        
        if(loop1!=-1 && loop0==-1)dfs(dfs,loop1,1);
        if(loop0!=-1 && loop1==-1 && sol1.find(loop0^(1ll<<pos))!=sol1.end())dfs(dfs,loop0^(1ll<<pos),0);
        for (auto i: v1)if (sol1[i] != i)dfs(dfs, i, 1);
        
        
        if (loop0 != -1 && loop1 != -1) {
            //assert((loop0^(1<<pos))==loop1);
            //assert(col[loop1]==0);
            sol0[loop0] = loop1;
            sol1[loop1] = loop0;
            loop0 = -1;
            loop1 = -1;
        }
        
        for (auto [i, j]: sol1) {
            if (col[i] == 1) {
                if(i==j){
                    int a=i^(1ll<<pos);
                    int b=sol0[a];
                    
                    sol1[i]=b;
                    sol0[b]=i;
                    sol0[a]=a;
                    continue;
                }
                int a = i ^ (1ll << pos);
                int b = sol0[a];
                //assert(a!=b);
                
                sol1[i] = b;
                sol1[j] = a;
                sol0[a] = j;
                sol0[b] = i;
            }
        }
        
        
        for (auto [i, j]: sol0)res[i] = j;
        for (auto [i, j]: sol1)res[i] = j;
        
        int cont=0;
        for(auto [i,j] : res){
            if(i==j)cont++;
            //cout<<i<<" -> "<<j<<"\n";
            //assert(((i&((1ll<<(pos+1))-1))&(j&((1ll<<(pos+1))-1)))==0);
            
        }
        assert(cont<=1);
        
        return res;
    };    
    auto sol = solve(solve, 59, a);
    
    for (int i = 0; i < n; i++) {
        cout << sol[a[i]] << "\n";
        //assert((a[i]&sol[a[i]])==0);
    }
}

int main() {
    //ios::sync_with_stdio(false);
    
    if (const char *f = getenv("REDIRECT_STDOUT"); f) {
        freopen(f, "w", stdout);
    }
    
    srand(42);
    int T = 1;
#if TESTCASE
    cin >> T;
#endif
    
    for (int t = 1; t <= T; t++) {
        solve(t);
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
0
1
4
5
2
6

output:

4
6
0
2
5
1

result:

ok OK!

Test #2:

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

input:

272
315
138
126
6
394
297
44
273
84
200
9
197
396
133
16
46
65
87
86
336
316
174
140
162
250
306
52
188
57
36
63
192
320
388
10
156
15
208
38
32
31
228
30
305
234
384
220
142
72
27
337
110
94
317
304
242
398
209
5
323
29
284
301
309
244
230
261
61
254
266
194
296
275
313
80
206
214
88
308
18
288
106...

output:

196
309
129
313
116
86
210
238
168
55
310
58
114
90
199
208
318
384
297
47
194
337
307
285
4
141
267
66
390
218
256
62
151
122
244
98
112
46
209
287
288
283
224
142
277
87
35
305
182
292
174
145
160
2
206
261
49
38
314
148
290
226
146
138
10
280
242
386
257
132
316
215
204
6
303
304
265
135
11
236
3...

result:

ok OK!

Test #3:

score: 0
Accepted
time: 39ms
memory: 8112kb

input:

5134
36416
73248
85220
2072
16524
36385
101507
91137
17604
22
640
70530
66850
107792
81952
163
84260
46246
45090
101411
18824
66360
116881
400
50338
109824
17508
122881
98691
99843
36481
1696
102658
27008
2566
4
32900
103171
1153
104706
69923
82280
19616
66849
17540
36870
8352
117777
82156
6785
6780...

output:

70048
8256
264
67363
68960
70018
4896
35216
67880
69064
105763
35873
4237
18561
46214
106240
1224
16384
17540
21136
66660
57473
9472
125953
2116
16529
67976
6800
3112
18924
20496
104707
3745
99345
106497
62626
5667
3280
125200
1697
36480
133
70208
39554
45090
69537
54278
8358
36113
99618
25873
5158
...

result:

ok OK!

Test #4:

score: 0
Accepted
time: 1ms
memory: 3524kb

input:

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

output:

5
0
4
2
13
1
11
14
10
9
7
3
12
8
6

result:

ok OK!

Test #5:

score: 0
Accepted
time: 23ms
memory: 6912kb

input:

3237
9776
12036
8229
2100
10676
17349
26144
2690
30256
3088
27328
31796
3344
54
3637
16908
17030
31749
8593
153
20020
2305
24980
17413
1155
16524
1068
16576
2881
1139
10416
1924
17284
1042
16969
1066
28084
24608
29220
25125
19744
26117
128
28724
4760
17792
27008
17696
4372
6784
19157
8577
405
19072
...

output:

22533
16433
24080
30209
22017
10250
219
121
2053
25508
277
513
25285
4808
28672
10448
10561
560
19012
1122
12289
250
3616
11056
572
15920
10960
6712
24756
2184
17220
123
11312
6693
11652
24785
512
7701
3472
7184
540
2512
1136
3585
1123
14848
597
10900
28320
341
8480
16476
27200
9524
16532
8533
913
3...

result:

ok OK!

Test #6:

score: 0
Accepted
time: 1ms
memory: 3896kb

input:

32
21
10
13
29
15
30
14
0
26
19
18
2
8
25
5
23
17
12
24
3
4
22
20
27
6
9
1
28
7
16
11
31

output:

10
21
18
2
16
1
17
31
5
12
13
29
23
6
26
8
14
19
7
28
27
9
11
4
25
22
30
3
24
15
20
0

result:

ok OK!

Test #7:

score: 0
Accepted
time: 2ms
memory: 3936kb

input:

286
304
63
445
257
143
170
407
68
55
44
256
53
176
310
4
436
356
33
6
442
160
38
314
273
296
420
299
173
64
408
0
401
169
423
40
284
135
187
358
397
301
70
260
393
190
174
36
428
65
183
421
21
390
58
28
73
288
434
403
104
10
405
443
168
46
43
171
47
398
311
185
279
413
15
277
23
19
20
42
261
278
139...

output:

143
384
2
120
304
277
40
290
392
403
96
394
271
137
443
11
155
414
441
5
287
89
133
174
151
27
148
274
294
39
447
46
80
24
407
163
312
324
153
50
146
313
98
54
65
273
411
19
190
264
26
426
57
389
419
438
159
13
44
279
437
42
4
81
401
404
276
400
49
136
326
104
34
432
170
424
428
427
405
186
105
308
...

result:

ok OK!

Test #8:

score: 0
Accepted
time: 2ms
memory: 3972kb

input:

260
261
790
778
536
273
7
28
19
840
12
3
527
75
4
599
795
336
543
793
82
850
286
852
2
848
539
841
587
847
326
535
515
519
837
86
78
322
271
525
80
785
22
596
523
794
95
81
339
70
798
590
67
333
69
834
284
21
540
30
72
789
581
514
8
26
27
11
1024
594
770
257
348
279
861
331
73
600
264
277
577
6
345
...

output:

602
73
85
327
590
856
835
844
23
851
860
336
788
859
264
68
527
320
70
781
13
577
11
861
15
324
22
276
16
537
328
348
344
26
777
785
541
592
338
783
78
841
267
340
69
768
782
524
793
65
273
796
530
794
29
579
842
323
833
791
74
282
349
855
837
836
852
863
269
93
606
515
584
2
532
790
263
599
586
286...

result:

ok OK!

Test #9:

score: 0
Accepted
time: 1ms
memory: 3976kb

input:

128
240
194
178
243
2
131
163
32
112
225
153
129
97
82
25
158
140
144
134
66
69
65
98
24
13
26
192
157
160
3
49
211
196
6
133
14
33
5
12
139
99
176
28
179
83
138
11
150
19
155
224
137
208
15
4
154
113
143
147
135
18
81
34
149
73
136
23
76
209
30
197
146
27
17
80
48
227
145
168
152
68
0
50
1
51
29
20...

output:

15
29
65
0
241
40
80
159
143
18
6
114
158
161
134
97
83
99
25
157
146
178
145
135
210
197
51
66
77
168
142
12
9
153
72
177
204
154
211
20
144
67
227
76
140
21
148
73
200
68
31
22
42
240
201
5
130
112
96
24
225
162
209
10
150
23
136
179
34
193
26
69
132
226
163
195
28
98
3
7
155
243
205
242
192
194
1...

result:

ok OK!

Test #10:

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

input:

24
2
12
28
5
26
3
24
10
8
7
22
17
1
6
16
20
19
0
18
11
4
9
25
27

output:

25
18
3
10
1
28
7
5
19
24
9
6
26
17
0
11
8
16
12
20
27
22
2
4

result:

ok OK!

Test #11:

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

input:

1572
2144
58
3077
672
2376
2112
3978
1879
1170
557
2817
851
3975
2346
1814
1294
24
2602
1610
3457
606
1875
2818
2629
864
2156
1350
178
30
674
1547
2668
2948
1864
2432
2178
1310
176
2317
658
1057
587
2152
256
2927
1069
1282
1682
440
2208
2096
2850
1213
3076
3599
2607
1574
849
657
1188
578
676
1161
11...

output:

156
3205
858
1375
1559
1823
5
2088
2893
2370
1206
1164
8
581
105
2657
2151
1365
2341
526
1185
2060
1117
170
31
1923
537
3588
961
2125
2404
275
1081
23
625
120
705
2630
1618
1357
862
2340
660
2656
16
834
605
2408
1607
1887
1871
1101
2626
859
384
1360
2192
46
1358
792
2100
3083
2918
785
624
2913
900
2...

result:

ok OK!

Test #12:

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

input:

494
410
96
93
915
349
71
374
344
537
649
146
962
132
19
78
141
162
103
101
272
263
2
367
615
544
787
898
368
70
994
15
185
355
594
113
80
61
326
60
576
200
612
385
586
154
5
657
520
319
528
58
271
194
274
290
377
369
9
769
362
125
614
50
102
651
393
74
371
810
682
375
519
583
98
64
119
387
424
391
3...

output:

613
906
290
104
162
680
649
39
358
374
365
61
379
936
305
274
349
664
514
111
640
381
528
280
351
108
25
15
185
29
368
70
28
301
270
938
962
57
323
319
562
411
126
416
609
610
362
482
576
367
325
112
313
141
93
134
14
390
204
657
258
257
461
793
372
118
928
140
85
273
8
400
312
285
551
904
536
87
12...

result:

ok OK!

Test #13:

score: 0
Accepted
time: 2460ms
memory: 126156kb

input:

199969
8669248
1075841048
201328650
44042242
577154
1477480448
75844
406986886
1209534848
37758482
402981064
8462848
67126848
36160
35783200
268500996
25297024
203492360
138412736
1243643904
180232
570441730
272732160
67568128
52564512
570886432
34016
1225073920
536940936
1074372864
4556832
26850128...

output:

4269088
109117952
6295940
88080424
1076302080
100933648
33842
17826056
2135072
16959500
34078978
1145209888
1710464
411062274
71336978
1610786880
4984836
1610645664
67114032
831660032
407110658
335546512
738347008
33581058
4817920
204472832
2904320
1051140
18112514
134372864
1184512
218388488
800194...

result:

ok OK!

Test #14:

score: 0
Accepted
time: 2486ms
memory: 121088kb

input:

190281
53740576
202441232
536983640
1145053184
202703424
706479124
537213456
135726400
322181124
369160232
264208
16875750
536984090
604439104
254017728
538217476
672404500
12716036
1075089440
401830
310411820
1357398048
201721088
151389008
67162128
302098580
385933344
310487132
134481938
1144115456...

output:

1879087108
6337792
402915842
137483536
805353498
4329992
402686026
536871452
1610646560
8456916
205632768
4596480
402915392
152044848
538052144
1394610208
38404616
539038514
857738244
21070400
75984
537930368
1079111696
605094944
1215374592
8389224
8393804
1611661984
805417544
138421264
537071648
13...

result:

ok OK!

Test #15:

score: 0
Accepted
time: 2416ms
memory: 126528kb

input:

199998
344064132
2066
301989920
83886244
1744994560
84017920
704909320
1090847234
1354825984
19407360
42205408
436469796
67963392
34621480
35652096
100673568
34734336
285356032
136316320
536912388
50667520
9199616
2099392
2621792
285220880
1182088
1581074
50320
17111168
67747856
20987920
672661780
1...

output:

167772722
1476396580
1157628036
681574410
386146816
35919936
4210944
541065540
136855556
9472260
1142949912
1075839106
37929984
541204546
274268162
1074839616
17139200
202424320
1073777232
134431746
546471936
560009216
68158000
4341912
1207961088
557604
263560
5378050
188480
538316832
547881088
1073...

result:

ok OK!

Test #16:

score: -100
Runtime Error

input:

199984
4402408632320
9034687045437440
18155138279542816
2269533733650432
9077568067863552
45176733762093056
4503668347109380
68719501312
563500280252416
10133374039506944
567382359670784
4329570308
144255925568405504
848827271610432
288233124932880384
162411061562179648
108086700294537232
2199137340...

output:


result: