QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#770017#7905. Ticket to RideguosounTL 2858ms4320kbC++171.8kb2024-11-21 20:17:282024-11-21 20:17:29

Judging History

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

  • [2024-11-21 20:17:29]
  • 评测
  • 测评结果:TL
  • 用时:2858ms
  • 内存:4320kb
  • [2024-11-21 20:17:28]
  • 提交

answer

#include <bits/stdc++.h>
using ll = long long;

struct hope {
  int bk;
  ll bkv;
  std::vector<int> fa, nx;
  std::vector<ll> d;
  int find(int u) {
    while (fa[u] != u) u = fa[u] = fa[fa[u]];
    return u;
  }
  hope(ll x) { bk = 0, bkv = x, fa = {0}, nx = {0}, d = {0}; }
  void push_back(ll v) {
    int idx = fa.size();
    fa.push_back(idx);
    if (bkv >= v) {
      fa[idx] = idx - 1;
      nx.push_back(0), d.push_back(0);
      return;
    }
    nx[bk] = idx, d[bk] = v - bkv, bk = idx, bkv = v;
    nx.push_back(idx), d.push_back(0);
  }
  void add(int p, ll v) {
    assert(p < (int)fa.size());
    p = find(p);
    if (p == bk) {
      bkv += v;
      return;
    }
    d[p] -= v;
    while (d[p] <= 0) {
      if (nx[p] == nx[nx[p]]) {
        bkv = bkv - d[p];
        bk = p;
        fa[nx[p]] = nx[p] - 1;
        d[p] = 0, nx[p] = p;
        break;
      }
      d[p] += d[nx[p]];
      fa[nx[p]] = nx[p] - 1;
      nx[p] = nx[nx[p]];
    }
  }
  ll query() { return bkv; }
};


