QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643571#7749. A Simple MST Problemlichenyu_acWA 18ms31508kbC++141.7kb2024-10-15 21:51:322024-10-15 21:51:33

Judging History

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

  • [2024-10-15 21:51:33]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:31508kb
  • [2024-10-15 21:51:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;

int p[N],top,v[N],w[N],s[N],g[N];

void primes(int n=N-1){
    g[1]=1;
    for(int i=2;i<=n;i++){
        s[i]=s[i-1];
        if(!v[i])v[i]=p[++top]=i,s[i]++,w[i]=1,g[i]=i;
        for(int j=1;j<=top;j++){
            if(p[j]>v[i]||p[j]>n/i)break;
            v[i*p[j]]=p[j];
            if(i%p[j]==0)w[i*p[j]]=w[i],g[i*p[j]]=g[i];
            else w[i*p[j]]=w[i]+1,g[i*p[j]]=g[i]*p[j];
        }
    }
}

int calc(int x,int y){
    return w[x]+w[y]-w[__gcd(x,y)];
}

bool vis[N];
int dis[N],b[N];
int prim(int l,int r){
    int ret=0;
    for(int i=l;i<=r;i++)vis[i]=0;
    vis[l]=1;
    for(int i=l;i<=r;i++)dis[i]=calc(l,i);
    for(int j=l;j<r;j++){
        int x=0,ans=0x3f3f3f3f;
        for(int i=l;i<=r;i++)
            if(!vis[i]&&dis[i]<ans)x=i,ans=dis[i];
        vis[x]=1,ret+=ans;
        for(int i=l;i<=r;i++)
            if(!vis[i])dis[i]=min(dis[i],calc(x,i));
    }
    return ret;
}

void solve(){
    int l,r,ans=0;
    scanf("%d%d",&l,&r);
    if(l==r){
        puts("0");
        return;
    }
    if(l==1){
        for(int i=2;i<=r;i++)ans+=w[i];
        printf("%d\n",ans);
        return;
    }
    else if(s[r]==s[l-1]){
        printf("%d\n",calc(l,r));
        return;
    }
    for(int i=1;i<=r;i++)b[i]=0;
    for(int i=l;i<=r;i++)b[g[i]]++;
    for(int i=1;i<=r;i++){
        if(b[i])ans+=(b[i]-1)*w[i];
    }
    for(int i=1;i<=r;i++)
        if(b[i])
            for(int j=i*2;j<=r;j+=i)
                if(b[j])ans+=w[j],b[j]=0;
    for(int i=1;i<=r;i++)
        if(b[i])ans+=w[i]+1;
    printf("%d\n",ans-2);
}

int main(){
    primes(1e6);
    int T;scanf("%d",&T);
    while(T--)solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 10ms
memory: 25412kb

input:

5
1 1
4 5
1 4
1 9
19 810

output:

0
2
3
9
1812

result:

ok 5 lines

Test #2:

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

input:

2
27 30
183704 252609

output:

8
223092

result:

ok 2 lines

Test #3:

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

input:

1
183704 252609

output:

223092

result:

ok single line: '223092'

Test #4:

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

input:

2
639898 942309
30927 34660

output:

983228
11512

result:

ok 2 lines

Test #5:

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

input:

3
21731 33468
46192 370315
1712 3753

output:

34608
948775
5299

result:

ok 3 lines

Test #6:

score: 0
Accepted
time: 4ms
memory: 27452kb

input:

4
15237 67700
10918 86104
98287 116980
17432 23592

output:

148811
210927
60893
18687

result:

ok 4 lines

Test #7:

score: 0
Accepted
time: 16ms
memory: 29416kb

input:

5
5594 70302
19202 69588
5634 7877
59821 469300
97439 261121

output:

179735
145706
6565
1203684
488669

result:

ok 5 lines

Test #8:

score: 0
Accepted
time: 18ms
memory: 27356kb

input:

6
43477 229639
188276 269887
72424 150178
9009 36918
137421 180271
14666 124530

output:

541705
255651
232054
77284
135277
313203

result:

ok 6 lines

Test #9:

score: 0
Accepted
time: 12ms
memory: 26928kb

input:

7
461436 501798
98856 148334
20953 119408
910 5027
762 14117
10959 46088
96149 130311

output:

139017
151124
281536
10504
34818
98004
108375

result:

ok 7 lines

Test #10:

score: 0
Accepted
time: 15ms
memory: 28248kb

input:

8
6448 11162
33691 94044
137536 140277
106719 267437
13494 38185
3185 4173
4835 299526
25162 43201

output:

13177
175485
9711
480992
69059
2808
840950
53422

result:

ok 8 lines

Test #11:

score: 0
Accepted
time: 14ms
memory: 29752kb

input:

9
4136 54985
38425 155322
107602 157683
115533 137627
13677 44903
43432 69310
70004 129314
43033 55373
76424 147123

output:

139668
339337
153266
68520
87592
76612
183238
39109
211339

result:

ok 9 lines

Test #12:

score: 0
Accepted
time: 15ms
memory: 27420kb

input:

10
21662 27103
55634 196143
20466 44902
87028 202799
127745 151602
1598 1679
95299 126981
13367 134183
52307 66285
10136 38071

output:

17117
410126
71979
344673
74754
263
100586
342577
41870
77522

result:

ok 10 lines

Test #13:

score: 0
Accepted
time: 18ms
memory: 26888kb

input:

20
14973 29525
12674 35281
27500 64458
67431 109122
12468 19466
4606 9884
38731 44161
3212 89277
23213 37134
4392 40769
5378 7211
22586 29237
56331 81369
43924 59554
31787 34990
19949 21972
47309 65085
5666 48185
99 2714
7969 131566

output:

40882
63073
107649
129480
19975
14563
17562
238237
41056
99346
5358
20747
73854
48244
9911
6517
54866
117382
6374
347901

result:

ok 20 lines

Test #14:

score: 0
Accepted
time: 15ms
memory: 28344kb

input:

30
11101 53557
6079 6241
869 14433
6164 10602
73432 82272
15845 17496
18885 49518
12127 35037
5812 14898
12225 15757
19736 36027
34506 69210
12204 37099
642 1256
11875 12382
169453 211949
20884 26173
8302 26634
75302 79147
13938 16896
11229 13736
4753 7575
2742 17752
4443 5021
2988 5533
1042 1364
19...

output:

118619
538
35473
12392
28768
4915
88426
63728
25217
10666
47893
102086
69488
1584
1669
135374
16581
50701
12720
8517
7762
8170
40235
1798
7014
936
78143
29
32461
19423

result:

ok 30 lines

Test #15:

score: 0
Accepted
time: 17ms
memory: 24932kb

input:

40
1022 1378
14032 55415
12506 15792
3919 16767
12870 32763
10624 12091
1144 29449
5184 9133
4178 8021
7785 13966
3880 26749
15390 34240
2582 11246
431 4695
7020 28894
14092 27156
52666 55295
4068 22068
7392 11533
18273 31481
18854 47481
7786 39812
7341 24968
22021 54790
3221 10332
4930 37633
4407 1...

output:

959
116367
9946
34920
55460
4626
75707
10961
11069
17829
62128
52987
23362
10769
60198
36594
9093
48818
11976
39528
82591
88609
48598
96601
19475
89551
19435
27135
16967
139445
1063
181709
57729
6335
4114
5586
5189
5669
59793
8451

result:

ok 40 lines

Test #16:

score: 0
Accepted
time: 12ms
memory: 27396kb

input:

50
15626 23807
5585 6016
6101 8103
9127 21310
36189 45079
14069 28358
4793 6034
4029 8938
35309 95923
43860 65991
3472 11896
13230 36032
11979 20636
2432 24320
1680 8915
2612 5242
9797 10319
2232 9531
24754 30470
41799 71066
9681 10551
434 2733
8898 28848
2033 35179
8338 13387
1547 5093
1840 3757
47...

output:

23466
1386
5889
33690
28343
40048
3754
13493
176378
65680
23137
63701
24080
59083
18974
7221
1739
19409
17905
86553
2807
5709
55079
89488
15241
9203
4985
12067
5112
815
36773
6032
21936
48301
14796
43205
40728
1000
10389
346
16233
134
5168
54990
5999
25607
7930
9444
25040
30739

result:

ok 50 lines

Test #17:

score: 0
Accepted
time: 15ms
memory: 27476kb

input:

60
1284 4788
3389 36000
222 7286
25716 33186
38085 40233
3531 6181
774 2555
2653 3785
1441 2911
5474 6951
7325 8378
623 1484
3626 29205
863 14748
49190 61921
2406 35177
7742 9801
200 1071
5199 13189
7551 9135
25991 50726
17330 21478
46 97
1580 6205
7679 16145
7074 19995
17354 41321
7546 9420
3186 71...

output:

9024
88511
17924
22330
7191
7459
4538
3287
3846
4320
3130
2162
69268
36338
39569
88635
5995
2088
22192
4684
73244
12692
112
12062
23979
35542
68915
5472
10740
464
301
171
1183
29157
16502
38047
16131
3142
4940
51225
10426
4988
20823
38873
1185
31126
665
11014
128
9270
4447
12193
22928
10020
521
5876...

result:

ok 60 lines

Test #18:

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

input:

70
2967 4866
39014 52178
4501 9931
2868 17671
18883 24548
44427 53286
9239 37925
1019 1411
234 3511
4974 11964
3336 7079
2397 2807
1482 5860
845 967
47 3347
22581 38595
618 9784
1987 6683
1970 10280
13073 16008
12155 23980
26996 33533
1211 2524
116 3464
292 360
342 432
10396 22134
21754 66962
10977 ...

output:

5260
41323
14979
39729
17180
28404
79481
1059
8102
19420
10197
1225
11392
373
8086
47200
23657
12336
21966
8903
32960
19601
3385
8239
193
250
32568
131030
41881
26631
57583
18937
22825
27887
7666
45760
37714
4084
1599
7021
13489
3750
22270
13773
686
10747
2711
1325
15075
206
12399
28434
14321
5809
1...

result:

ok 70 lines

Test #19:

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

input:

80
227 762
1864 11313
3710 6984
9210 16876
2146 5715
12841 17952
540 3928
2471 3084
1297 10323
1336 4968
2550 2572
33143 35415
821 1994
1397 14292
6850 16209
9375 15494
829 4086
6431 26191
20951 28745
3738 19999
101 4288
2971 5562
809 1230
21199 26540
181 386
11348 11762
2783 5152
17773 39328
2469 3...

output:

1273
25013
8944
21618
9356
14607
8548
1852
23539
9384
74
7598
3126
34097
26366
18382
8268
54251
24042
43950
10390
7142
1132
16776
486
1397
6513
61971
2251
2716
119
10648
11149
14387
88616
48016
3101
13598
42354
15386
761
11212
11013
15564
4022
23786
18860
39658
2971
20321
9970
65802
3429
2772
19206
...

result:

ok 80 lines

Test #20:

score: 0
Accepted
time: 15ms
memory: 26444kb

input:

90
1834 3251
1286 4017
968 8098
991 1889
4679 9273
47 2565
404 3201
1698 5864
1568 3560
2090 4761
5519 20863
952 1123
6765 7477
1881 12407
22889 32445
1149 1341
5532 20827
2641 11993
4531 5449
1440 16324
2378 29912
10725 14148
913 1665
3757 3940
2607 6438
663 1609
1134 19991
7011 7315
3043 4479
1183...

output:

3678
7004
18415
2406
12675
6103
6973
10872
5155
7008
41935
469
2265
27853
29404
566
41797
25248
2792
39305
74142
10472
2013
597
10541
2425
49947
1026
3977
1732
21450
11809
1816
1175
21684
176
24632
13337
2393
3679
145481
1240
1203
34363
15259
26644
14236
8201
5876
432
18294
211
1018
2099
28005
33979...

result:

ok 90 lines

Test #21:

score: 0
Accepted
time: 17ms
memory: 27684kb

input:

100
2851 7328
280 359
20953 49433
106 1188
195 208
5208 9395
8380 12027
8091 11163
3161 7447
215 3448
2022 7980
4069 7320
2838 3679
15 231
1888 14353
10452 12414
4 1185
789 1675
19521 23307
301 2895
6831 30967
33555 35031
483 2712
4746 21571
4294 13075
13819 13959
5986 15296
9258 9513
331 6202
2467 ...

output:

12003
221
83960
2553
41
11627
11086
8930
11682
7983
15657
8920
2482
466
33116
6113
2741
2360
11587
6407
66138
4987
5539
45716
24197
479
25858
866
14840
7126
11092
15742
1357
59273
7251
95126
5877
9720
19666
59359
3213
5286
7653
2305
8616
3020
718
7748
3928
6874
27620
0
23370
10227
7369
4750
59084
55...

result:

ok 100 lines

Test #22:

score: -100
Wrong Answer
time: 13ms
memory: 24588kb

input:

500
2771 3702
817 1288
1215 5937
453 1488
3267 3321
2058 2466
703 825
9 97
1251 2046
234 1684
4778 7026
2763 5165
11 32
620 1738
367 1281
2469 5782
650 5733
138 479
1879 3268
124 1307
2795 3892
2069 3176
6336 7230
1176 2018
324 1422
1596 3589
680 1487
1904 2126
16 27
620 1118
52 215
4143 4516
511 62...

output:

2723
1266
12164
2574
187
1172
345
180
2286
3513
6500
6601
42
2812
2276
9095
12945
805
3613
2825
3197
3054
2672
2410
2667
5162
2069
630
22
1255
361
1194
295
7685
7555
1503
94
247
4141
6957
4296
558
20
8633
8501
5076
464
5344
13145
3032
2471
3
3203
1477
353
1084
4158
3948
755
4821
15
6213
2893
69
7032...

result:

wrong answer 124th lines differ - expected: '10', found: '5'