QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#469203#4898. 基础图论练习题ship207718 87ms22732kbC++172.4kb2024-07-09 16:04:402024-07-09 16:04:41

Judging History

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

  • [2024-07-09 16:04:41]
  • 评测
  • 测评结果:18
  • 用时:87ms
  • 内存:22732kb
  • [2024-07-09 16:04:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
constexpr int M=2e5+5,bas=1e9+7,mod=998244353;
int m,q,ans,f[M];ull tr[M],pw[M];
vector<array<int,3>>edge;
vector<array<int,2>>opt;
vector<int>g[M];ll n;
ll read(){
    ll x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
int rdc(int x){return x>=mod?x-mod:x;}
int find(int x){return f[x]==x?x:find(f[x]);}
void update(int x,ull p){while (x<=n) tr[x]+=p,x+=x&-x;}
ull query(int x){ull ans=0;while (x) ans+=tr[x],x-=x&-x;return ans;}
ull gethash(int l,int r){return (query(r)-query(l-1))*pw[n-l];}
void merge(int x,int y){ x=f[x];y=f[y];
    if (g[x].size()<g[y].size()) swap(x,y);
    for (auto z:g[y]){ f[z]=x;
        update(z,pw[z]*(x-y));
        g[x].emplace_back(z);
    } g[y].clear();
}
void motherfucker(){
    ll a=read(),x=read(),b=read(),y=read();
    if (x>y) swap(a,b),swap(x,y);
    ll tmp=min(n-__gcd(a,b),n*2-a-b);
    printf("%lld\n",((n-a)%mod*x+(tmp-(n-a))%mod*y)%mod);
}
int main(){
    n=read();m=read();q=read();
    if (m==2&&q==0) return motherfucker(),0;
    for (int i=pw[0]=1;i<=n;i++) pw[i]=pw[i-1]*bas;
    for (int i=1;i<=m;i++){
        int x=read(),k=read();
        opt.push_back({k,x});
    }
    sort(opt.begin(),opt.end());
    for (int i=1;i<=q;i++){
        int x=read(),y=read(),z=read();
        edge.push_back({z,x+1,y+1});
    }
    sort(edge.begin(),edge.end()); int h1=0,h2=0;
    for (int i=1;i<=n;i++) f[i]=i,g[i]={i},update(i,pw[i]*i);
    while (h1<opt.size()||h2<edge.size())
        if (h2==edge.size()||h1<opt.size()&&opt[h1][0]<edge[h2][0]){
            const int len=opt[h1][1]; int lst=1;
            while (gethash(len+1,n)!=gethash(1,n-len)){
                int l=1,r=n-len,pos=-1;
                while (l<=r){
                    int mid=l+r>>1;
                    if (gethash(len+1,len+mid)!=gethash(1,mid))
                        pos=mid,r=mid-1;
                    else l=mid+1;
                }
                merge(pos,len+pos);  lst=pos;
                ans=rdc(ans+opt[h1][0]);
            } h1++;
        }
        else{
            if (gethash(edge[h2][1],edge[h2][1])!=gethash(edge[h2][2],edge[h2][2]))
                merge(edge[h2][1],edge[h2][2]),ans=rdc(ans+edge[h2][0]); h2++;
        }
    printf("%d\n",ans);
    return 0;
}

詳細信息

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 60ms
memory: 18996kb

input:

161199 9 46510
147335 540442844
159493 801351455
149342 821625305
128476 843250712
95524 275754315
139315 106523502
93575 680460786
155498 328812257
146020 410466645
79992 141967 50596784
152210 68644 268349216
72549 96959 42994091
93869 27394 945120577
2909 81886 270684270
12735 35026 871917997
974...

output:

359714743

result:

ok 1 number(s): "359714743"

Test #2:

score: 0
Accepted
time: 74ms
memory: 20052kb

input:

168549 9 49402
160577 34610415
114623 670751010
74448 676966248
53782 845469137
130729 375561046
31610 261496571
134601 154875802
136129 905308676
166248 499420220
69637 72676 875637640
160442 125460 1269794
146261 61770 714794725
137610 1291 490170432
162092 81850 488118013
106400 48193 276190368
4...

output:

520439176

result:

ok 1 number(s): "520439176"

Test #3:

score: 0
Accepted
time: 60ms
memory: 17632kb

input:

127164 9 45109
56483 490066497
70966 229077054
87305 993081887
72423 442762798
80262 200507011
101712 162752728
67532 590730535
44956 565466274
124237 429166816
13030 8906 742024040
97259 101468 187678659
13401 4301 143856524
125750 80473 258719294
106155 10339 592121345
120034 92354 50915550
112430...

output:

211463174

result:

ok 1 number(s): "211463174"

Test #4:

score: 0
Accepted
time: 63ms
memory: 19168kb

input:

158784 9 48415
138305 177767002
147417 50196642
85527 776201932
144377 990389932
118355 310906417
145220 218744495
145002 132736644
51947 834751363
139733 839880491
158443 157692 159261414
111518 14927 747973081
37498 66196 69874791
11597 115114 22394413
16704 133459 109302190
112143 46551 813021872...

output:

151875883

result:

ok 1 number(s): "151875883"

Test #5:

score: 0
Accepted
time: 20ms
memory: 15388kb

input:

111371 0 45933
13298 59545 852258097
94111 54245 459369673
40744 23311 644404848
37039 92443 220984611
17374 43165 421794343
57652 57965 470479953
62977 14481 563172671
102144 3471 36594913
46628 43278 11508424
55965 80136 777230453
56962 35374 349098036
34825 27995 339605509
43021 17657 780921827
5...

output:

92500087

result:

ok 1 number(s): "92500087"

Subtask #2:

score: 8
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 8
Accepted
time: 79ms
memory: 20876kb

input:

191116 49595 45279
87483 815631830
153579 433065789
167569 346797140
98560 154881536
170720 13622837
133236 561208103
155537 421316363
140536 514298139
6005 986290017
154400 85233907
166826 351094521
174419 304435906
173900 61174962
112778 693574534
104503 745038995
134920 31228457
117606 662581798
...

output:

938591083

result:

ok 1 number(s): "938591083"

Test #7:

score: 0
Accepted
time: 81ms
memory: 18652kb

input:

158784 46472 48415
117545 640905746
155053 431989480
155561 63255800
142377 310683680
127120 588058774
150004 169474069
127002 588668628
150906 152304212
108743 687077799
41914 919104130
85429 816335084
132059 559711015
9237 981038801
108448 689051256
152572 446125546
151056 149667391
3602 992249821...

output:

719582900

result:

ok 1 number(s): "719582900"

Test #8:

score: 0
Accepted
time: 87ms
memory: 22732kb

input:

168163 49816 47597
129571 532707978
89007 791596146
120950 589183161
116493 617468410
89768 786647320
94035 758413684
137865 480953267
136999 487494650
134286 503698037
115468 623920627
128035 542927955
91335 776005194
150127 398148336
2766 992431297
143028 109308374
98376 730561618
135270 13761588
...

output:

934807905

result:

ok 1 number(s): "934807905"

Test #9:

score: 0
Accepted
time: 64ms
memory: 17084kb

input:

121718 46964 48021
43354 819111261
10530 955367869
80777 501381455
69544 639333275
114691 89113603
45387 810937142
31928 865064071
89801 391744587
94263 339137420
119935 23921502
56223 766531932
108313 167240585
106757 185911175
30245 872961430
71691 612640613
102314 242401520
101122 257170039
61627...

output:

135228392

result:

ok 1 number(s): "135228392"

Test #10:

score: 0
Accepted
time: 73ms
memory: 22352kb

input:

188134 49787 48968
187895 50171716
119433 814368117
139552 750931626
132931 458299971
142653 741277533
177407 244563903
130505 469034750
145157 399488414
173707 262070086
168863 158870562
172377 35902964
140369 421860855
29507 967813282
165485 301042299
143784 737822317
162077 173448746
108264 85153...

output:

100771003

result:

ok 1 number(s): "100771003"

Subtask #3:

score: 6
Accepted

Test #11:

score: 6
Accepted
time: 0ms
memory: 10268kb

input:

569435269457904707 2 0
490445920091092693 772271583
144842828305643603 609043885

output:

884694794

result:

ok 1 number(s): "884694794"

Test #12:

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

input:

946929772456816659 2 0
589193907831915013 196301185
485768367910597533 207014034

output:

790540706

result:

ok 1 number(s): "790540706"

Test #13:

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

input:

693038683299151358 2 0
654733556025919068 724998910
450253521190874799 187460097

output:

122292064

result:

ok 1 number(s): "122292064"

Test #14:

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

input:

572269482188906358 2 0
545978502848607475 331750201
488577730099900109 477584735

output:

429885702

result:

ok 1 number(s): "429885702"

Test #15:

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

input:

984888155303961325 2 0
421568681423492040 823358650
324408005979881943 905919848

output:

551223124

result:

ok 1 number(s): "551223124"

Test #16:

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

input:

968068649251960108 2 0
932666179822285222 303897491
422068063538287737 405622211

output:

516717723

result:

ok 1 number(s): "516717723"

Test #17:

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

input:

973235486287221374 2 0
604729607242747292 566399250
440704799734330948 93237801

output:

772791524

result:

ok 1 number(s): "772791524"

Test #18:

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

input:

980842002786834388 2 0
921076927921054095 989436809
917078581302025088 354268450

output:

387335763

result:

ok 1 number(s): "387335763"

Test #19:

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

input:

584600268153835325 2 0
436736455094118542 788823700
379215887395241676 440751386

output:

178749302

result:

ok 1 number(s): "178749302"

Test #20:

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

input:

984888155303961325 2 0
421568681423492040 823358650
324408005979881943 905919848

output:

551223124

result:

ok 1 number(s): "551223124"

Subtask #4:

score: 0
Runtime Error

Dependency #3:

100%
Accepted

Test #21:

score: 0
Runtime Error

input:

569435269457904707 2 48002
490445920091092693 772271583
144842828305643603 609043885
71626464779726163 20936760728342582 933619218
254533877531926689 561120543297327423 444805145
102181371350776436 64807827761321835 63236550
442490347461393187 274703226312639148 379888813
153103619447430279 56932615...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #31:

score: 0
Runtime Error

input:

755526150476311190 942 0
492334667739348527 1
755523898623296976 1
532486636690994793 1
755526150476030559 1
755526150476249097 1
502164090270592200 1
657422656495814703 1
487200614853438190 1
311037325561173142 1
755526150475651155 1
125287404340238660 1
755524914808674090 1
755526150476177007 1
75...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #3:

100%
Accepted

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

100%
Accepted

Dependency #5:

0%

Subtask #8:

score: 0
Skipped

Dependency #5:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

0%