QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#721213#7839. 虹KnownError_100 ✓2693ms796664kbC++143.2kb2024-11-07 15:35:092024-11-07 15:35:09

Judging History

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

  • [2024-11-07 15:35:09]
  • 评测
  • 测评结果:100
  • 用时:2693ms
  • 内存:796664kb
  • [2024-11-07 15:35:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ui = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,l,r) for(int i=(l);i>=(r);--i)
#define repn(i,n) for(int i=0;i<(n);++i)
#define sizc(x) ((int)(x).size())
#define allc(x) (x).begin(),(x).end()
#define fir first
#define sec second

constexpr int N = 8e4+5, B = 300;

int n,m;
vector<int> G[N];

namespace Sieve{
    bitset<N> vis;
    vector<int> primes;
    void init(){
        rep(i,2,n)if(!vis[i]){
            primes.push_back(i);
            rep(j,2,n/i)vis[i*j]=1;
        }
    }
}
using Sieve::primes;

bitset<N> D[N],S,z,Z;
int g[N];

int f[N];
void dfs(int u,int fa){
    f[u]=fa;
    for(auto v:G[u])if(v!=fa)dfs(v,u);
}
vector<pair<int,int>> Q1[B],Q2[B];

vector<int> Q3[N];
pair<int,int> rg[N];

void dfsu(int x,int val){
    if(x==primes.size()||(ll)val*primes[x]>n){
        for(auto id:Q3[val])D[id]&=Z;
        return;
    }
    dfsu(x+1,val);
    int mul=1;
    while((ll)val*primes[x]<=n){
        val*=primes[x];
        mul*=primes[x];
        for(int i=mul;i<=n;i+=mul){
            g[i]*=primes[x];
            Z[i]=z[g[i]];
        }
        dfsu(x+1,val);
    }
    for(int i=primes[x];i<=n;i+=primes[x]){
        while(g[i]%primes[x]==0)g[i]/=primes[x];
        Z[i]=z[g[i]];
    }
}