void mian() {
  int n, m;
  std::cin >> n >> m, ++n;
  std::vector<std::vector<std::pair<int, int>>> lf(n + 1);
  while (m--) {
    int l, r, v;
    std::cin >> l >> r >> v;
    lf[r + 1].push_back({l + 1, v});
  }
  std::vector<ll> dp(n + 1, -1e18);
  dp[0] = 0;
  std::vector<ll> ans;
  for (int i = 1; i < n; i++) {
    auto tmp = dp;
    dp.assign(n + 1, -1e18);
    hope h(tmp[0]);
    for (int j = 1; j <= n; j++) {
      for (auto [l, v] : lf[j]) {
        h.add(l - 1, v);
      }
      dp[j] = h.query();
      h.push_back(tmp[j]);
    }
    ans.push_back(dp.back());
  }
  std::reverse(ans.begin(), ans.end());
  for (auto i : ans) std::cout << i << ' ';
  std::cout << '\n';
}
int main() { 
  std::cin.tie(0)->sync_with_stdio(0); 
  int t;
  std::cin >> t;
  while (t--) mian();
}
/*
1 2
4 4

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

input:

2
4 3
0 2 3
3 4 2
0 3 1
3 1
1 3 100

output:

2 3 5 6 
0 100 100 

result:

ok 2 lines

Test #2:

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

input:

1000
2 9
0 2 396628655
1 2 268792718
0 2 16843338
1 2 717268783
0 1 693319712
0 1 856168102
1 2 407246545
1 2 527268921
0 1 536134606
6 2
2 5 451394766
0 5 695984050
9 7
0 6 73936815
2 9 505041862
4 5 223718927
5 7 179262261
3 5 449258178
0 5 493128
0 3 994723920
6 6
3 5 433389755
2 4 773727734
4 5 ...

output:

2085622420 4419671380 
0 0 451394766 451394766 1147378816 1147378816 
223718927 672977105 994723920 1218442847 1668194153 1742130968 1921393229 1921393229 2426435091 
127680943 773727734 1334798432 2227456393 2675644351 2675644351 
976357580 1594205360 2103791342 2721639122 3241574409 3936588085 418...

result:

ok 1000 lines

Test #3:

score: 0
Accepted
time: 23ms
memory: 3788kb

input:

100
99 83
33 47 476927808
66 71 627937890
14 84 645468307
89 96 588586447
24 43 710156469
5 85 11308832
46 56 208427221
8 62 726478310
34 74 135993561
10 74 851555000
49 52 946936715
34 39 771067386
76 96 16233727
29 34 612324591
71 86 591062856
24 94 670656770
21 59 629389147
48 67 860046161
34 86 ...

output:

131347174 276869285 946936715 1078283889 1223806000 1355153174 1699007616 1969489139 1975876901 2246358424 2246358424 2721560040 2721560040 2998429325 3096939475 3110534651 3349497930 3724362755 4882915593 5014262767 5871777743 6003124917 6778566352 7530637253 7661984427 7661984427 7661984427 815857...

result:

ok 100 lines

Test #4:

score: 0
Accepted
time: 21ms
memory: 3592kb

input:

100
95 96
5 89 124321145
33 77 773363571
1 94 468188689
35 84 284660056
0 92 245485733
8 57 596788519
10 93 59267682
49 90 450355885
76 84 190264757
84 87 797853944
4 41 437909067
73 74 532217941
5 8 999048465
0 95 143672912
12 55 290639413
6 86 899138487
35 36 508500258
21 68 843227286
0 94 9058576...

output:

1272369836 1903674815 2748981113 2925702770 2951858051 3748029578 3924751235 3950906516 4545883522 4735350922 4912072579 5329793703 5734399387 5911121044 5946764048 6532253331 6708974988 6735130269 7316163512 7492885169 7519040450 7674437726 8074553640 8251275297 8277430578 8432827854 8609549511 871...

result:

ok 100 lines

Test #5:

score: 0
Accepted
time: 19ms
memory: 3588kb

input:

100
86 92
68 73 730593611
9 11 314305867
63 64 699021890
6 11 787982418
69 72 421876106
31 37 449645826
76 82 238642240
28 31 467098727
22 23 333165290
34 42 645351348
34 38 618797828
10 14 164751728
30 34 88922825
80 83 936426204
72 77 383499583
46 51 128937895
49 57 437892230
50 56 692509142
14 19...

output:

987528833 1943214328 2850671579 3750797988 4594973746 5293995636 5939438559 6537351768 7295198258 8185806974 9093264225 9993390634 10837566392 11598929402 12443105160 13088548083 13686461292 14053565377 14974356349 15874482758 16718658516 17480021526 18324197284 18999222924 19760585934 20604761692 2...

result:

ok 100 lines

Test #6:

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

input:

100
81 84
34 73 564718673
8 50 657489855
21 65 373282330
11 54 667584659
18 58 850348020
7 47 593942770
18 63 903492853
10 55 897217447
14 59 211655411
19 55 409828915
13 55 29599937
8 50 288981803
36 72 845363118
29 71 245960658
5 51 704846394
4 46 990499066
4 39 857206811
13 45 623803672
3 35 7771...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1579851645 1688016338 1688016338 2828615820 2936780513 2936780513 3154788497 3947417123 4844055621 5416102236 6085851635 7381675290 8016930442 8871843928 10210533499 11498381971 12614109011 13901957483 13901957483 14749882994 16086529293 ...

result:

ok 100 lines

Test #7:

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

input:

100
90 84
8 90 544067926
15 90 295641139
1 85 902318577
9 90 987378388
7 88 133595743
0 90 33207011
0 90 418600362
9 85 767527655
2 89 235369723
1 90 439147697
1 83 145434750
2 88 708179173
8 86 751546514
0 81 405752009
2 88 26193206
5 77 587219021
0 86 541362608
7 84 965163611
7 89 890265728
4 83 6...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 587219021 1031406396 1523585030 1523585030 1523585030 2678374149 3141571642 4854384801 6126474244 8978806560 11608076036 14734165356 16508213836 20090070737 2...

result:

ok 100 lines

Test #8:

score: 0
Accepted
time: 188ms
memory: 3868kb

input:

10
851 868
679 693 378192988
267 399 343857831
131 748 576579017
575 787 12204822
499 576 826908873
155 724 737312468
623 795 638740575
172 407 637837864
11 283 259084035
186 273 908657968
85 417 701461051
184 807 832409248
152 281 213019511
109 435 715286463
524 814 347540017
60 664 594004384
504 7...

output:

891385001 1219204255 1219204255 1516678750 1887587817 2215407071 2215407071 2512881566 2740735819 2753391924 3038210314 3050866419 3313797806 3541652059 3612342669 3839126554 3909817164 4280726231 4608545485 4608545485 4906019980 5133874233 5146530338 5465480444 5465480444 5762954939 5990809192 6003...

result:

ok 10 lines

Test #9:

score: 0
Accepted
time: 164ms
memory: 3636kb

input:

10
913 863
98 634 432130709
48 800 479851779
69 906 186774359
416 789 756411639
274 327 906033133
459 906 362923880
790 809 670510137
91 866 875171159
21 903 956639323
107 165 590430725
55 510 156036789
98 828 45500146
439 482 655902695
138 617 28938721
833 856 624732370
77 892 535654097
3 868 23177...

output:

418488187 966063397 1384551584 1826025664 2244513851 2542625088 2801740920 3099852157 3375801952 3634917784 3933029021 4197648871 4456764703 4754875940 4754875940 4822625709 5120736946 5227862880 5525974117 5525974117 5713687947 5891835123 6106424028 6156877401 6186674887 6484786124 6579410968 68775...

result:

ok 10 lines

Test #10:

score: 0
Accepted
time: 161ms
memory: 3600kb

input:

10
874 958
483 551 631858791
601 659 30225807
759 777 630132600
772 835 916633496
246 314 538628510
208 251 615840950
700 785 523731402
413 436 643299496
201 228 161288468
401 472 997421612
704 762 228097972
447 466 375836694
350 365 580675905
294 306 39388076
221 290 285200936
440 454 347252805
548...

output:

957614597 1612685590 2250760006 2881495320 3420983646 3734724339 4242003786 4555744479 5035470860 5349211553 5772752393 6086493086 6482898460 6796639153 7170903160 7484643853 7881049227 8194789920 8563367427 8877108120 9211409411 9525150104 9808380749 9998025568 10311766261 10594996906 10721590662 1...

result:

ok 10 lines

Test #11:

score: 0
Accepted
time: 114ms
memory: 3668kb

input:

10
961 924
90 532 71550121
310 699 446173607
415 936 223219513
6 531 905549873
322 876 879397647
339 789 150918417
199 612 126195703
180 667 404334728
258 714 879226371
314 875 62611196
162 658 204244054
142 689 614679390
363 887 544546349
302 846 546951131
433 951 529946158
347 882 343766215
11 542...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 10 lines

Test #12:

score: 0
Accepted
time: 79ms
memory: 3868kb

input:

10
898 919
8 797 50899375
29 891 494390299
7 893 602512657
56 882 930376306
53 827 162645369
45 886 590182657
61 824 346335916
116 895 129420744
0 898 462749196
4 887 532121466
12 743 760270355
22 854 738909464
3 876 300986641
1 843 561518289
105 852 851292970
27 889 940486169
20 884 120755595
88 89...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 10 lines

Test #13:

score: 0
Accepted
time: 2858ms
memory: 4160kb

input:

1
10000 10000
4243 4355 678092074
417 1119 480129711
1423 4497 648552857
3970 7187 341033928
3562 9406 262707175
2221 7546 593247929
8687 9420 19219689
1203 8523 264021888
1234 2415 374691722
2826 7687 139199900
7658 8431 780718641
7761 8218 852678681
3240 7544 193841776
1110 9353 662982105
5712 938...

output:

588915533 672758678 1261674211 1261674211 1544748874 1867906031 1867906031 2150980694 2296343133 2369281050 2579417796 2652355713 2860989061 2866405141 3144063724 3289426163 3362364080 3572500826 3645438743 3790801182 3859488171 4073875845 4142562834 4283508095 4360863190 4566582758 4643937853 47213...

result:

ok single line: '588915533 672758678 1261674211...29 4979636530079 4980177042778 '

Test #14:

score: 0
Accepted
time: 2670ms
memory: 4320kb

input:

1
10000 10000
6563 6718 205472596
4591 9659 475725571
1507 9704 807626376
3641 7881 799005138
183 9439 28519651
6822 7271 926087759
5222 6087 884632001
2210 2277 325917815
260 1122 945273281
2746 7330 120115078
4623 4842 325811390
3853 8463 973977593
2504 7276 135612374
1406 9852 295818637
1578 2542...

output:

996020286 1897811392 2545421008 2545421008 3034660540 3056353513 3056353513 3545593045 3545593045 3545593045 3891170292 3954343297 3976036270 4402102797 4465275802 4465275802 4530985758 4810853049 4832546022 5038611976 5321785554 5321785554 5387495510 5450668515 5469055201 5600314594 5958294733 5958...

result:

ok single line: '996020286 1897811392 254542100...79 4997402004439 5005758110695 '

Test #15:

score: -100
Time Limit Exceeded

input:

1
10000 10000
5404 6322 715910077
2196 2974 714311457
9670 9954 795453872
5071 5850 864153416
654 1514 851872013
8786 9137 46967238
7843 8400 18379890
1437 1664 147962143
4304 4688 800880165
3156 3210 73542745
1502 2177 469337815
4219 5217 892643689
3726 4497 350048955
4735 5731 209961438
2221 2935 ...

output:

762317317 1185941641 1628033444 2051657768 2425094776 2787474698 3101235022 3463614944 3751448241 4065208565 4427588487 4657746870 5007695118 5333887116 5565286722 5913993747 6188958060 6471585351 6769064691 6994040286 7326656295 7492155656 7849111230 8014610591 8332861073 8498360434 8637855686 8909...

result: