QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#330182#8077. Alice and BobKiharaToumaAC ✓839ms50196kbC++141.6kb2024-02-17 13:30:022024-02-17 13:30:03

Judging History

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

  • [2024-02-17 13:30:03]
  • 评测
  • 测评结果:AC
  • 用时:839ms
  • 内存:50196kb
  • [2024-02-17 13:30:02]
  • 提交

answer

//qoj8077
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e6 + 10;
int T, n, cnt[N], ps[N];
ll a[N], b[N];

ll clc(ll x){
    return x * (x-1) * (x-2) / 6;
}

int ch[N*64][2], siz[N*64], tt;
void ins(ll x){
    int p = 0;
    ++ siz[p];
    for(ll i = 0; i <= 62; ++ i){
        if(!ch[p][(x>>i)&1]){
            ch[p][(x>>i)&1] = ++ tt;
        }
        p = ch[p][(x>>i)&1];
        ++ siz[p];
    }
}
void qry(ll x, ll &ans){
    int p = 0, op = 1;
    ans += siz[p] * op;
    op *= -1;
    for(ll i = 0; i <= 62; ++ i){
        p = ch[p][(x>>i)&1];
        ans += siz[p] * op;
        op *= -1;
    }
}

int main(){
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        ll ans = clc(n);
        for(int i = 1; i <= n; ++ i){
            scanf("%lld", &a[i]);
            b[i] = a[i];
            ins(a[i]);
        }
        sort(b + 1, b + n + 1);
        int m = unique(b + 1, b + n + 1) - b - 1;
        for(int i = 1; i <= n; ++ i){
            ps[i] = lower_bound(b + 1, b + m + 1, a[i]) - b;
            ++ cnt[ps[i]];
        }
        for(int i = 1; i <= n; ++ i){
            int p = ps[i];
            if(cnt[p]){
                ll cc = cnt[p], dd = 0;
                cnt[p] = 0;
                qry(a[i], dd);
                ans -= dd * cc * (cc-1) / 2 + clc(cc);
            }
        }
        printf("%lld\n", ans);
        for(int i = 0; i <= tt; ++ i){
            ch[i][0] = ch[i][1] = siz[i] = 0;
        }
        for(int i = 0; i <= n; ++ i){
            cnt[i] = 0;
        }
        tt = 0;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12076kb

input:

3
4
2 0 2 3
3
2 2 3
3
0 2 3

output:

3
0
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 839ms
memory: 12060kb

input:

1000000
3
63 98 95
3
61 38 97
3
7 73 98
3
1 10 91
3
94 31 99
3
96 54 97
3
14 44 99
3
81 51 97
3
96 95 92
3
35 90 98
3
7 39 96
3
71 8 96
3
36 35 99
3
82 52 96
3
89 53 99
3
76 85 95
3
80 34 91
3
9 13 99
3
12 17 94
3
40 4 95
3
57 5 93
3
47 69 93
3
23 0 94
3
62 44 97
3
7 4 99
3
21 97 99
3
41 3 99
3
36 9...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 1000000 lines

Test #3:

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

input:

100
100
124984902967623755 124984902967623755 124984902967623755 124984902967623755 124984902967623755 701781449690403068 701781449690403068 701781449690403068 701781449690403068 977908122754831361 977908122754831361 977908122754831361 977908122754831361 977908122754831361 977908122754831361 9779081...

output:

107461
109751
153588
148116
161700
153167
152261
147129
154844
148422
136125
144245
120331
143949
150459
143152
150484
142034
152295
45020
154673
144755
11376
151352
147181
154487
152901
0
126850
152846
154609
87893
153158
136511
137776
145664
148716
143071
154503
152145
137939
148806
147587
150303
...

result:

ok 100 lines

Test #4:

score: 0
Accepted
time: 174ms
memory: 40816kb

input:

1113
500
769204668397077579 769204668397077579 769204668397077579 769204668397077579 995636665671483472 707686578767609936 707686578767609936 707686578767609936 707686578767609936 917930880083760145 917930880083760145 917930880083760145 917930880083760145 226122951868372052 226122951868372052 226122...

output:

19851032
895
20280315
631
574
150
765
1140
798
832
964
922
925
757
885
20486163
934
595
424
819
868
878
892
347
51
842
835
841
666
336
500
904
347
207
832
580
658
1140
688
781
850
730
576
886
20288370
0
892
20379355
859
704
772
779
838
162653189
20459989
0
880
689
934
861
910
19351276
0
436
1140
787...

result:

ok 1113 lines

Test #5:

score: 0
Accepted
time: 171ms
memory: 42828kb

input:

1113
20
226387647481511936 383163331085680645 383163331085680645 383163331085680645 383163331085680645 94933209478071316 94933209478071316 94933209478071316 918231256204066892 148839563663332351 148839563663332351 148839563663332351 148839563663332351 288511938102641684 288511938102641684 2885119381...

output:

823
949
516
940
249
694
859
880
853
676
20020312
576
694
676
584
853
754
180
576
20506117
798
686
811
877
877
757
775
710
781
627
0
20272126
827
884
891
810
1140
0
949
631
919
910
740
940
850
895
852
655
20355240
706
532
595
814
20058143
836
847
496
838
849
819
823
844
884
676
937
580
802
0
907
749
...

result:

ok 1113 lines

Test #6:

score: 0
Accepted
time: 161ms
memory: 42868kb

input:

1113
20
126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 126396674840466495 1263966...

output:

0
1045
886
724
0
910
192
736
859
835
860
892
898
823
799
952
216
634
496
631
925
0
724
853
961
874
916
20310675
19950672
576
937
656
944
0
819
859
835
572
847
631
814
495
853
582
865
871
216
761
256
606
576
922
0
0
520
631
934
20325576
694
0
0
180
416
20498228
895
20364391
718
826
955
778
658
898
76...

result:

ok 1113 lines

Test #7:

score: 0
Accepted
time: 447ms
memory: 12016kb

input:

277777
7
707459322718999568 707459322718999568 707459322718999568 707459322718999568 707459322718999568 707459322718999568 707459322718999568
8
531317697140506624 531317697140506624 531317697140506624 531317697140506624 531317697140506624 531317697140506624 531317697140506624 531317697140506624
7
97...

output:

0
0
20
0
4
0
0
0
0
17
25
0
0
0
56
0
9
0
0
56
0
0
0
45
4
0
0
0
0
18
27
34
0
29
20
0
0
0
19
0
24
1
0
0
24
20
0
0
0
4
4
0
4
0
0
0
0
26
0
3
0
30
0
0
56
0
25
0
42
27
0
0
0
0
4
0
0
0
4
0
0
18
19
0
17
0
4
30
0
0
27
0
0
0
0
48
0
0
15
4
0
0
0
0
30
45
0
18
0
0
0
15
0
0
27
20
0
0
15
0
17
0
0
21
0
18
0
0
20
56
...

result:

ok 277777 lines

Test #8:

score: 0
Accepted
time: 433ms
memory: 12052kb

input:

269964
7
707459322718999568 707459322718999568 707459322718999568 707459322718999568 707459322718999568 707459322718999568 707459322718999568
8
531317697140506624 531317697140506624 531317697140506624 531317697140506624 531317697140506624 531317697140506624 531317697140506624 531317697140506624
7
97...

output:

0
0
20
0
4
0
0
0
0
17
25
0
0
0
56
0
9
0
0
56
0
0
0
45
4
0
0
0
0
18
27
34
0
29
20
0
0
0
19
0
24
1
0
0
24
20
0
0
0
4
4
0
4
0
0
0
0
26
0
3
0
30
0
0
56
0
25
0
42
27
0
0
0
0
4
0
0
0
4
0
0
18
19
0
17
0
4
30
0
0
27
0
0
0
0
48
0
0
15
4
0
0
0
0
30
45
0
18
0
0
0
15
0
0
27
20
0
0
15
0
17
0
0
21
0
18
0
0
20
56
...

result:

ok 269964 lines

Test #9:

score: 0
Accepted
time: 446ms
memory: 12076kb

input:

269965
7
230614371974251604 230614371974251604 230614371974251604 230614371974251604 230614371974251604 230614371974251604 230614371974251604
3
536859150713357636 536859150713357636 441156301639193619
7
124970556636004427 124970556636004427 124970556636004427 124970556636004427 124970556636004427 12...

output:

0
0
0
0
0
4
42
0
12
0
0
1
0
45
0
0
42
0
0
0
30
0
0
0
0
0
0
0
56
0
0
0
0
17
0
0
0
0
0
0
12
12
0
3
3
24
0
0
0
42
25
0
1
0
0
0
0
0
18
0
0
0
0
0
15
27
0
4
3
0
17
0
0
0
0
0
0
0
0
0
0
0
0
0
14
1
0
0
0
0
0
18
27
0
0
0
0
0
0
0
21
0
17
0
0
0
26
0
0
0
0
0
0
30
0
4
4
12
1
0
0
21
0
0
0
0
3
1
0
0
0
0
0
4
0
27
0
...

result:

ok 269965 lines

Test #10:

score: 0
Accepted
time: 413ms
memory: 12636kb

input:

19580
98
532442205557641491 532442205557641491 532442205557641491 532442205557641491 532442205557641491 288235054533006661 288235054533006661 288235054533006661 288235054533006661 288235054533006661 288235054533006661 142985775232668922 142985775232668922 142985775232668922 142985775232668922 142985...

output:

136839
149391
154699
20317
97478
2696
3542
6997
18897
141447
13105
146045
115088
18
152160
66764
0
0
127352
63
138594
0
152173
44551
0
153902
1751
150058
81682
1640
0
59151
2060
152836
6994
41273
97624
13506
154541
892
107979
83856
150907
2494
0
89301
149883
0
151981
1422
108103
154349
149896
67730
...

result:

ok 19580 lines

Test #11:

score: 0
Accepted
time: 440ms
memory: 14192kb

input:

19581
100
764976963254243339 611779753208270860 611779753208270860 611779753208270860 616472540793361484 460366951686952020 460366951686952020 460366951686952020 460366951686952020 764613385670099004 764613385670099004 764613385670099004 764613385670099004 247571880840548624 247571880840548624 24757...

output:

152786
154637
150155
154940
126763
4743
153989
66911
120643
126327
196
123249
0
6426
68320
36123
146082
7578
147495
4432
152720
153734
154210
135376
36
154478
6240
6942
153727
147576
24801
142627
148807
153791
0
49431
0
62182
89257
13470
112569
52490
154133
153988
136930
149207
147214
0
117712
29811...

result:

ok 19581 lines

Test #12:

score: 0
Accepted
time: 348ms
memory: 50196kb

input:

113
98
292822280374932800 292822280374932800 293931705813778452 293931705813778452 293931705813778452 293931705813778452 293931705813778452 293931705813778452 293931705813778452 293931705813778452 293931705813778452 293931705813778452 293931705813778452 293931705813778452 293931705813778452 29393170...

output:

120041
73350
115067
148109
57855
15935
39648
124032
7696
142732
98297
13
109338
49
106241426462
96849
897
60076
70189972778
1427
40930
7700
166112106836
52892
116776
304
119806
115299
3110
58927
38136226084
700
124774
43728
206
70644
54316
39570
0
7441834300
0
80
0
26008
35453
32861
10629
0
6915
385...

result:

ok 113 lines

Test #13:

score: 0
Accepted
time: 279ms
memory: 42028kb

input:

90
3406
532424562553209088 158855933934257476 158855933934257476 158855933934257476 158855933934257476 782715729020470283 707669346552398929 288319712831477061 247514693620221263 247514693620221263 130530491746762814 842387340990879055 842387340990879055 153296734442554448 837791090267406655 8377910...

output:

6571367942
11726
166292869644
27
26954
28868
28736
2372
53734
165417925984
9146
166632009448480
0
60
27531
0
142222
51335
100925369590
76346
29109712247
6238
10275818834
10998
335
0
5764
51996271007
0
103460
13125
25615
0
41824
4281
27350
10814
29329734597
166330673153
8247657371
3849858883
18826157...

result:

ok 90 lines

Test #14:

score: 0
Accepted
time: 408ms
memory: 42504kb

input:

63
3370
922457482464597072 464039388170490879 464039388170490879 225349977749853507 463671340262293524 900274011071579216 900274011071579216 307744856415159361 307744856415159361 703236115670565964 613182476301435148 613182476301435148 613182476301435148 688248329052635212 842668473126573120 8426684...

output:

6367224179
9582
69594082093
0
166186252899
0
26950773803
114768
59941009202
99503564
2043
5199059656
3356
33573899
23283
9979
20831626068740078
166288445933
20711
5271382473
24449
20830452120748755
166316383674
166329198847
1363080174
78722583
166632349906996
5826
41348735293
0
526157446
88900470842...

result:

ok 63 lines

Test #15:

score: 0
Accepted
time: 338ms
memory: 44064kb

input:

56
10
630074613009813580 630074613009813580 630074613009813580 630074613009813580 630070128879621453 224983586954039571 172436823461351759 854966784809058315 244138107286409556 244138107286409556
77
311104896306774017 311104896306774017 379446981849842689 707669058572587073 707669058572587073 154329...

output:

88
67545
2688540916
19672614065
6751
55
3772
131024
14155
28237
78039
68737
88965
72819
122147545917
3676
4283
98824
26376
2353
8187
126004
0
40456955007
37726694236
6186
0
101455838361
7002
166330037724
146115823547
1667
85320
4285
18
20831632903226707
0
122543
21571524911
0
31994
5401
11240134209
...

result:

ok 56 lines

Test #16:

score: 0
Accepted
time: 384ms
memory: 43928kb

input:

57
37
535749739189960979 514406861548373252 842576109031736383 842576109031736383 842576109031736383 842576109031736383 842576109031736383 842576109031736383 842576109031736383 707761693432807741 707761693432807741 707761693432807741 707761693432807741 707761693432807741 19211788235314256 1921178823...

output:

6025
0
20831638130249234
20831631512426859
15
199
78656
152181
98678
15603512283
96409189
0
64970
75646
166327921171
87272
82133
1467
90187
80888
26866545690
141842
0
145665484
106040
145896
319
166632091953803
0
23476
166329981715
161299353463
165993021685
0
110699
287
78027
75269
123526
0
52540
79...

result:

ok 57 lines

Test #17:

score: 0
Accepted
time: 665ms
memory: 48632kb

input:

44
48
129680861313193295 53119448608413003 53119448608413003 53119448608413003 531229392692641808 537135964781036560 537135964781036560 537135964781036560 537135964781036560 537135964781036560 537135964781036560 537135964781036560 537135964781036560 537135964781036560 537135964781036560 537135964781...

output:

10558
60437
18989792160
103517
48
122852
0
30410
4336
22480
71773
20831632673297518
436
144467
166331158889
52587
31
3164
89026
165835468247
10569247187
162524786965
48496202430
20832558062262740
0
6916292574
89845
191003661
4222
22360
20831634138885646
85260483
23778
70662
128456
162230429
22121
12...

result:

ok 44 lines

Test #18:

score: 0
Accepted
time: 196ms
memory: 41716kb

input:

45
500000
124913378541507854 124913378541507854 124913378541507854 124913378541507854 154119238920781903 153226070486422788 153226070486422788 153226070486422788 153226070486422788 153226070486422788 153226070486422788 153226070486422788 153226070486422788 153226070486422788 153226070486422788 15322...

output:

20831632792066685
41121
47451
1507
2872570499
86
27025
1820615906
40652
14472
4494
81902
18957
0
166152234114
2304
13241352661
2512161557
2853
30813
74164
20054
14444
27
27639
24
8556
111472863425
3335038965
78779573669
48505683890
67859190149
24757
106181
56242
16047
8433886324
15411
78792
16892904...

result:

ok 45 lines

Test #19:

score: 0
Accepted
time: 650ms
memory: 47176kb

input:

31
26
73188992934219844 923864119700181056 311897363957761360 311897363957761360 23665889703445525 784030688001152272 918284098177421376 990077814066643264 990077814066643264 990077814066643264 990077814066643264 990077814066643264 153273697379095552 855880527022657600 855880527022657600 85588052702...

output:

2130
17448
35325
10689037581
590
166273093978
70958640548
143706269312
166027340204
0
7891
115444873997
52540
58317
41910991283
1491
46908
20831628381932131
153260
8585
7496
54712708344
142716152590
123313199953
115436
5058734812
20832558101516158
20831626942253027
149789421147
0
87745

result:

ok 31 lines

Test #20:

score: 0
Accepted
time: 30ms
memory: 16860kb

input:

32
50
379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396527276356 379503396...

output:

0
1971
484
42812
9964
56
90901
64527
8397
5380
0
110397
55641
20
5508
43504
57399
95027
19364942289
143608645067
17219
6607990598
128534
0
166329067259
26249
3020
39083
0
1250
73987
70731

result:

ok 32 lines

Test #21:

score: 0
Accepted
time: 409ms
memory: 42868kb

input:

49
69
158569700491592720 230609698835730451 918024612355314705 918024612355314705 918024612355314705 382823583065392389 157496577120539732 764978128581644540 764978128581644540 919062281894036812 919062281894036812 919062281894036812 312248178298863941 312248178298863941 312248178298863941 312248178...

output:

48469
127530056
262
178
17669
20831631650968240
32633
29453943615
2362
166314675889
38627
13152
164520613597
11480
58610
0
27670
1540
55419
0
4058
81877043522
60443898546
61
52
97086
14667397744
2056606
9628
132355
63960
139240
16
115238
4877
19586
584063219
15787
0
71232
166214817242
76746
125355
7...

result:

ok 49 lines

Test #22:

score: 0
Accepted
time: 334ms
memory: 48484kb

input:

50
17
859539636439811408 859539636439811408 859539636439811408 72362456256675921 379780388568973584 312156025124044816 860591951459733567 247589547299132735 172419148668818703 172419148668818703 172419148668818703 859188631294772236 513513031342249295 513513031342249295 994866168667067472 7657522049...

output:

569
166070665858
3241029553
1196857431
53563
39282032591
33602
46232
15016
7980
391
44552
0
26896
42789556572
36625975431
139288
33444
83751
1978
151692
88405681102
79337
102843
5101
20832558070045494
36207559212
148425
121795
5267495114
276
9
112317
59470
0
6250
4960
5488
0
84
1858
63140478413
4273...

result:

ok 50 lines

Test #23:

score: 0
Accepted
time: 407ms
memory: 42228kb

input:

98
82
75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 75361692648554570 753616...

output:

0
30962
135
31361
512
160383565763
107803
2329
372
28251
39290
70502938269
869
72962358
107836703
93986
6046740498
539116207
90481
1498
107156
37527
14487
3276
67161
1847942655
5151
25921
20254
525
42921865173
61209
166122343573
66210
5517
20831636130004066
0
64032309783
102342
166325991568
11886
60...

result:

ok 98 lines

Extra Test:

score: 0
Extra Test Passed