signed main(){
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

    cin>>n>>m;
    rep(i,1,n){
        int x;cin>>x;
        z[i]=x&1;
    }
    rep(i,2,n){
        int u,v;cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    Sieve::init();
    rep(i,1,m){
        int op,l,r;
        cin>>op>>l>>r;
        if(op==1){
            int bl=(l-1)/B+1,br=(r-1)/B+1;
            if(bl==br){
                dfs(l,0),D[i][l]=1;
                rep(j,l+1,r){
                    int p=j;
                    while(!D[i][p])D[i][p]=1,p=f[p];
                }
                continue;
            }
            Q1[bl].emplace_back(l,i);
            Q2[bl].emplace_back(r,i);
        }
        else{
            int u;cin>>u;
            rg[i]={l,r};
            Q3[u].push_back(i);
        }
    }
    rep(i,1,(n-1)/B){
        int u=i*B;
        dfs(u,0);
        S.reset(),S[u]=1;
        int it=u;
        sort(allc(Q1[i]),greater<pair<int,int>>());
        sort(allc(Q2[i]));
        for(auto p:Q1[i]){
            while(it>p.fir){
                --it;
                int x=it;
                while(!S[x])S[x]=1,x=f[x];
            }
            D[p.sec]=S;
        }
        S.reset(),S[u]=1;
        it=u;
        for(auto p:Q2[i]){
            while(it<p.fir){
                ++it;
                int x=it;
                while(!S[x])S[x]=1,x=f[x];
            }
            D[p.sec]|=S;
        }
    }
    rep(i,1,m)D[i]^=D[i-1];
    rep(i,1,n)Z[i]=z[g[i]=1];
    dfsu(0,1);
    rep(i,1,m)if(rg[i].fir){
        int l,r;tie(l,r)=rg[i];
        D[i]>>=l;
        int s=D[i].count()-(D[i]>>r-l+1).count();
        cout<<(r-l+1+19901990ll*s)%20242024<<'\n';
    }
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 4ms
memory: 19416kb

input:

998 1000
955556485 952505211 899166521 258704448 894183248 636280051 62949347 983956660 113872828 588367167 208142006 665025449 944228063 284736189 169202015 56096447 404419923 30158095 111191865 717455344 790159420 391379127 208279658 426780799 886604643 940903663 618716147 773652834 385881251 1593...

output:

16521790
13341944
16841705
2220375
880451
3621051
12662029
6300750
3240463
2400556
6501168
3580517
9221391
8381420
12982211
8001004
9361122
17262479
3600913
10401408
16202143
15022309
16341874
7861442
1560390
8340899
12421304
13961591
10421679
12101636
17361912
11781615
4780673
13641787
20102392
171...

result:

ok 490 lines

Test #2:

score: 10
Accepted
time: 9ms
memory: 20092kb

input:

1000 997
103470799 773962597 977631665 55926526 616833039 263471628 825848455 638144717 340710593 68036397 623497249 808915869 345157828 256095693 400262335 173843004 238983751 646376872 243739767 221162275 465477137 772061029 840064611 274062983 522264159 689460088 20129595 287189331 622217799 6948...

output:

13621441
17282360
11241382
15841876
17222347
1880319
12441746
10381083
18222171
7341024
10081427
2900456
2900406
13801602
17521768
19901997
8521022
13281468
2400503
17201967
19942477
14461494
19742168
14461471
12121799
2600806
18902095
1941004
19901993
10221200
8901579
9201080
19442423
720422
130019...

result:

ok 527 lines

Test #3:

score: 10
Accepted
time: 7ms
memory: 19996kb

input:

1000 1000
1697351 841785432 606301324 899151762 398181773 419939453 419455373 826820357 965555426 240847697 718049384 378823565 364137136 867089279 445499605 934770217 134914678 642584637 766848023 203338778 153291975 240768524 446186401 462123008 408740063 755064293 274502953 646610365 27815415 164...

output:

368
198
7021295
16001721
18602311
8021119
17201976
1380573
13141934
3580444
14641604
16681966
3240524
16182225
7541265
8520964
6341385
18922654
17861873
13781440
11581327
14342249
3600640
6821000
16841702
860350
16501686
3420674
18881910
6161028
17022054
3920543
4600572
6300810
3761005
11401360
8181...

result:

ok 502 lines

Subtask #2:

score: 20
Accepted

Test #4:

score: 20
Accepted
time: 1790ms
memory: 654092kb

input:

65531 65535
968854923 932574892 192297572 866236747 654755663 148562561 273214896 947434573 938626677 992982166 219888853 229840279 676071061 383387319 372883953 729287797 601010887 31942080 990584163 823724544 181337075 918252129 896876911 768539961 357780649 890577681 819641335 320266037 55445939 ...

output:

2662122
12263904
9988949
9098885
10661570
169420
12206075
11189204
12737561
19687277
3177635
12864425
16522132
8890301
19817862
19631288
14433359
4841805
15087340
13737927

result:

ok 20 lines

Test #5:

score: 20
Accepted
time: 1789ms
memory: 653748kb

input:

65534 65536
820462503 674023407 678774031 936839760 967886021 931679487 453790312 457688550 70497701 344893727 154301715 507005683 73026386 390834155 323019588 839428562 139619227 778200763 402648418 434214668 203135761 709945633 736891475 834231887 757898689 714927300 773615727 495008913 178272181 ...

output:

3556992
16638524
17773272
4500556
15023833
15616791
16530231
2941967
3166188
12186952
18098140
476862
4445062
9237154
8863687
143980
14070479
6047549
7425512

result:

ok 19 lines

Test #6:

score: 20
Accepted
time: 1830ms
memory: 653772kb

input:

65536 65536
405634173 17394581 118925347 922474073 743773645 237837181 499268357 244246848 939786401 792695975 628358275 678027475 348815741 419958879 726832416 24340945 901834373 56505761 405488783 771756785 890119785 252669240 492790889 529308875 31501425 546890993 105451499 269507525 583855527 42...

output:

14813680
12244780
5372831
129044
15936400
19557428
17514428
4965101
11035792
17705809
19062063
9585446
1382379
17154907
17605748
17161957
6292833
16315460
11100885
4587223

result:

ok 20 lines

Subtask #3:

score: 20
Accepted

Dependency #2:

100%
Accepted

Test #7:

score: 20
Accepted
time: 1705ms
memory: 653880kb

input:

65536 65533
30932122 78382923 537901462 43608430 743690928 918369886 474585919 91526068 574096807 937639556 275209310 841686338 356806157 792932071 603518094 832348491 468678335 713509816 101484129 852321989 436384847 445099357 227895189 501297162 399636691 271485365 207312863 509602081 865283531 19...

output:

1496564
9125549
16577986
6310026
1063976
16707
52957
14908581
14790251
14722135
13755277
11137460
5968935
8549164
18541922
24957
1930126
16330833
14364850
2239625
10619499
16538
6589616
2426893
19692596
19164930
15643210
18580925
12236638
6881655
2537792
9181
5316249
16956425
5578816
5938013
7323269...

result:

ok 45533 lines

Test #8:

score: 20
Accepted
time: 1807ms
memory: 654028kb

input:

65536 65535
896327463 680912869 425088586 463001926 222746654 139797223 797862825 191243957 970951057 833986727 442405892 825555128 314556958 914737211 212060430 912767901 453296903 873665049 564716803 471005323 213780115 573452539 543739081 881018559 902197811 297810647 51022403 757374500 594296052...

output:

3765898
7160189
1840871
8384498
12162436
17733710
213192
867756
9465798
5355255
9688576
14003307
3802366
3494697
2813852
18250238
14202178
3534428
4309535
12426295
20119652
19552024
19554541
276659
9217790
4968412
4966695
8795674
14327484
5321111
5143428
4804826
14976742
1065939
6768277
11126616
392...

result:

ok 25535 lines

Test #9:

score: 20
Accepted
time: 1625ms
memory: 653996kb

input:

65536 65536
273612167 315772190 71207511 736212317 523695534 424195293 720590001 84825693 594307129 913990193 946510345 222887460 962253802 124933747 293256949 752514778 915822505 86321273 339054171 563974341 489916343 956984316 111089551 70521376 292460752 45000461 214783067 288398507 49055118 1032...

output:

8409099
627948
11730380
8939261
10928253
17059110
6990391
13342784
4902327
5950655
16232329
8204509
19093841
4451012
18709415
3229726
10846229
5082475
17190005
14833410
5282247
2331065
10279617
4557434
7700054
8071957
10999644
1165013
95904
113129
12805875
15919700
10967571
3128343
12049502
18201862...

result:

ok 55536 lines

Subtask #4:

score: 30
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #10:

score: 30
Accepted
time: 1696ms
memory: 654216kb

input:

65536 65536
690710135 657115917 211163039 197295969 367013816 156855111 797052165 886430858 508869157 17134147 61796741 347521885 250213399 668920827 220381843 208336869 792057463 245539955 861408575 952059033 360332858 249610287 456737865 567698963 120715589 263131517 574343202 122801665 999840299 ...

output:

8040100
3021434
9107120
13724129
19834787
14940549
6403684
523398
5240085
12839771
3633093
11132658
20077338
11562974
4875599
14609248
9659750
16422583
8666268
18202469
9564561
15213093
11526145
19105135
5273205
14674017
13442536
3940980
11196942
12398974
4242874
17444381
10527254
7117230
7801758
84...

result:

ok 32817 lines

Test #11:

score: 30
Accepted
time: 1645ms
memory: 654432kb

input:

65536 65536
170304261 71878445 697047463 26536118 288496955 296519416 798352076 455901935 112317553 316596485 118780647 983962473 147855782 547028521 787615861 195975475 707627127 396956425 88941067 567087327 710386346 98438291 66729629 279815862 826118743 223108495 928573999 931742906 643699659 746...

output:

26156
23416
44529
18790437
179412
5345034
19864608
17193359
1683682
1101789
17202182
3942854
19699539
17312852
17869402
10804850
19613278
1205247
17596278
1441167
12820276
9278420
6946809
4827331
17854429
16854274
7013401
15197353
7634324
6573386
10812965
15740317
12416100
14805172
8791862
3555911
9...

result:

ok 54616 lines

Test #12:

score: 30
Accepted
time: 1825ms
memory: 652576kb

input:

65534 65536
418820062 329896341 692391895 395362428 157193467 129138716 640964346 56172381 600587925 363136405 238370903 160128513 51235613 595121292 416717709 911948685 369399841 324706983 564913713 142006521 995220829 569218724 960953803 110442236 988689878 329122927 579650897 494130281 805483377 ...

output:

3722534
1642037
9000155
26797
18260516
10141151
5996188
11901875
647641
10326901
3849463
602819
7461708
4343389
17664484
14508412
9241911
3121606
19839193
11299183
8386787
16550463
12550737
19282100
4112538
1119285
6373193
4966374
15020078
14303001
5617046
12265071
5530990
10673373
6236623
19571786
...

result:

ok 11161 lines

Test #13:

score: 30
Accepted
time: 1499ms
memory: 654452kb

input:

65535 65536
40159670 616546517 635130937 77466737 659136612 932097848 379284085 520067901 644270537 520589915 334168227 587475447 428153433 654877316 858838608 415007221 904452303 468994015 92514149 443749003 804933427 233837837 917210605 742865247 172477723 256829127 955032199 218062404 156945304 3...

output:

4012
5004225
18430554
3269256
8444471
16539477
8812413
2939774
20334
18636194
998
11368250
9047594
3334145
14142232
19923541
17860027
4322674
3460905
6286005
16367286
3866104
19582855
16842599
2606835
13525740
9097458
11249615
20312
12361947
8362814
14378671
1687058
9988709
6046604
1003937
16605
137...

result:

ok 32813 lines

Test #14:

score: 30
Accepted
time: 2293ms
memory: 655524kb

input:

65535 65536
282726917 194315094 983494371 997843378 434298909 899659941 494211327 973321579 742895953 226060139 337435275 554934675 7189175 241187709 796709538 92708973 342166395 453751106 373939199 40714295 78999882 8885357 287039037 979321771 124201556 310605183 317016708 996799011 921717869 53692...

output:

16953
13209
177
10825744
30571
17726724
11265362
18429393
4375308
17352613
5480947
12386497
14554025
5733475
5562660
14236964
10039934
15761002
13542015
19256578
806936
1584266
8229552
3958243
15412478
8546981
2182278
9691184
18870420
7753928
7324840
8673769
5524414
13100958
19424461
4554734
1654576...

result:

ok 32656 lines

Subtask #5:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #15:

score: 20
Accepted
time: 2313ms
memory: 795424kb

input:

79999 79996
635394353 806780511 826597371 793762079 333138314 429096159 401894869 625722149 616526293 367571207 711713149 597366281 666979179 244748289 564660251 985817954 246396913 425479439 995583415 850880133 47931612 775966469 941900917 207077751 257486961 877578787 53990419 484584707 923646540 ...

output:

29937
1910
16830515
141512
14313981
6068327
13233150
12747739
11125779
4187083
8092951
9155432
10499223
6136617
13028827
2622655
1231814
11082105
14675789
6442229
18388790
17709422
8825438
14739801
7287870
19857977
9539588
10827879
11224843
8961140
18382324
19466400
8331588
16823579
383399
3900868
1...

result:

ok 40096 lines

Test #16:

score: 20
Accepted
time: 2444ms
memory: 795352kb

input:

79998 79999
608035833 149278714 290869512 991618649 451971119 974701573 181943435 344458834 627923214 382919143 508808203 111862226 35754921 885058650 530953550 45952737 629847463 640317358 318872628 860836707 292340265 133012941 238508349 347870703 177823619 577767736 914920793 930293605 283499148 ...

output:

5885923
17576214
2167564
15582449
7788481
2219448
14858236
15755520
5382526
5314607
4052334
16001822
3626340
18021589
11845386
5847998
17062126
19659913
19424762
5121351
15267491
1813420
5949567
3162466
6084055
5205866
11401181
10897958
19750634
5028699
1692067
16047192
2724868
10727973
7369422
6665...

result:

ok 8904 lines

Test #17:

score: 20
Accepted
time: 2219ms
memory: 795468kb

input:

80000 80000
620891279 314795903 843880649 65086746 120446681 548948399 480807963 6685633 229258305 99985531 976659026 187591336 487780589 68869183 520113483 579568547 17909785 920271485 932516785 926606319 932035361 917385743 593992325 162667837 684536933 664104427 351611569 122422039 377593479 8633...

output:

44198
3544
4890
4117
41678
9578
14461
32587
667
20753
5151
14359
71169
15142
23637
40570
71527
7776
11479
69956
14686442
9684357
4444878
12702546
14693596
12545794
7386314
3322278
19566490
15754163
14677478
6847938
16493120
8610996
592245
408155
4141943
4921488
3024224
6645554
9091672
16435684
18037...

result:

ok 68613 lines

Test #18:

score: 20
Accepted
time: 1850ms
memory: 795288kb

input:

79999 80000
91783769 450826957 248644981 2675243 967851313 723278977 195366587 961567794 714461297 708977345 347748673 89614657 638796360 642806175 427800287 614118479 482476163 225735577 808069831 771141445 256198415 799182884 852605327 178454179 614787258 470097513 589706543 602634407 440272857 25...

output:

78977
79661
79261
78950
79534
78914
79080
79061
79041
79416
78730
79222
79162
78675
78666
79254
79281
78321
79747
79655
79192
79136
78751
79126
78812
79143
78750
79381
79572
79552
79165
78515
79632
79660
79065
78459
79926
79767
79693
79663
78688
78896
79342
79258
78987
78965
79920
78802
79071
78498
...

result:

ok 80000 lines

Test #19:

score: 20
Accepted
time: 1862ms
memory: 795432kb

input:

79999 80000
682743924 614832237 899869835 540431151 822786317 227945133 935983411 989231359 721490075 628101733 524189189 689132165 928325490 212442524 320218045 312739603 206920221 507339380 546897299 483226477 530685639 824134755 83443741 822814147 968776935 244416033 132524577 752446425 299256219...

output:

79206
78399
79154
79089
79794
79582
79229
78896
78901
79529
79383
79177
79344
79153
79188
78771
78840
79185
78476
79474
79230
78750
79415
79026
78980
79529
79195
78798
79102
79614
78992
78735
78861
79606
79399
78942
79020
78759
79400
78898
78685
79187
79119
79165
78815
79220
79301
79023
78934
78956
...

result:

ok 80000 lines

Test #20:

score: 20
Accepted
time: 2693ms
memory: 796664kb

input:

80000 79996
513551673 392710681 809819869 294630781 357976969 977317841 893482480 140598408 919495755 859788887 757358168 456763555 467040695 163540455 850001989 869235571 730673055 972214053 658305363 757224641 960452273 808330129 79574079 410677408 489598301 441993771 1025449 503166145 873150027 3...

output:

79176
79032
79691
78645
79222
78677
79857
79289
19300869
19960816
1299594
5039597
7099916
17780451
16721279
17541238
1779153
15560727
19060427
16600530
4260014
18320831
79887
12340290
14240397
7700022
17361312
13860396
16940809
13341121
7740334
6719659
6720068
5699452
6380184
6719750
13700357
672023...

result:

ok 72752 lines