QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883333#9638. 线段树与区间加xxzx0 4381ms50804kbC++176.0kb2025-02-05 15:55:012025-02-05 15:55:06

Judging History

This is the latest submission verdict.

  • [2025-02-05 15:55:06]
  • Judged
  • Verdict: 0
  • Time: 4381ms
  • Memory: 50804kb
  • [2025-02-05 15:55:01]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define clo 1000.*clock()/CLOCKS_PER_SEC
#ifndef xxzx
#define endl '\n'
#endif
using ll=long long;
using PII=pair<int,int>;
const int N=4e5+10;
bool memory1;
template<typename T=int> T read() {
    T f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=x*10+ch-'0', ch=getchar(); }
    return f*x;
}
int n,m,l[N],r[N],ls[N],rs[N],id[N],idfn[N];
unsigned va[N],vb[N],len[N];
struct SegmentTree {
    unsigned res[N<<2],lz[N<<2],f[N<<2],cl[N<<2];
    #define ls (id<<1)
    #define rs (id<<1|1)
    // res = v*f
    void Build(int id,int l,int r) {
        if(l==r) return f[id]=vb[idfn[l]],void();
        int mid=(l+r)>>1;
        Build(ls,l,mid),Build(rs,mid+1,r);
        f[id]=f[ls]+f[rs];
    }
    void pushdown(int id) {
        if(cl[id]) {
            cl[id]=0;
            res[ls]=lz[ls]=0,cl[ls]=1;
            res[rs]=lz[rs]=0,cl[rs]=1;
        }
        if(lz[id]) {
            unsigned val=lz[id]; lz[id]=0;
            res[ls]+=f[ls]*val,lz[ls]+=val;
            res[rs]+=f[rs]*val,lz[rs]+=val;
        }
    }
    void Modify(int id,int l,int r,int x,int y,unsigned val) {
        if(x>y) return;
        if(x<=l&&y>=r) {
            // cerr<<"Modi "<<id<<" "<<l<<" "<<r<<" "<<x<<" "<<y<<" "<<f[id]*val<<" "<<f[id]<<endl;
            res[id]+=f[id]*val,lz[id]+=val;
            return;
        }
        pushdown(id);
        int mid=(l+r)>>1;
        if(x<=mid) Modify(ls,l,mid,x,y,val);
        if(y>mid) Modify(rs,mid+1,r,x,y,val);
        res[id]=res[ls]+res[rs];
    }
    void Clear(int id,int l,int r,int x,int y) {
        if(x>y) return;
        if(x<=l&&y>=r) {
            res[id]=lz[id]=0,cl[id]=1;
            return;
        }
        pushdown(id);
        int mid=(l+r)>>1;
        if(x<=mid) Clear(ls,l,mid,x,y);
        if(y>mid) Clear(rs,mid+1,r,x,y);
        res[id]=res[ls]+res[rs];
    }
    #undef ls
    #undef rs
}sgt;
int sz[N],son[N],fa[N][20],dep[N];
void dfs1(int x,unsigned sum) {
    // cerr<<"Dfs1"<<endl;
    sum+=va[x];
    vb[x]+=sum*len[x],sz[x]=1;
    if(!ls[x]) return;
    for(auto y:{ls[x],rs[x]}) {
        fa[y][0]=x,dep[y]=dep[x]+1;
        dfs1(y,sum);
        sz[x]+=y;
    }
    son[x]=(sz[ls[x]]>=sz[rs[x]])? ls[x]:rs[x];
}
void dfs11(int x) {
    if(!ls[x]) return;
    for(auto y:{ls[x],rs[x]}) {
        vb[x]-=vb[y];
        dfs11(y);
    }
}
int jump(int x,int h) {
    for(int i=0;h;h>>=1,i++) if(h&1) x=fa[x][i];
    return x;
}
int lca(int x,int y) {
    if(dep[x]<dep[y]) swap(x,y);
    x=jump(x,dep[x]-dep[y]);
    if(x==y) return x;
    for(int i=19;i>=0;i--)
        if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
    return fa[x][0];
}
int L[3][N],R[3][N],tim,top[N],vis[N];
void dfs2(int x) {
    // cerr<<"Dfs2 "<<endl;
    vector<int> nd;
    int p=x; vis[p]=1,nd.push_back(p);
    while(son[p]) p=son[p],vis[p]=1,nd.push_back(p);
    for(auto i:nd) L[0][i]=++tim,top[i]=x,idfn[tim]=i;
    for(auto i:nd) R[0][i]=tim;
    for(auto i:nd) {
        L[1][i]=tim+1;
        if(ls[i]&&!vis[ls[i]]) dfs2(ls[i]);
        R[1][i]=tim;
    }
    for(auto i:nd) {
        L[2][i]=tim+1;
        if(rs[i]&&!vis[rs[i]]) dfs2(rs[i]);
        R[2][i]=tim;
    }
}
int rt;
void clear(int x) {  // x 到根全体清空
    while(x) {
        sgt.Clear(1,1,2*n-1,L[0][top[x]],L[0][x]);
        x=fa[top[x]][0];
    }
}
void addsub(int p,unsigned v) {
    // cerr<<L[0][p]<<" "<<R[0][p]<<endl;
    // cerr<<L[1][p]<<" "<<R[1][idfn[R[0][p]]]<<endl;
    // cerr<<L[2][p]<<" "<<R[2][idfn[R[0][p]]]<<endl;
    sgt.Modify(1,1,2*n-1,L[0][p],R[0][p],v);
    sgt.Modify(1,1,2*n-1,L[1][p],R[1][idfn[R[0][p]]],v);
    sgt.Modify(1,1,2*n-1,L[2][p],R[2][idfn[R[0][p]]],v);
}
void add(int x,int y,int op,unsigned v) { // x 到 y 左/右 子树加
    // cerr<<"Add "<<x<<" "<<y<<" "<<op<<" "<<v<<endl;
    while(top[x]!=top[y]) {
        // cerr<<x<<" "<<top[x]<<" "<<L[op][top[x]]<<" "<<R[op][x]<<endl;
        sgt.Modify(1,1,2*n-1,L[op][top[x]],R[op][x],v);
        if(son[x]&&((op==1)? ls[x]:rs[x])==son[x]) addsub(son[x],v);
        x=fa[top[x]][0];
    }
    // cerr<<x<<" "<<y<<" "<<L[op][y]<<" "<<R[op][x]<<endl;
    sgt.Modify(1,1,2*n-1,L[op][y],R[op][x],v);
    if(son[x]&&((op==1)? ls[x]:rs[x])==son[x]) addsub(son[x],v);
}
bool memory2;
int main() {

    n=read(),m=read();
    set<pair<PII,int>> seg;
    for(int i=1;i<=2*n-1;i++) {
        l[i]=read(),r[i]=read(),va[i]=read<unsigned>(),vb[i]=read<unsigned>();
        seg.insert({{l[i],r[i]},i});
        len[i]=r[i]-l[i]+1;
        if(l[i]!=r[i]) ls[i]=read(),rs[i]=read();
        if(l[i]==1&&r[i]==n) rt=i;
    }
    dfs1(rt,0);
    dfs11(rt);
    dfs2(rt);
    for(int j=1;j<20;j++) for(int i=1;i<=2*n-1;i++) fa[i][j]=fa[fa[i][j-1]][j-1];
    for(int i=1;i<=2*n-1;i++) if(rs[i]) id[l[rs[i]]]=i;
    id[1]=2*n,id[n+1]=2*n+1,dep[2*n]=dep[2*n+1]=-1;
    // for(int i=1;i<=2*n-1;i++) cerr<<idfn[i]<<" ";
    // cerr<<endl;
    sgt.Build(1,1,2*n-1);
    // unsigned val=(vb[2]+vb[4]+vb[5]+vb[6]+vb[7]);
    // cerr<<val<<endl;
    // cout<<sgt.res[1]<<endl;
    // m=1;
    // return 0;
    // cerr<<jump(8,2)<<" "<<fa[8][0]<<" "<<fa[]<<endl;
    for(int _=1,l,r,v;_<=m;_++) {
        l=read(),r=read(),v=read();
        auto it=seg.lower_bound({{l,r},0});
        if(it!=seg.end()&&it->first==make_pair(l,r)) {
            int p=it->second;
            clear(fa[p][0]);
            // cerr<<"P "<<p<<endl;
            addsub(p,v);
        }
        else {
            int x=id[l],y=id[r+1],z=((max(x,y)<=2*n-1)? lca(x,y):max(x,y));
            // cerr<<"A "<<x<<" "<<y<<" "<<dep[y]-dep[z]-1<<endl;
            if(x<=2*n-1&&x!=z) { clear(x),add(x,jump(x,dep[x]-dep[z]-1),2,v); }
            if(y<=2*n-1&&y!=z) { clear(y),add(y,jump(y,dep[y]-dep[z]-1),1,v); }
        }
        cout<<sgt.res[1]<<endl;
    }

    #ifdef xxzx
    cerr<<"Time: "<<clo<<"MS"<<endl;
    cerr<<"Memory: "<<abs(&memory1-&memory2)/1024./1024.<<"MB"<<endl;
    #endif
    return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 45ms
memory: 36740kb

input:

2000 2000
1793 1798 1262660447 3355636366 3629 1228
103 1852 1180930258 1265499397 1821 3806
680 680 2673755170 3193571303
737 740 3064103572 3343535318 1993 502
1720 1721 3117882744 1227116751 3561 1857
117 117 2249090646 234980450
1897 1901 87845907 4069299503 2523 1140
1832 1835 981230847 3022191...

output:

3079305268
850362222
2072450865
3855086628
3790667112
1516006555
1234386417
1385471247
1154851441
1432251412
4017657876
4168890441
2316870970
3296345348
248710763
2101205640
2673495007
974559766
756114357
3260752597
2203106412
3673232333
855985344
2033446685
2471851657
3691120728
1050392690
38951311...

result:

wrong answer 1st lines differ - expected: '3152111116', found: '3079305268'

Test #2:

score: 0
Wrong Answer
time: 27ms
memory: 34724kb

input:

2000 2000
372 372 0 989361745
268 744 0 2134086804 3992 1151
929 932 0 3450655381 1108 1775
1527 1527 0 2098122263
261 264 0 767043297 3813 2562
1011 1013 0 1426875762 997 1431
160 160 0 2574808476
1660 1770 0 2181120880 1536 69
1650 1650 0 3634539115
811 811 0 4269292508
518 518 0 3874323908
248 25...

output:

1156435640
2221228426
483505422
4155907744
2975337630
63286150
46098018
3799871542
2453278710
2996626115
2999143642
2053652821
3746653149
449371563
3462500675
2386560554
4012127657
3415516825
2711830381
4244884185
159652911
139646109
1193545480
3376890798
412655508
1719254316
2861956808
3106280414
2...

result:

wrong answer 1st lines differ - expected: '2047726267', found: '1156435640'

Test #3:

score: 0
Wrong Answer
time: 56ms
memory: 36792kb

input:

2000 2000
1045 1046 0 2632377141 2540 3747
1673 1674 0 1669064774 1585 1359
1737 1737 0 4187517691
134 134 0 1381105987
1678 1678 0 3194199856
629 632 0 1039365507 1669 3337
1224 1225 0 2056342816 2564 1715
501 1491 0 2746594998 563 3172
1859 1860 0 1399867507 3486 1239
377 377 0 4114286174
266 266 ...

output:

1676674544
538019360
3345374485
3685119702
988248742
209691244
2451088650
1731842600
3652130491
1826670439
3942021889
1420371447
2921133511
3546841885
2619524241
41176983
3806161888
1893825286
1017745348
2040788593
1150533996
4062621744
1432358777
574413313
1686157289
719663012
4072075389
2393509639...

result:

wrong answer 1st lines differ - expected: '1036900736', found: '1676674544'

Test #4:

score: 0
Wrong Answer
time: 8ms
memory: 36752kb

input:

2000 2000
1922 1923 4154142567 0 624 1116
1611 1625 1842722647 0 1405 1312
101 102 328256453 0 3110 2786
859 860 1546215739 0 489 2099
1154 1157 4134074442 0 341 792
531 532 1656285477 0 1961 1533
451 454 2149232978 0 3570 253
496 496 12489066 0
1697 1700 2769881303 0 2485 3845
1232 1232 4274380990 ...

output:

2975033606
992523173
3648188645
2220088974
342759623
530904408
2938916712
838900372
3123173824
371270249
3363579316
2019592583
1781167785
1781246952
1758393964
99976203
3465794444
623190934
3967558096
3209006647
2120171017
59815991
2163592070
1520874096
4237329757
4049218231
1435220721
3696163501
45...

result:

wrong answer 1st lines differ - expected: '1244935696', found: '2975033606'

Test #5:

score: 0
Wrong Answer
time: 28ms
memory: 36780kb

input:

2000 2000
1516 1516 786840671 0
546 547 533550872 0 3506 319
947 952 3586638444 0 1398 2922
1769 1777 1598495528 0 2351 3492
1487 1488 3433976236 0 2998 372
266 268 4081199540 0 3034 1376
9 11 16162852 0 2016 2453
606 606 868772445 0
500 501 1406522390 0 1201 3967
1448 1449 2080781326 0 1547 1988
22...

output:

3179466100
129146720
1483639252
2904472748
3281999006
1135453842
1642802938
4018559695
1608373960
2758674791
2807958345
2016873143
3187178632
885240809
697934028
3836053124
340646274
679507708
3968272857
3500881361
3022600115
4238137308
487638796
92993681
500326841
1123076540
546229375
215986800
252...

result:

wrong answer 1st lines differ - expected: '355422488', found: '3179466100'

Test #6:

score: 0
Wrong Answer
time: 4381ms
memory: 50804kb

input:

40000 40000
19061 19064 2717945240 3834098532 59850 71996
14933 14933 877340266 1841904212
34098 34170 3550522541 2738188651 75607 2753
4691 4691 530532762 675854163
9890 9890 2833834223 2233457146
14140 14140 1300081732 193421532
1623 1623 1598527863 3121134528
4929 4929 1218079042 439770536
324 39...

output:

446032584
1068667284
1095232464
2809690491
796335975
3053259587
846764611
4186880632
344640614
590799026
324517100
3214600311
2711067493
461047809
3754104924
2461788999
2524251946
767334293
3609191518
2438864664
625854147
4049665807
1694792185
681149406
1204745038
4292232147
646299330
1435183388
242...

result:

wrong answer 1st lines differ - expected: '3762372552', found: '446032584'

Test #7:

score: 0
Time Limit Exceeded

input:

40000 40000
37504 37504 0 2993769426
14320 14322 0 3704545631 44050 52152
2757 37130 0 1236105917 2455 3677
884 884 0 4026492894
10076 10077 0 609448457 7650 75701
16404 16404 0 245461674
22018 22018 0 2771692605
1501 1501 0 2419888954
16860 16861 0 1871411848 33204 21442
15067 15068 0 1175031405 20...

output:

3043301312
3828780490
1764651786
3371325463
4042853178
2192292408
1365660230
3922429886
784393756
2251041343
2435854723
2730367790
989058747
2340102336
3912226568
3061725600
1443821865
3648406353
1741225104
3937904060
2809284428
1390447527
1986574728
1881764172
2118564901
490621537
1421025677
328355...

result:


Test #8:

score: 0
Time Limit Exceeded

input:

40000 40000
20206 20206 0 4103926985
25572 25573 0 1124285259 79417 25683
23524 23524 0 2945938453
26314 26316 0 3769707656 62994 20223
1933 1933 0 3202000408
12690 27072 0 663839624 50239 60259
27007 27013 0 1608124753 48394 32123
1283 1284 0 4010999538 17252 36084
11373 11375 0 3200987115 25973 22...

output:

2636541354
1989382600
4019111239
2014251429
2100301135
1863438317
2399501571
1326138648
3478425731
402036618
1655428879
953342639
3387919196
3123617156
3897509863
675447646
151315870
3770108965
4179813837
1092314771
16927998
118518594
2519614088
1482860177
738512899
882544279
3354512884
1839856090
1...

result:


Test #9:

score: 0
Time Limit Exceeded

input:

40000 40000
28600 31103 398400104 0 50206 67695
18214 18214 987691543 0
21117 21117 2501164446 0
35971 35972 884844107 0 49942 386
17501 17501 4216208706 0
12649 12649 3198897355 0
1690 1695 1689582721 0 30803 36361
33084 33084 2651714130 0
26656 26660 3389387136 0 27495 17328
32764 32764 2921506964...

output:

33141280
738777899
1430909578
2495570363
2485870587
423571815
3704064392
1902393337
2822434533
1159014167
1308130736
1932524554
2092551380
3924263280
2065449916
2203823048
1629901841
3697726653
847882159
3110632694
17922192
3878998845
3694398312
1622710693
1542494982
2954652074
2673372237
767779192
...

result:


Test #10:

score: 0
Time Limit Exceeded

input:

40000 40000
24203 24203 1353036479 0
30073 30082 1740596718 0 53750 62241
11650 11652 3664808690 0 7271 53525
17686 17686 2170088447 0
14215 14215 877899577 0
10389 14544 1220290260 0 2779 34931
17557 17561 3312844542 0 9486 56774
37025 37026 360931058 0 52630 1863
8544 8545 2355582057 0 34372 13606...

output:

166456831
1720477463
2814660468
2954046912
2501151141
1661342565
1635994787
922802748
694311294
2901184995
654801891
4196746424
3943030541
1253134810
2074849560
1594402815
2373842929
960447554
65101132
908491517
2824111265
2454896976
4220408255
2879793339
802519851
3300526147
646361108
1024079082
41...

result:


Test #11:

score: 0
Time Limit Exceeded

input:

200000 200000
32600 32601 279707947 3333652085 81223 369345
107195 110357 2797643167 3204100200 211635 180774
50076 50076 3586231592 2031356328
9086 9086 2226760698 457985624
89785 143170 2137446218 370802330 339432 56185
15190 19580 3336566407 2687475581 239505 274514
199717 199717 1343907462 27476...

output:

2009836216
3727996800
3450134793
3406485732
1123726936
1170973510
764967399
1336588779
917647199
2249365950
2934805008
1625886692
2425348432
3997654416
3288567872
3719461083
228163419
1349877510
2715061693
3905289161
813191337
1445005585
1078905575
3999781666
3626536053
3480952270
1200888304
7849245...

result:


Test #12:

score: 0
Time Limit Exceeded

input:

200000 200000
103447 103448 0 2671179003 304649 129499
145911 145911 0 1121422691
157741 157744 0 1929193038 145603 72009
11904 11905 0 2289998670 146636 237088
122867 122868 0 186090819 413 270761
193873 193873 0 203093844
20838 20838 0 2999266101
92497 92498 0 2375994881 321423 197661
10185 10185 ...

output:

1287630144
1911410702
2542412142
2949149180
2597050152
1479226049
699517062
1840378744
3561042026
2295091954
1476949713
318057754
3160099934
2529106282
1409773717
2979058284
254069790
2408520951
767089333
2745981939
2707418577
350113395
2245460988
2655942395
3685437519
3972634965
351126485
128739571...

result:


Test #13:

score: 0
Time Limit Exceeded

input:

200000 200000
190183 190188 0 1706040846 362170 41622
150705 150705 0 2188179441
148325 148330 0 2355075143 61581 324431
190406 190407 0 1131747042 383315 217073
23144 23152 0 1897327529 396050 285637
93051 93051 0 1804212175
186538 186541 0 3315936642 306793 151829
45692 45692 0 1239029798
30972 30...

output:

2075029659
3550857507
3975089737
1922279342
534671262
1315305932
3932082574
576645640
1491251464
1599102206
2909848918
2484431669
2562655797
1342243997
95469720
3085411021
4220881397
2707863723
509188519
2382632511
2493078850
3595217833
1848800013
4146508855
3672985783
880937040
2586434528
940969940...

result:


Test #14:

score: 0
Time Limit Exceeded

input:

200000 200000
90506 102530 236918570 0 337847 201999
50479 50482 1884914043 0 242965 18370
197965 197965 1150415084 0
181841 181841 524351831 0
43868 43886 3739237894 0 365544 340081
104279 104279 1518148351 0
34148 34154 3970381744 0 379789 218872
73698 73698 3847658012 0
71224 71225 2029945887 0 3...

output:

2255959540
776843588
1939762368
407450021
2416728973
3351051967
238272039
3173214263
964780820
2479009385
2078308329
1085718897
3336408401
2469655047
3702885352
590105323
625121410
2752075115
3402348887
2538671649
3018668433
680197831
421512740
52919903
1904990371
2601865274
2699800194
868148810
207...

result:


Test #15:

score: 0
Time Limit Exceeded

input:

200000 200000
184636 184636 470383782 0
69147 163622 581509052 0 286341 357499
95155 95155 577954429 0
126294 126294 3693354981 0
184618 187568 3886149811 0 333358 166507
188512 188512 303047117 0
20400 20400 3407789462 0
44704 44705 1224895264 0 162096 75280
133755 133757 109227272 0 132577 372294
...

output:

3881118135
3222757985
114387977
2262724873
1481024296
3192177672
1825099959
3248957793
800918233
2409713038
1720265294
846986202
3604862840
2795825247
2843485417
302001729
4214926529
1468759477
2241022395
1641387459
929124036
182926454
8909911
3676263238
36476901
4207789233
2593381466
1110673084
829...

result:


Test #16:

score: 0
Time Limit Exceeded

input:

200000 200000
30492 35854 729190907 1956530869 220290 207964
178288 178288 793919639 4043397768
4965 4965 2255872372 819681301
64878 99465 669086428 517288923 75560 27338
13595 16760 415742798 3804064469 203533 253759
154291 154293 601666143 200879632 289484 190128
121100 121101 2476950350 105407364...

output:

471513582
3630844676
3875941193
2896405930
669552784
3268457446
2146222050
605859738
2765286760
495141188
4086176516
2112662641
2591436465
492880871
1996952630
1460580722
867472280
656568358
3261504944
710546895
2041047365
1396139122
97414999
2915182723
3542315947
4089917171
98331268
4059949710
2855...

result:


Test #17:

score: 0
Time Limit Exceeded

input:

200000 200000
158994 158994 0 2397655320
165026 165026 0 1247467790
193088 193089 0 1131792894 25325 134960
34834 34834 0 1974874050
106908 106908 0 158855686
73570 73571 0 660499851 32725 33730
126276 126276 0 2799927501
183868 183870 0 2792433045 319704 248051
145831 145832 0 796369972 384435 1211...

output:

4182761634
2573478161
1350665442
4003647920
3752866119
2045097891
294942592
2656374143
3465144855
4048241142
568216039
1275946502
2793678470
506492253
3268400564
4214675058
2878134889
4018100185
3149301803
651378366
3927235736
323941181
1641767162
3958658541
532492579
2908952880
3098771026
251757398...

result:


Test #18:

score: 0
Time Limit Exceeded

input:

200000 200000
42026 42026 0 103840682
115527 115527 0 730801603
175286 175286 0 952465904
115721 115722 0 3887082779 210578 202527
14017 17027 0 2717984672 155430 298216
113340 113340 0 1196664755
143222 143224 0 1622284707 237907 258953
115973 115975 0 2441078898 207848 192004
54478 54478 0 3169258...

output:

414885310
3561634217
907708502
431108259
134499723
1370370964
3472808209
1965421824
18679129
3963909820
715649719
3581743230
624354660
2042815270
3296727898
13670829
850771529
2207676392
2005666559
517001898
3106897744
920969049
2499123660
2266052285
626222568
3008857823
1233766271
2614591058
152315...

result:


Test #19:

score: 0
Time Limit Exceeded

input:

200000 200000
92524 92524 182603024 0
116778 116778 2576939405 0
10207 10207 1898802503 0
178036 178038 1935186518 0 44870 317892
137541 137544 2674676024 0 210860 64999
68085 68085 1958593201 0
179926 179929 2584382023 0 185913 349215
45422 45423 2495993608 0 157833 264143
109854 121340 113104103 0...

output:

1322337890
797089258
1174479137
1396032883
2491180222
3651374899
3620003872
1897689846
3876075825
3281084590
3810807273
1232855921
2994275502
3655558692
276170581
1259049899
690900421
2217306599
2131266112
2396128532
952280766
1375430604
2555335540
3054156293
3705630941
362650566
1678646501
84213641...

result:


Test #20:

score: 0
Time Limit Exceeded

input:

200000 200000
12387 12389 2109068107 0 384829 227596
26592 26594 2550267931 0 57077 72658
80444 80444 1329109323 0
119995 119995 4165698375 0
48876 48876 766047886 0
155836 155836 3512049107 0
50100 50100 1831955483 0
193088 193089 3589455426 0 34273 140648
126549 126549 1726763169 0
149430 154350 1...

output:

319213653
643850300
26925468
3564415217
2552428795
1587331186
3811807116
4163238217
3080701073
827381908
3334226586
2354013989
2217608702
3697153292
3318661634
2146372480
4144789700
441478769
920011275
3556198687
3726186208
3494995005
1319374668
2286567794
3637865715
3922617781
3106661187
1564132471...

result:


Test #21:

score: 0
Time Limit Exceeded

input:

200000 200000
165129 165131 3633865218 98447901 160942 69260
170590 170592 2878276602 4164208122 147121 65383
199006 199017 3624152661 4138881358 49640 64235
92616 137590 1278705205 1262535969 229078 92015
12733 12733 1753647128 400573041
138294 138294 503689729 1701121075
178554 185671 951413620 10...

output:

727625040
3094395468
1686555439
1085422057
1806711522
3304198166
947013730
4068517911
2127695064
435257377
1257778838
2730472923
4195837408
3300930087
840048359
2003134375
2756192247
1378560628
2809103596
3050025804
3479089390
1088935534
1710519493
2053541055
3633548045
840666081
3676355515
34333401...

result:


Test #22:

score: 0
Time Limit Exceeded

input:

200000 200000
42616 42616 0 4073548647
148817 148819 0 678516345 137141 295278
136568 136568 0 1311526245
162591 162591 0 1123778942
152429 152430 0 865424725 274628 226053
123226 123226 0 1843160929
3315 3315 0 2548140955
158521 158522 0 726899994 308692 139695
128630 128630 0 3560425273
137094 137...

output:

949752360
1589180878
135034780
2395961013
3553437685
1384498415
4117685394
846015166
1952259393
4241943119
2293135207
544154046
267007526
356177042
4012598703
2832076712
2714715624
60996927
3227378108
469324219
1155775116
2937379281
206656324
2918992689
1021698353
3480633
1906910737
1877926964
24393...

result:


Test #23:

score: 0
Time Limit Exceeded

input:

200000 200000
92930 92933 0 945338790 270177 344831
44586 44586 0 2120126372
80169 80169 0 3407810035
173606 173606 0 2056188474
144888 144888 0 1376882346
9586 9586 0 2496173660
67542 67542 0 3278572994
95705 95705 0 2103944675
73814 73815 0 4244900263 66623 87248
149429 149431 0 2014898776 8786 61...

output:

4175796843
594840094
4289455554
710718517
3647812736
2173012349
2064234600
3256476347
1415711229
1288899201
2003518750
1188383909
640096676
1291524057
4209501388
191442694
3703440395
794494102
3304020530
2461430094
647006636
77133788
1986104686
3275853237
3688311060
2255698416
164317009
4207895095
2...

result:


Test #24:

score: 0
Time Limit Exceeded

input:

200000 200000
182457 182458 3070241886 0 235330 232917
130450 160512 2343593919 0 288610 262204
86835 86836 2084902783 0 271317 299422
39111 91715 827843559 0 14965 357810
131676 131677 2889067161 0 266237 6055
88274 88274 4216568292 0
119859 119861 3636500316 0 297047 394521
30700 112091 528067902 ...

output:

3633547518
3074446252
501784244
591686752
2848650061
1190139676
3655719397
2516800484
1588324487
1792479775
411870068
1134436647
1268603560
3796009473
188550192
1070534284
1139263636
3231714626
1163949132
1333051707
1105393365
2526844405
3944412603
632694493
633697579
3733989723
228302882
3750821490...

result:


Test #25:

score: 0
Time Limit Exceeded

input:

200000 200000
16728 16728 2942007300 0
176509 176509 1919353043 0
102679 102679 3974389408 0
182519 182519 1184106257 0
83079 83089 1520374942 0 181757 4901
35926 35926 2259226600 0
33932 33933 3693656209 0 101981 2261
1804 1805 4038337356 0 92067 46297
15141 15143 4117148560 0 172165 356831
59008 5...

output:

3552080672
3639133188
2659139728
694571178
4124668395
2697317059
3595986119
492675787
2410727407
1770532037
3411472399
3431642493
1824912799
1969593818
2723077675
1262991670
3866818399
3789497452
3466794788
1949992233
2961580434
221588224
185407249
2137757997
2831595223
566746211
2286032099
36601221...

result: