QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301419#7950. Lucky DrawsTobo#WA 270ms40524kbC++203.0kb2024-01-09 20:29:582024-01-09 20:29:58

Judging History

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

  • [2024-01-09 20:29:58]
  • 评测
  • 测评结果:WA
  • 用时:270ms
  • 内存:40524kb
  • [2024-01-09 20:29:58]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using i64 = long long;
using namespace std;
const int N = 2e4 + 5;
// const int B = 340;
// const int M = 5e3 + 5;
// const int base = 1753591;
// const int mod = 998244353;
// const int mod = 1e9 + 7;
// const double pi = acos(-1);

int n, k, m, l[N], r[N];
vector<vector<int>> dp;
vector<int> add[N], del[N];
struct node
{
    int val, tag;
};
vector<vector<node>> st;
#define lc cur << 1
#define rc cur << 1 | 1
void pushdown(int k, int cur)
{
    st[k][lc].tag += st[k][cur].tag;
    st[k][rc].tag += st[k][cur].tag;
    st[k][lc].val += st[k][cur].tag;
    st[k][rc].val += st[k][cur].tag;
    st[k][cur].tag = 0;
}
void pushup(int k, int cur)
{
    st[k][cur].val = max(st[k][lc].val, st[k][rc].val);
}
int query(int k, int cur, int l, int r, int a, int b)
{
    if (a <= l && r <= b)
        return st[k][cur].val;
    if (a > r || b < l)
        return -1e9;
    pushdown(k, cur);
    int mid = l + r >> 1;
    return max(query(k, lc, l, mid, a, b), query(k, rc, mid + 1, r, a, b));
}
void update(int k, int cur, int l, int r, int a, int b, int x)
{
    if (a <= l && r <= b)
    {
        st[k][cur].val += x;
        st[k][cur].tag += x;
        return;
    }
    pushdown(k, cur);
    int mid = l + r >> 1;
    if (a <= mid)
        update(k, lc, l, mid, a, b, x);
    if (b > mid)
        update(k, rc, mid + 1, r, a, b, x);
    pushup(k, cur);
}
void solve()
{
    cin >> n >> k;
    vector<int> tmp{(int)-1e9};
    for (int i = 1; i <= n; i++)
        cin >> l[i] >> r[i], tmp.push_back(l[i]), tmp.push_back(r[i]);
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
    for (int i = 1; i <= n; i++)
    {
        l[i] = lower_bound(tmp.begin(), tmp.end(), l[i]) - tmp.begin();
        r[i] = lower_bound(tmp.begin(), tmp.end(), r[i]) - tmp.begin();
        m = max({m, l[i], r[i]});
        add[l[i]].push_back(i);
        del[r[i]].push_back(i);
    }
    dp.resize(m + 1, vector<int>(k + 1));
    st.resize(k + 1, vector<node>((m + 5) * 4));
    for (int i = 1, cur = 0; i <= m; i++)
    {
        dp[i] = dp[i - 1];
        cur += add[i].size();
        for (int x : add[i])
            for (int j = 0; j <= k; j++)
                update(j, 1, 0, m, l[x], r[x], -1);
        for (int j = 1; j <= k; j++)
            dp[i][j] = max(dp[i][j], cur + query(j - 1, 1, 0, n, 0, i - 1));
        for (int j = 0; j <= k; j++)
            update(j, 1, 0, m, i, i, dp[i][j]);
        cur -= del[i].size();
        for (int x : del[i])
            for (int j = 0; j <= k; j++)
                update(j, 1, 0, m, l[x], r[x], 1);
    }
    cout << dp[m][k] << '\n';
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    cout << fixed << setprecision(10);
    while (t--)
        solve();
}

詳細信息

Test #1:

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

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: 1ms
memory: 4472kb

input:

3 2
2 4
1 3
3 5

output:

3

result:

ok single line: '3'

Test #3:

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

input:

4 1
2 3
1 1
4 5
4 5

output:

2

result:

ok single line: '2'

Test #4:

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

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: 229ms
memory: 36180kb

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: 254ms
memory: 39784kb

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: 78ms
memory: 17024kb

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: 214ms
memory: 36168kb

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: 270ms
memory: 37456kb

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: 186ms
memory: 28652kb

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: 16ms
memory: 7548kb

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: 85ms
memory: 17296kb

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: 234ms
memory: 39544kb

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: 12ms
memory: 6724kb

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: 247ms
memory: 40524kb

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: 181ms
memory: 32316kb

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: 243ms
memory: 38556kb

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: 247ms
memory: 38036kb

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: 230ms
memory: 36916kb

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: 222ms
memory: 29476kb

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: -100
Wrong Answer
time: 216ms
memory: 20884kb

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:

2321

result:

wrong answer 1st lines differ - expected: '5000', found: '2321'