QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410583#6662. 기지 간소화tuanlinh12311 743ms101476kbC++203.3kb2024-05-14 10:11:192024-05-14 10:11:19

Judging History

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

  • [2024-05-14 10:11:19]
  • 评测
  • 测评结果:11
  • 用时:743ms
  • 内存:101476kb
  • [2024-05-14 10:11:19]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;

const ll maxn=300005, Mod=1e9+7;

struct SegTree
{
    struct Node
    {
        ll sum=0, pre=0, suf=0, len=0;
        Node(){}

        Node (ll x): sum(x), pre(x), suf(x), len(1){}

        Node operator + (const Node &o) const 
        {
            Node ans;
            ans.len=len+o.len;
            ans.sum=sum+o.sum+suf*o.pre;
            ans.pre=pre==len?pre+o.pre:pre;
            ans.suf=o.suf==o.len?o.suf+suf:o.suf;
            return ans;
        }
    };

    ll n;
    vector <Node> St;

    void build(ll i, ll Start, ll End, ll v)
    {
        if (Start==End) {St[i]=Node(v); return;}
        ll mid=(Start+End)/2;
        build(i*2, Start, mid, v);
        build(i*2+1, mid+1, End, v);
        St[i]=St[i*2]+St[i*2+1];
    }
    SegTree(ll n, ll v): n(n){St.resize(n*4+1), build(1, 0, n-1, v);}

    void update(ll i, ll Start, ll End, ll idx, ll v)
    {
        if (Start==End) {St[i]=Node(v); return;}
        ll mid=(Start+End)/2;
        if (mid>=idx) update(i*2, Start, mid, idx, v);
        else update(i*2+1, mid+1, End, idx, v);
        St[i]=St[i*2]+St[i*2+1];
    }
    void update(ll idx, ll v){update(1, 0, n-1, idx, v);}

    ll query(){return St[1].sum;}
};

