QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303578 | #7950. Lucky Draws | PPP# | AC ✓ | 150ms | 5660kb | C++17 | 2.4kb | 2024-01-12 19:07:12 | 2024-01-12 19:07:13 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef long double ld;
int n, k;
const int maxN = 2e4 + 10;
ll dp[maxN];
ll ndp[maxN];
const int INF = 1e9;
ll lazy[4 * maxN];
ll mn[4 * maxN];
void apply(int v, ll x) {
lazy[v] += x;
mn[v] += x;
}
void push(int v, int tl, int tr) {
if (tl != tr && lazy[v] != 0) {
apply(2 * v, lazy[v]);
apply(2 * v + 1, lazy[v]);
}
lazy[v] = 0;
}
void merge(int v) {
mn[v] = min(mn[2 * v], mn[2 * v + 1]);
}
void upd(int v, int tl, int tr, int l, int r, ll x) {
if (tr < l || tl > r) return;
if (l <= tl && tr <= r) {
apply(v, x);
return;
}
push(v, tl, tr);
int tm = (tl + tr) / 2;
upd(2 * v, tl, tm, l, r, x);
upd(2 * v + 1, tm + 1, tr, l, r, x);
merge(v);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
cin >> n >> k;
vector<int> S;
S.emplace_back(-1e7);
vector<pair<int,int>> ints;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
ints.emplace_back(a, b);
S.emplace_back(a);
S.emplace_back(b);
}
S.emplace_back(1e7);
sort(S.begin(), S.end());
S.erase(unique(S.begin(), S.end()), S.end());
for (int p = 0; p < S.size(); p++) {
dp[p] = INF;
}
vector<vector<int>> D(S.size());
for (auto& it : ints) {
int where = lower_bound(S.begin(), S.end(), it.second) - S.begin();
int ps = lower_bound(S.begin(), S.end(), it.first) - S.begin();
D[where].emplace_back(ps);
}
dp[0] = 0;
k++;
k = min(k, (int)S.size() - 1);
for (int it = 0; it < k; it++) {
ndp[0] = INF;
for (int z = 0; z <= 4 * S.size() + 5; z++) {
mn[z] = INF;
lazy[z] = 0;
}
upd(1, 0, S.size() - 1, 0, 0, dp[0] -INF);
for (int t = 1; t < S.size(); t++) {
for (int x : D[t - 1]) {
upd(1, 0, S.size() - 1, 0, x - 1, +1);
}
ndp[t] = mn[1];
upd(1, 0, S.size() - 1, t, t, dp[t] - INF);
}
for (int t = 0; t < S.size(); t++) {
dp[t] = ndp[t];
}
}
cout << n - dp[S.size() - 1];
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
5 2 1 2 1 4 3 6 4 7 5 6
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
3 2 2 4 1 3 3 5
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
4 1 2 3 1 1 4 5 4 5
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
7 2 5 6 7 9 7 7 1 4 2 3 4 7 4 7
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 128ms
memory: 5344kb
input:
10000 50 -16187 -16186 743439 743441 -995450 -995449 921242 921242 -287646 -287644 110263 110264 650110 650110 897150 897151 262837 262839 935191 935193 6079 6080 815160 815162 -624776 -624774 -782088 -782086 486051 486052 -704289 -704287 -592330 -592329 -943804 -943803 43046 43047 -896912 -896910 -...
output:
100
result:
ok single line: '100'
Test #6:
score: 0
Accepted
time: 140ms
memory: 5660kb
input:
10000 50 39778 39796 7765 7768 95957 95972 -92200 -92178 -67044 -67014 856 871 -95402 -95380 -29447 -29418 77170 77191 -50433 -50421 -18466 -18446 47582 47583 89872 89873 19175 19205 -46181 -46175 30461 30465 -83893 -83891 -87464 -87450 -92490 -92469 -95035 -95008 -60182 -60165 -9191 -9191 -61912 -6...
output:
265
result:
ok single line: '265'
Test #7:
score: 0
Accepted
time: 37ms
memory: 3864kb
input:
1000 200 1255 1300 4000 4019 4062 4090 4733 4781 1597 1684 6391 6394 4958 5012 3552 3552 3136 3182 2597 2664 7296 7344 5596 5685 8676 8745 1897 1995 6009 6029 2548 2553 410 460 4985 5046 2520 2581 8270 8342 1376 1447 1317 1367 6561 6623 5059 5114 8435 8444 4773 4823 6756 6825 3674 3769 8881 8893 278...
output:
948
result:
ok single line: '948'
Test #8:
score: 0
Accepted
time: 89ms
memory: 3808kb
input:
1000 500 -27340 -27339 41144 41145 -31978 -31977 13653 13657 37912 37913 -82824 -82824 -91670 -91670 -85311 -85309 -49781 -49778 -30498 -30495 -33143 -33143 3794 3798 62829 62833 22827 22830 99614 99618 -54630 -54628 -5781 -5780 40734 40734 -13748 -13747 41681 41681 -49625 -49622 -42947 -42947 6610 ...
output:
516
result:
ok single line: '516'
Test #9:
score: 0
Accepted
time: 97ms
memory: 3864kb
input:
1000 500 -3496 -3464 2153 2307 -5775 -5724 -7511 -7499 -4073 -3773 2240 2394 -2877 -2580 2835 3331 5980 6318 751 1043 5623 5963 866 1134 -1848 -1572 8095 8452 -7239 -7039 2369 2413 -5821 -5675 4954 5039 -6311 -6018 -6863 -6857 -3559 -3401 -7508 -7438 7374 7538 -4953 -4713 -144 1 -9359 -8940 -8579 -8...
output:
1000
result:
ok single line: '1000'
Test #10:
score: 0
Accepted
time: 70ms
memory: 3816kb
input:
1000 500 814 814 8756 8756 2118 2118 5308 5309 9638 9638 158 159 70 70 3511 3512 3144 3145 269 269 5539 5540 8941 8942 1435 1436 9269 9270 9919 9920 1985 1985 8847 8847 1030 1030 8502 8503 7582 7582 6360 6360 5189 5190 6449 6450 7108 7109 1570 1571 4431 4432 1196 1197 3287 3287 1894 1894 6115 6116 8...
output:
596
result:
ok single line: '596'
Test #11:
score: 0
Accepted
time: 10ms
memory: 3860kb
input:
1000 50 711 739 -4064 -4064 -1532 -1528 1078 1098 -4675 -4664 -509 -484 -423 -408 2288 2295 4639 4654 -396 -393 -3122 -3101 1860 1864 3974 3998 -823 -814 -1514 -1486 1518 1524 -4892 -4888 2015 2040 1683 1693 2805 2813 3535 3537 1471 1489 -1526 -1509 3380 3391 -4292 -4279 643 668 -1456 -1442 1378 138...
output:
252
result:
ok single line: '252'
Test #12:
score: 0
Accepted
time: 44ms
memory: 4120kb
input:
2000 100 6105 6141 950 965 -8714 -8620 -6719 -6698 3336 3374 -3881 -3845 2465 2490 6007 6008 -5842 -5764 1982 1986 8489 8589 1213 1224 -3562 -3546 -178 -128 7670 7728 3314 3385 5661 5705 5411 5456 2832 2845 7540 7588 6943 6991 9884 9897 -9728 -9703 -170 -98 8378 8458 6165 6230 -457 -424 3743 3805 14...
output:
920
result:
ok single line: '920'
Test #13:
score: 0
Accepted
time: 126ms
memory: 4512kb
input:
5000 100 -32309 -32305 -14221 -14178 2909 2940 -23269 -23269 48439 48457 -93061 -93044 -97541 -97510 54476 54516 16328 16372 66277 66313 34364 34396 -44802 -44796 -94411 -94407 56356 56361 17649 17656 -39918 -39908 45204 45215 22938 22975 -16544 -16536 35609 35614 -72296 -72263 80886 80911 -33735 -3...
output:
416
result:
ok single line: '416'
Test #14:
score: 0
Accepted
time: 5ms
memory: 3728kb
input:
500 100 578 579 361 362 -772 -769 864 864 -300 -299 -275 -272 851 852 962 963 -636 -633 103 105 -50 -50 -358 -355 -754 -751 -215 -215 626 628 407 410 -27 -25 637 637 950 952 -604 -604 734 737 725 728 -552 -551 944 944 952 953 -916 -913 158 161 -961 -958 -67 -64 -817 -815 372 373 -85 -83 -843 -841 -2...
output:
243
result:
ok single line: '243'
Test #15:
score: 0
Accepted
time: 136ms
memory: 4940kb
input:
7000 70 489558 489681 83771 84235 766135 766920 742572 743390 400303 400800 188030 188443 788547 789313 666559 667311 655652 655896 285103 285347 428766 429006 713220 713941 440604 440860 100264 100745 701486 702373 193176 193841 971933 972901 922156 922715 476431 476818 124980 125219 270457 270472 ...
output:
674
result:
ok single line: '674'
Test #16:
score: 0
Accepted
time: 70ms
memory: 3804kb
input:
700 582 97421 97426 25468 25486 94444 94468 91505 91537 87588 87629 86178 86225 61643 61664 40105 40141 60492 60515 14255 14257 82766 82803 85040 85052 76280 76300 83342 83358 59649 59676 67986 68029 26507 26548 62283 62294 11430 11463 59607 59620 57201 57233 94928 94962 37927 37963 86484 86492 4003...
output:
699
result:
ok single line: '699'
Test #17:
score: 0
Accepted
time: 131ms
memory: 5464kb
input:
10000 50 -1000000 -999993 -999997 -999990 -999987 -999981 -999981 -999974 -999979 -999970 -999975 -999971 -999973 -999970 -999963 -999960 -999956 -999953 -999949 -999944 -999948 -999943 -999944 -999939 -999937 -999928 -999927 -999922 -999924 -999914 -999916 -999914 -999915 -999914 -999908 -999906 -9...
output:
217
result:
ok single line: '217'
Test #18:
score: 0
Accepted
time: 131ms
memory: 5456kb
input:
10000 50 -1000000 -999991 -999993 -999988 -999988 -999973 -999981 -999975 -999971 -999966 -999964 -999954 -999959 -999949 -999953 -999949 -999945 -999933 -999940 -999925 -999930 -999925 -999928 -999917 -999925 -999917 -999921 -999908 -999918 -999914 -999917 -999905 -999916 -999908 -999906 -999902 -9...
output:
308
result:
ok single line: '308'
Test #19:
score: 0
Accepted
time: 119ms
memory: 4572kb
input:
5000 100 -1000000 -999981 -999992 -999981 -999984 -999966 -999979 -999972 -999977 -999965 -999972 -999967 -999966 -999961 -999965 -999946 -999963 -999947 -999957 -999950 -999953 -999945 -999948 -999935 -999941 -999935 -999934 -999930 -999926 -999923 -999923 -999919 -999913 -999912 -999906 -999891 -9...
output:
531
result:
ok single line: '531'
Test #20:
score: 0
Accepted
time: 103ms
memory: 5348kb
input:
10000 40 -68033 -67768 -58016 -57796 -62750 -62334 -77626 -77369 -52688 -52400 -98635 -98478 -67178 -66799 -66094 -65983 -68566 -68279 -72694 -72338 -100151 -99825 -54029 -53790 -65096 -64993 -99628 -99399 -54202 -53883 -85504 -85312 -67013 -66921 -65101 -64863 -95054 -94914 -98172 -97813 -93575 -93...
output:
4000
result:
ok single line: '4000'
Test #21:
score: 0
Accepted
time: 81ms
memory: 4780kb
input:
10000 50 -91306 -91289 -92940 -92867 -99746 -99685 -95631 -95588 -96821 -96766 -95641 -95562 -92821 -92775 -99110 -99065 -93844 -93800 -94843 -94763 -99949 -99884 -94333 -94297 -91609 -91585 -97302 -97275 -90529 -90498 -98846 -98771 -100028 -99998 -98140 -98099 -94018 -93950 -93212 -93181 -91625 -91...
output:
5000
result:
ok single line: '5000'
Test #22:
score: 0
Accepted
time: 2ms
memory: 4024kb
input:
1000 10 760 848 1553 1640 600 649 -708 -678 -804 -788 275 315 -134 -133 -49 22 -419 -356 594 600 664 708 1178 1248 -331 -256 1989 2045 -739 -669 1576 1620 -841 -750 281 336 817 818 1867 1906 -704 -690 -111 -70 366 450 971 1045 1888 1940 200 201 268 304 -829 -790 -924 -886 -406 -379 -432 -400 -618 -5...
output:
321
result:
ok single line: '321'
Test #23:
score: 0
Accepted
time: 9ms
memory: 3820kb
input:
1000 40 6979 7391 -9400 -8765 1514 2070 7821 8080 2766 3210 10858 11303 16860 17276 -430 134 13826 14433 2573 3288 -2022 -1908 -1466 -821 19833 20155 -10063 -9920 -3216 -2940 15765 16158 8728 9115 -9443 -8540 881 1096 -2485 -1637 14765 15432 13623 14110 4610 5310 9531 10315 11576 12464 -3011 -2620 -...
output:
1000
result:
ok single line: '1000'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
100 5 105 106 124 126 143 146 100 102 123 127 144 147 128 130 103 106 128 131 123 127 100 101 140 141 119 122 135 135 120 122 119 121 139 140 113 116 124 127 125 127 98 102 119 122 123 126 105 105 128 131 108 110 123 127 99 100 144 147 103 105 120 121 134 137 103 105 129 130 114 115 123 126 100 100 ...
output:
50
result:
ok single line: '50'
Test #25:
score: 0
Accepted
time: 6ms
memory: 4128kb
input:
2000 10 -10168 -9769 -2550 -2343 -3086 -2972 7836 8037 9993 10159 -8614 -8300 -6704 -6468 933 1123 6414 6685 6362 6602 -2200 -1803 -10138 -9986 5330 5610 2310 2750 7316 7516 11251 11620 3944 4145 -7529 -7290 -9655 -9414 -4038 -3895 10384 10571 -4142 -3812 -8681 -8459 2349 2510 5419 5617 -44 202 -706...
output:
450
result:
ok single line: '450'
Test #26:
score: 0
Accepted
time: 24ms
memory: 4060kb
input:
2000 50 208507 210168 -2969 4336 255779 263053 75466 81750 107319 111600 398667 402663 176635 184409 96837 101418 18137 24812 255109 261911 -3056 1083 26324 30669 36082 42242 336994 343288 36110 42027 17697 22600 98405 100603 176183 184611 385605 390644 39932 40505 77033 82204 49588 54384 246251 250...
output:
1986
result:
ok single line: '1986'
Test #27:
score: 0
Accepted
time: 67ms
memory: 4784kb
input:
10000 40 5001 5002 7445 7446 3639 3640 9173 9174 9336 9337 8041 8042 1636 1637 2755 2756 4880 4881 3887 3888 4664 4665 6694 6695 3228 3229 7219 7220 5653 5654 2897 2898 2403 2404 9822 9823 234 235 8880 8881 9813 9814 541 542 744 745 466 467 9574 9575 1326 1327 5257 5258 3549 3550 5642 5643 4331 4332...
output:
80
result:
ok single line: '80'
Test #28:
score: 0
Accepted
time: 79ms
memory: 4852kb
input:
10000 50 9064 9065 5957 5958 7508 7509 7876 7877 5599 5600 5284 5285 727 728 7594 7595 6283 6284 2812 2813 7187 7188 442 443 3970 3971 8665 8666 5173 5174 5194 5195 1670 1671 4631 4632 4760 4761 1545 1546 5847 5848 8305 8306 3106 3107 8598 8599 4478 4479 894 895 365 366 4457 4458 756 757 6988 6989 2...
output:
100
result:
ok single line: '100'
Test #29:
score: 0
Accepted
time: 2ms
memory: 3776kb
input:
1000 10 914 915 759 760 54 55 56 57 186 187 107 108 529 530 551 552 217 218 266 267 40 41 816 817 528 529 236 237 863 864 467 468 204 205 879 880 232 233 702 703 9 10 260 261 584 585 173 174 89 90 643 644 355 356 956 957 163 164 612 613 695 696 208 209 767 768 0 1 806 807 878 879 474 475 792 793 166...
output:
20
result:
ok single line: '20'
Test #30:
score: 0
Accepted
time: 30ms
memory: 3780kb
input:
1000 300 31 32 820 821 572 573 690 691 673 674 20 21 123 124 506 507 296 297 433 434 37 38 805 806 305 306 186 187 781 782 299 300 987 988 948 949 758 759 859 860 802 803 275 276 606 607 58 59 268 269 446 447 354 355 745 746 462 463 665 666 795 796 104 105 712 713 858 859 229 230 372 373 418 419 949...
output:
600
result:
ok single line: '600'
Test #31:
score: 0
Accepted
time: 14ms
memory: 3872kb
input:
2000 50 1291 1292 1679 1680 41 42 1808 1809 126 127 1531 1532 1457 1458 235 236 1072 1073 462 463 275 276 437 438 1672 1673 163 164 296 297 243 244 470 471 1655 1656 1906 1907 358 359 888 889 925 926 766 767 168 169 1418 1419 344 345 1969 1970 141 142 624 625 588 589 1170 1171 1660 1661 734 735 1658...
output:
100
result:
ok single line: '100'
Test #32:
score: 0
Accepted
time: 123ms
memory: 5652kb
input:
10000 40 25307 82093 26537 42696 47910 47911 40360 40361 18699 95490 14770 14771 600 601 57800 57801 29670 29671 59020 59021 39000 47727 4400 4401 31310 31311 20300 20301 48790 48791 7460 7461 7250 7251 25550 25551 48170 48171 10488 63444 62801 80975 11166 94361 58540 58541 14980 14981 33370 33371 5...
output:
3374
result:
ok single line: '3374'
Test #33:
score: 0
Accepted
time: 150ms
memory: 5640kb
input:
10000 50 11910 11911 57263 86489 62072 72292 56680 56681 6560 6561 39920 39921 23900 23901 18170 18171 1890 1891 7434 71470 46910 46911 57110 57111 21380 21381 35190 35191 2600 2601 35120 35121 1530 1531 65830 65831 10830 10831 50289 90330 23185 96905 20096 65171 53970 53971 22410 22411 36690 36691 ...
output:
3383
result:
ok single line: '3383'
Test #34:
score: 0
Accepted
time: 146ms
memory: 5452kb
input:
10000 50 45110 45111 42140 42141 18090 18091 47855 55093 29340 29341 28890 45796 17000 17001 39375 54763 24474 90399 20744 28499 18010 18011 38074 55838 48181 80344 46002 68558 4293 74235 18087 89331 48080 95853 5948 57997 14780 14781 47750 47751 32710 32711 38622 64949 7240 7241 46505 77024 42740 4...
output:
5049
result:
ok single line: '5049'
Test #35:
score: 0
Accepted
time: 20ms
memory: 3808kb
input:
1000 100 2553 4316 3136 4040 3452 4889 1875 4225 4270 4271 3041 4112 3590 3591 1180 1181 3280 3281 1765 3590 3243 4638 4887 7617 2940 2941 1817 7583 4947 7214 1864 3333 2700 2701 1960 1961 3990 3991 4580 8653 2290 2291 4930 4931 1170 1171 1619 2346 446 5203 1140 1141 790 791 1570 1571 2490 3116 2500...
output:
599
result:
ok single line: '599'
Test #36:
score: 0
Accepted
time: 50ms
memory: 3792kb
input:
1000 250 2430 2431 2754 8795 3224 9819 306 6089 2954 7428 730 731 3984 5529 1710 1711 3321 7369 1778 9544 4600 4601 1326 7149 3 3543 2569 9688 2780 2781 919 8167 2320 2321 3240 3241 452 1029 4390 4391 420 421 1320 1321 1500 1501 1330 1331 551 785 142 3175 4330 4331 1619 7299 37 3503 532 3902 1515 54...
output:
749
result:
ok single line: '749'
Test #37:
score: 0
Accepted
time: 47ms
memory: 4120kb
input:
2000 100 6353 11064 4330 4331 8430 8431 1330 1331 7840 7841 6890 6891 6300 6301 3161 3538 3270 3271 3400 3401 9370 11084 9652 11191 4600 4601 4532 12055 8849 14094 9390 9391 766 3308 1940 1941 4782 18918 2200 2201 5080 5081 2560 2561 7796 15476 9380 9381 3760 3761 4870 10363 3650 3651 2670 2671 1623...
output:
1099
result:
ok single line: '1099'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
40 5 0 1 10 11 20 21 30 31 40 41 50 51 60 61 70 71 80 81 90 91 100 101 110 111 120 121 130 131 140 141 150 151 160 161 170 171 180 181 190 191 116 357 91 307 170 270 91 387 113 305 132 304 182 304 8 148 124 364 89 238 51 228 83 349 162 282 191 383 108 333 199 377 56 261 57 240 154 283 198 393
output:
24
result:
ok single line: '24'
Test #39:
score: 0
Accepted
time: 132ms
memory: 4792kb
input:
5000 100 16419 46048 870 871 13034 13891 4310 4311 24485 32546 7390 7391 10466 13218 210 211 16242 33624 12170 12171 5070 46310 13510 13511 24588 45998 3024 24048 9660 9661 13170 13171 24780 24781 5940 27839 17070 17071 1178 35469 2957 24930 2074 44268 19300 19301 22700 22701 22280 22281 16620 16621...
output:
2600
result:
ok single line: '2600'
Test #40:
score: 0
Accepted
time: 25ms
memory: 3676kb
input:
500 400 2460 2461 442 3190 310 4388 812 2716 1460 1461 960 961 2320 2321 1630 1631 2076 4122 1700 1701 731 2101 150 151 2300 2301 2440 2441 320 321 1252 4814 929 3248 1900 1901 448 4503 1450 3142 560 561 89 2757 350 351 2136 4869 330 331 1830 1831 140 141 2156 2833 1310 1311 160 161 903 3955 2090 20...
output:
500
result:
ok single line: '500'