int maintenance_costs_sum(std::vector<int> U, std::vector<int> V, std::vector<int> W) 
{
    ll n=sz(W)+1;
    vector <vector <pll>> A(n);
	for (ll i=0; i<sz(W); i++)
        A[U[i]].pb({V[i], W[i]}), A[V[i]].pb({U[i], W[i]});
    // all nodes in subtree i is marked with val, all nodes outside marked with val^1
    auto solve=[&](ll val)
    {
        SegTree S(n, val^1);
        vector <ll> ans(n, 0), child(n, 0), big(n, -1);
        function <void(ll, ll)> predfs=[&](ll u, ll pa)
        {
            child[u]=1;
            for (auto [v, w]:A[u])
            {
                if (v==pa) continue;
                predfs(v, u), child[u]+=child[v];
                if (big[u]==-1 || child[big[u]]<child[v]) big[u]=v;
            }
        }; predfs(0, 0);
        function <void(ll, ll, ll)> mark=[&](ll u, ll pa, ll c)
        {
            S.update(u, c);
            for (auto [v, w]:A[u])
                if (v!=pa)
                    mark(v, u, c);
        };
        function <void(ll, ll)> calc=[&](ll u, ll pa)
        {
            for (auto [v, w]:A[u])
                if (v!=pa && v!=big[u])
                    calc(v, u), mark(v, u, val^1);
            if (big[u]!=-1) calc(big[u], u);
            for (auto [v, w]:A[u])
                if (v!=pa && v!=big[u])
                    mark(v, u, val);
            S.update(u, val);
            ans[u]=S.query();
        }; calc(0, 0);
        return ans;
    };
    ll answer=0;
    vector <ll> cnt[2];
    cnt[0]=solve(0), cnt[1]=solve(1);
    function <void(ll, ll)> getans=[&](ll u, ll pa)
    {
        for (auto [v, w]:A[u])
            if (v!=pa)
            {
                answer+=w*(n*(n+1)/2-cnt[0][v]-cnt[1][v]);
                answer%=Mod;
                getans(v, u);
            }
    }; getans(0, 0);
    return answer;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 3736kb

input:

2
1 0 1

output:

1

result:

ok single line: '1'

Test #2:

score: 5
Accepted
time: 1ms
memory: 3856kb

input:

299
72 263 662908099
170 230 583287081
181 87 461245480
117 116 41098264
282 218 300936390
238 128 561969086
175 105 305200697
152 28 927649982
211 58 290232523
233 188 304617152
246 74 61325892
283 120 724838352
207 94 123021801
138 241 893659708
171 283 82846115
104 250 142703714
111 63 547249068
...

output:

93964028

result:

ok single line: '93964028'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3856kb

input:

300
116 249 999999948
23 182 999999956
174 147 999999978
21 178 999999981
138 238 999999941
215 6 999999955
190 256 999999990
107 203 999999992
142 221 999999943
129 236 999999957
55 154 999999992
183 35 999999979
200 284 999999958
36 222 999999988
88 62 999999960
219 222 999999950
95 38 999999960
2...

output:

534442086

result:

ok single line: '534442086'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3976kb

input:

5
0 2 2
2 1 3
2 4 6
0 3 5

output:

98

result:

ok single line: '98'

Test #5:

score: 5
Accepted
time: 0ms
memory: 3688kb

input:

10
1 5 1
6 2 10
8 1 3
3 9 1
8 0 10
2 3 6
7 0 5
2 4 7
4 7 3

output:

1625

result:

ok single line: '1625'

Test #6:

score: 5
Accepted
time: 0ms
memory: 3976kb

input:

10
2 5 242840396
4 7 425058513
7 9 975802175
7 1 647540462
3 7 239781206
2 0 873867121
4 0 132645393
6 4 862552539
0 8 542726039

output:

711424766

result:

ok single line: '711424766'

Test #7:

score: 5
Accepted
time: 1ms
memory: 3788kb

input:

299
107 270 74
187 221 79
142 129 40
77 272 27
94 152 1
117 171 74
64 79 87
263 36 91
257 176 1
183 191 82
109 67 23
91 90 30
116 228 76
276 152 15
59 165 40
160 235 71
235 116 82
102 44 88
130 289 72
241 150 14
62 176 23
277 50 83
206 38 11
66 250 72
84 120 66
137 259 54
46 287 82
209 263 57
151 24...

output:

399821685

result:

ok single line: '399821685'

Test #8:

score: 5
Accepted
time: 1ms
memory: 3816kb

input:

300
111 245 844422933
103 173 980761620
210 18 509066965
36 51 134507716
264 28 523343821
249 88 748193505
30 46 832843261
286 33 489900279
125 288 575144383
106 87 191375234
259 126 882094013
10 57 842095866
73 65 254207339
175 280 353530327
21 145 883665290
130 110 818300025
137 48 259121083
0 102...

output:

156555229

result:

ok single line: '156555229'

Test #9:

score: 5
Accepted
time: 1ms
memory: 3744kb

input:

292
37 89 397871374
184 205 437399619
14 234 93902029
40 155 84065200
12 60 367994608
143 35 623301168
125 0 307800516
68 281 653696611
146 260 978361615
177 79 385187016
251 192 369734594
245 159 471356654
109 53 96376804
248 103 681417305
85 288 837771859
25 110 145156090
129 46 874442695
252 249 ...

output:

702681209

result:

ok single line: '702681209'

Test #10:

score: 5
Accepted
time: 1ms
memory: 3808kb

input:

285
93 162 959772147
32 172 751202610
173 257 284177666
199 112 94146918
80 117 514639361
245 265 282507802
135 109 829039102
53 38 832201899
166 245 984506327
247 224 843352696
4 98 415992963
189 33 989751728
117 153 801360684
106 213 848238622
119 77 300949830
177 29 951903134
110 27 991808126
102...

output:

281677588

result:

ok single line: '281677588'

Test #11:

score: 5
Accepted
time: 1ms
memory: 4040kb

input:

300
238 117 820410457
230 235 506467445
200 74 653603782
62 76 485420791
105 275 392365065
20 121 28250604
203 87 723682049
109 151 342880635
133 79 302983289
47 297 671031835
257 299 444969934
255 116 860542983
91 92 332672418
205 280 290258390
103 160 769766288
106 137 789215359
159 204 831106721
...

output:

144479203

result:

ok single line: '144479203'

Test #12:

score: 5
Accepted
time: 1ms
memory: 3856kb

input:

298
157 32 579243060
277 30 236601044
95 45 746850490
123 94 873131928
185 95 376156675
66 150 606904039
262 124 953899592
219 279 373193513
152 99 546195756
113 100 936194271
216 240 22619249
38 110 395200927
89 55 159263634
265 77 151240149
90 232 529211969
88 177 115952104
43 208 657967542
196 45...

output:

75917669

result:

ok single line: '75917669'

Test #13:

score: 5
Accepted
time: 0ms
memory: 3768kb

input:

300
86 72 35281851
86 65 772642113
86 85 267144561
68 86 237759697
225 86 275794715
188 86 708990293
86 224 212292280
61 86 139649599
141 86 852035124
131 86 522883805
62 86 374119946
86 107 661877081
218 86 365176681
14 86 676939669
86 254 678988772
86 189 741173114
86 175 101646645
86 10 776575255...

output:

970519677

result:

ok single line: '970519677'

Test #14:

score: 5
Accepted
time: 1ms
memory: 3840kb

input:

296
167 280 308339229
42 120 44980047
172 173 31087131
280 172 346584469
68 172 765593132
172 11 55592625
172 60 294200085
172 177 829489003
172 26 368114672
172 6 906646562
239 172 311081319
199 172 89488635
264 172 782569720
172 53 614220967
172 192 111994073
70 172 348033132
172 37 5375089
10 108...

output:

685676493

result:

ok single line: '685676493'

Test #15:

score: 5
Accepted
time: 1ms
memory: 3916kb

input:

299
219 189 428591428
214 280 645468138
239 124 44092787
278 109 973174819
229 28 708387042
118 105 231265201
106 23 115324206
127 163 182711436
61 68 171248721
67 218 585337538
198 30 576082156
147 49 179613791
109 244 356639356
122 205 714546250
179 207 831521336
292 188 754667151
91 55 962847082
...

output:

442304238

result:

ok single line: '442304238'

Test #16:

score: 5
Accepted
time: 1ms
memory: 4056kb

input:

300
72 138 240810351
80 111 534427405
105 137 731389559
86 95 740641088
86 126 67440531
151 147 975723723
84 98 889126297
60 37 235430076
98 236 462897489
183 146 446541268
42 135 730090491
92 259 6083997
189 161 972025910
3 29 546634976
53 270 249844443
28 122 103308828
105 275 560940747
121 124 94...

output:

51045998

result:

ok single line: '51045998'

Test #17:

score: 5
Accepted
time: 0ms
memory: 3900kb

input:

298
15 284 446739499
274 218 9244552
64 69 913186698
79 63 70124148
253 46 192851114
165 30 798777080
30 123 824050137
199 104 363328962
23 70 471441
170 54 206153629
18 49 203147626
83 136 841021519
158 184 342247212
72 139 144579819
237 6 976320498
235 224 141859373
169 39 844270142
231 273 615291...

output:

874031476

result:

ok single line: '874031476'

Test #18:

score: 5
Accepted
time: 1ms
memory: 3812kb

input:

300
211 34 999999974
255 27 999999997
50 98 999999974
16 21 999999946
207 243 999999999
39 64 999999983
279 79 999999975
95 248 999999960
69 276 999999977
94 6 999999960
137 281 999999969
127 49 999999945
122 72 999999958
124 63 999999991
125 52 999999963
152 92 999999994
26 120 999999989
29 275 999...

output:

558463020

result:

ok single line: '558463020'

Subtask #2:

score: 6
Accepted

Dependency #1:

100%
Accepted

Test #19:

score: 6
Accepted
time: 4ms
memory: 5288kb

input:

3987
1834 2601 895910969
1701 1884 820508615
3406 1155 439833658
2977 3131 370614789
617 2254 829077229
1648 1576 977756493
597 2928 624126121
1165 3147 11258087
3888 2644 341340941
3007 2676 281856885
3971 957 644422867
3791 1181 166275464
3089 2273 36236019
1918 1080 747406617
3032 2602 102478217
...

output:

695949490

result:

ok single line: '695949490'

Test #20:

score: 6
Accepted
time: 4ms
memory: 5408kb

input:

3996
2787 2080 999999558
3557 3990 999999513
1092 476 999999510
3925 539 999999701
2334 2431 999999969
895 152 999999232
219 3637 999999392
2547 2072 999999641
356 3936 999999660
741 3794 999999597
554 1962 999999246
1562 847 999999437
2515 3167 999999541
1793 2493 999999388
2723 1175 999999976
2394...

output:

274545286

result:

ok single line: '274545286'

Test #21:

score: 6
Accepted
time: 6ms
memory: 4772kb

input:

3929
2164 3410 1
1115 3069 1
313 571 1
1913 135 1
739 3902 1
3735 1024 1
1888 2039 1
2732 2069 1
276 3073 1
3568 1533 1
2550 3456 1
1519 3224 1
3692 463 1
3013 2755 1
104 2875 1
2838 926 1
1755 880 1
1263 1285 1
2823 492 1
2920 2177 1
3369 1547 1
527 1876 1
416 3588 1
2985 3903 1
3566 454 1
3438 244...

output:

130042608

result:

ok single line: '130042608'

Test #22:

score: 6
Accepted
time: 7ms
memory: 4848kb

input:

3979
1701 2739 947
550 1740 148
698 3394 439
998 1930 516
2860 789 927
3189 1474 727
708 525 93
3380 2998 356
1170 3170 161
3273 441 367
2735 912 327
3676 1798 652
2147 2986 902
374 1300 176
1209 2051 994
2466 2554 652
2952 1243 582
1283 3491 396
3230 3169 323
1357 2960 963
2061 2863 486
374 1551 74...

output:

477691640

result:

ok single line: '477691640'

Test #23:

score: 6
Accepted
time: 6ms
memory: 4744kb

input:

3993
129 1932 486250
3451 3517 971847
1040 2697 612116
2857 2720 474764
2266 1736 25882
608 1032 505927
885 2105 392299
1919 2570 296078
897 799 762212
3365 2413 202700
1016 356 738055
1782 1920 347257
3411 1463 42033
1517 3437 239957
2215 2285 472713
2088 2204 397307
64 1841 65633
2112 2683 695743
...

output:

260910030

result:

ok single line: '260910030'

Test #24:

score: 6
Accepted
time: 3ms
memory: 5032kb

input:

4000
102 66 280319606
889 2757 123671658
573 410 214275598
1812 1239 562948670
3870 2162 811676687
3666 3927 782714296
743 1959 698091997
3631 1350 693401332
1711 3285 823728351
3648 67 738528891
2207 210 876427103
3115 2668 374409224
3736 1282 355828430
255 1050 984348990
1204 1133 399430224
1924 1...

output:

320372497

result:

ok single line: '320372497'

Test #25:

score: 6
Accepted
time: 9ms
memory: 4840kb

input:

3999
2915 2669 358447038
3538 1529 848338205
1238 1652 883628661
2570 2404 223452927
799 3024 713067679
3364 1135 944572237
1115 1024 910103338
3191 2454 774565382
1908 486 217064756
2637 1209 971634195
1318 634 448430962
1541 1145 290974969
802 2090 33398467
2463 2097 270639399
131 1103 813548390
9...

output:

291075730

result:

ok single line: '291075730'

Test #26:

score: 6
Accepted
time: 6ms
memory: 4788kb

input:

3991
3043 3747 72450807
1035 2439 847359979
992 3356 367969130
2460 2892 203363882
1910 3198 819770022
552 2675 346346980
2432 2936 540637143
190 2609 410257275
2453 3575 355529268
3880 240 12331157
3785 3424 117046626
308 3405 307714020
1833 1500 713642516
2163 3286 125103861
2959 3314 131450008
16...

output:

383646236

result:

ok single line: '383646236'

Test #27:

score: 6
Accepted
time: 6ms
memory: 4868kb

input:

3992
3278 133 82819135
1138 1628 883942927
1518 1562 287462306
3906 2285 844307305
1123 3665 401186676
3421 2844 717868422
3912 2599 449585462
1058 204 196625144
2303 3869 74773481
3479 100 566381291
2638 3113 454696105
2492 2568 324166296
458 1181 267475836
2144 735 853935672
2661 1297 546999171
84...

output:

41229967

result:

ok single line: '41229967'

Test #28:

score: 6
Accepted
time: 2ms
memory: 5436kb

input:

3988
892 3476 65536289
1143 2155 78839637
2281 3630 277410807
945 2594 77206150
2323 1428 493894594
2462 190 55532886
3692 3325 33104595
1172 3873 760727613
314 1369 239234837
3747 3958 475742505
546 452 197939417
2821 2508 957723778
3234 3065 101320967
3010 2914 19947142
985 959 567195224
2766 1066...

output:

855099036

result:

ok single line: '855099036'

Test #29:

score: 6
Accepted
time: 4ms
memory: 5472kb

input:

3994
2898 1643 747208501
2589 2491 449233552
1952 108 167973884
809 516 700981441
2928 1529 486022338
996 3324 91061838
195 3011 976655798
2835 2673 861780462
255 1432 112332747
454 3339 275103950
3446 2406 525262110
698 2274 21319511
1906 2757 242526935
2008 3900 78216819
1939 3454 55978905
1478 47...

output:

926381062

result:

ok single line: '926381062'

Test #30:

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

input:

3999
3472 781 632697752
3913 3472 745809874
1012 3472 486404015
3472 1596 224135418
3472 391 174124536
2633 3472 668535346
3472 3820 309058783
3472 2891 828286963
3472 3137 207500886
3827 3472 55431764
3472 3426 830682140
3472 30 17107264
2734 3472 472803946
3472 1632 745035389
3472 1403 940800825
3...

output:

507959495

result:

ok single line: '507959495'

Test #31:

score: 6
Accepted
time: 4ms
memory: 4732kb

input:

4000
174 2644 47696590
169 2644 58166462
956 2644 460771360
2644 1815 520855324
3501 2644 986792612
1093 2644 506436717
966 2644 738217798
900 2644 925731103
2644 3182 714219046
2448 1924 763935310
2644 782 834386632
2516 2644 120793747
2644 1931 124334474
2644 2152 579180059
2644 2521 623628522
164...

output:

433113345

result:

ok single line: '433113345'

Test #32:

score: 6
Accepted
time: 5ms
memory: 4864kb

input:

3991
1764 2443 439882798
426 3349 992175122
2547 235 940448392
3812 2967 72708965
3066 3137 686248279
1981 112 936946216
3045 2145 956855424
3312 649 533586589
2188 2462 64477706
3422 1113 95138241
2078 3202 127346842
901 2425 482329548
3535 2014 303899910
2730 1390 831016026
2128 1974 105603514
17 ...

output:

134545619

result:

ok single line: '134545619'

Test #33:

score: 6
Accepted
time: 6ms
memory: 4872kb

input:

3989
583 3061 706872124
3869 629 162035787
1917 2195 400147505
115 541 844975714
3513 2008 667322023
1355 2871 481525925
1807 2969 702729114
900 2818 55373170
1638 2513 294382411
2375 3093 485828042
1605 507 778393073
3304 3618 865154341
3053 2947 676091124
2773 2732 941702348
1365 3111 167647093
17...

output:

277990633

result:

ok single line: '277990633'

Test #34:

score: 6
Accepted
time: 4ms
memory: 5008kb

input:

4000
1300 3993 2591399
3255 1495 614218131
24 3304 493255228
1569 2170 381311184
3026 3582 712596783
1738 3970 293387004
3384 781 361133661
2795 2371 93547297
58 698 879035234
573 2317 31056223
2188 3953 11876411
2899 3835 395815431
1436 1529 317267294
2116 2218 285301158
1012 1141 909178003
2762 20...

output:

794389140

result:

ok single line: '794389140'

Test #35:

score: 6
Accepted
time: 5ms
memory: 5096kb

input:

3996
2148 549 999999448
3741 562 999999858
3245 255 999999581
3611 762 999999421
1088 36 999999288
65 38 999999563
567 93 999999882
3413 841 999999485
3745 1149 999999267
3707 3415 999999905
2468 974 999999999
2085 2633 999999998
3339 1978 999999753
805 1857 999999996
3088 542 999999810
2596 3051 99...

output:

390647746

result:

ok single line: '390647746'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 10
Accepted
time: 663ms
memory: 67352kb

input:

249494
137621 137622 1
198127 198128 1
117358 117359 1
155777 155778 1
112742 112743 1
235668 235669 1
20632 20622 1
41333 41334 1
170699 170692 1
130269 130268 1
137208 137207 1
37791 37767 1
130187 130178 1
89795 89817 1
91408 91359 1
243301 243574 1
22017 22018 1
116466 116467 1
160094 160095 1
4...

output:

714152529

result:

ok single line: '714152529'

Test #37:

score: 10
Accepted
time: 686ms
memory: 67540kb

input:

249988
60491 60489 6472
121939 121913 6308
173388 173387 8137
226065 226066 8977
124350 124349 2792
112200 112199 428
125721 125743 5363
23768 23767 75
153585 153587 2454
17575 17576 5720
94114 94113 9201
42276 42275 6155
76932 76933 8614
159668 159667 6494
146337 146336 9800
141314 141315 4256
1985...

output:

540610742

result:

ok single line: '540610742'

Test #38:

score: 0
Wrong Answer
time: 743ms
memory: 67612kb

input:

249949
110548 110549 662920624
134621 134620 922164993
29294 29349 82667705
63017 63018 181551959
141206 141207 58318778
219568 219569 243357791
228521 228523 273934957
110836 110835 422662545
81151 81169 946526999
142445 142444 137916420
105444 105443 281588867
92357 92356 245508044
10069 10068 879...

output:

631222295

result:

wrong answer 1st lines differ - expected: '344332803', found: '631222295'

Subtask #4:

score: 0
Wrong Answer

Test #48:

score: 0
Wrong Answer
time: 627ms
memory: 101476kb

input:

249876
133760 107716 545485826
57898 35556 542825636
159559 78814 588304799
9037 105623 735470824
242676 240955 258616989
58653 143501 194781066
36591 97835 699376285
95049 123298 35300031
91751 203920 865003045
53908 18382 376452723
211462 200538 638209824
48693 89388 132147210
238496 151742 322726...

output:

966823055

result:

wrong answer 1st lines differ - expected: '497361697', found: '966823055'

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%