답안 #1091737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091737 2024-09-22T01:35:54 Z 12345678 Two Dishes (JOI19_dishes) C++17
100 / 100
2388 ms 197724 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=1e6+5;

ll n, m, qsa[nx], qsb[nx], st[nx], tt[nx], p[nx], q[nx], res, tmp;
vector<tuple<ll, ll, ll>> v;

struct segtree
{
    ll d[4*nx], lz[4*nx];
    void pushlz(int l, int r, int i)
    {
        d[i]+=lz[i];
        if (l!=r) lz[2*i]+=lz[i], lz[2*i+1]+=lz[i];
        lz[i]=0;
    }
    void update(int l, int r, int i, int idx, ll vl)
    {
        pushlz(l, r, i);
        if (r<idx||idx<l) return;
        if (l==r) return d[i]=max(d[i], vl), void();
        int md=(l+r)/2;
        update(l, md, 2*i, idx, vl);
        update(md+1, r, 2*i+1, idx, vl);
        d[i]=max(d[2*i], d[2*i+1]);
    }
    void updaterange(int l, int r, int i, int ql, int qr, ll vl)
    {
        pushlz(l, r, i);
        if (qr<l||r<ql) return;
        if (ql<=l&&r<=qr) return lz[i]+=vl, pushlz(l, r, i), void();
        int md=(l+r)/2;
        updaterange(l, md ,2*i, ql, qr, vl);
        updaterange(md+1, r, 2*i+1, ql, qr, vl);
        d[i]=max(d[2*i], d[2*i+1]);
    }
    ll query(int l, int r, int i ,int ql, int qr)
    {
        pushlz(l, r, i);
        if (qr<l||r<ql) return -1e18;
        if (ql<=l&&r<=qr) return d[i];
        int md=(l+r)/2;
        return max(query(l, md, 2*i, ql, qr), query(md+1, r, 2*i+1, ql, qr));
    }
} s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=n ;i++) cin>>qsa[i]>>st[i]>>p[i], qsa[i]+=qsa[i-1];
    for (int i=1; i<=m; i++) cin>>qsb[i]>>tt[i]>>q[i], qsb[i]+=qsb[i-1];
    for (int i=1; i<=n; i++)
    {
        if (st[i]<qsa[i]) continue;
        ll x=upper_bound(qsb, qsb+m+1, st[i]-qsa[i])-qsb-1;
        if (x!=m) v.push_back({i-1, -(x+1), p[i]});
        res+=p[i];
    }
    for (int i=1; i<=m; i++)
    {
        if (tt[i]<qsb[i]) continue;
        ll x=upper_bound(qsa, qsa+n+1, tt[i]-qsb[i])-qsa-1;
        if (x==n) res+=q[i];
        else v.push_back({x, -i, -q[i]});
    }
    sort(v.begin(), v.end());
    s.updaterange(0, m, 1, 1, m, -1e18);
    for (auto [x, y, vl]:v) 
    {
        y=-y, vl=-vl;
        //cout<<"point "<<x<<' '<<y<<' '<<vl<<'\n';
        tmp=s.query(0, m, 1, 0, y);
        s.update(0, m, 1, y, tmp);
        s.updaterange(0, m, 1, y, m, vl);
    }
    cout<<res+s.query(0, m, 1, 0, m);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 45044 KB Output is correct
2 Correct 264 ms 42756 KB Output is correct
3 Correct 95 ms 29780 KB Output is correct
4 Correct 208 ms 39340 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 245 ms 40932 KB Output is correct
7 Correct 50 ms 21944 KB Output is correct
8 Correct 46 ms 19792 KB Output is correct
9 Correct 111 ms 30792 KB Output is correct
10 Correct 257 ms 39844 KB Output is correct
11 Correct 73 ms 22608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10584 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 12636 KB Output is correct
11 Correct 1 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 1 ms 12636 KB Output is correct
14 Correct 2 ms 12772 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 2 ms 12756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10584 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 12636 KB Output is correct
11 Correct 1 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 1 ms 12636 KB Output is correct
14 Correct 2 ms 12772 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 2 ms 12756 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 3 ms 10844 KB Output is correct
19 Correct 4 ms 13128 KB Output is correct
20 Correct 3 ms 10844 KB Output is correct
21 Correct 3 ms 13120 KB Output is correct
22 Correct 4 ms 12892 KB Output is correct
23 Correct 3 ms 11048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10584 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 12636 KB Output is correct
11 Correct 1 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 1 ms 12636 KB Output is correct
14 Correct 2 ms 12772 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 2 ms 12756 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 3 ms 10844 KB Output is correct
19 Correct 4 ms 13128 KB Output is correct
20 Correct 3 ms 10844 KB Output is correct
21 Correct 3 ms 13120 KB Output is correct
22 Correct 4 ms 12892 KB Output is correct
23 Correct 3 ms 11048 KB Output is correct
24 Correct 183 ms 33216 KB Output is correct
25 Correct 182 ms 39856 KB Output is correct
26 Correct 185 ms 40112 KB Output is correct
27 Correct 172 ms 39860 KB Output is correct
28 Correct 161 ms 39872 KB Output is correct
29 Correct 89 ms 29704 KB Output is correct
30 Correct 363 ms 42836 KB Output is correct
31 Correct 84 ms 29880 KB Output is correct
32 Correct 47 ms 23240 KB Output is correct
33 Correct 233 ms 39600 KB Output is correct
34 Correct 293 ms 40736 KB Output is correct
35 Correct 338 ms 38052 KB Output is correct
36 Correct 324 ms 37796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10584 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 12636 KB Output is correct
11 Correct 1 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 1 ms 12636 KB Output is correct
14 Correct 2 ms 12772 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 2 ms 12756 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 3 ms 10844 KB Output is correct
19 Correct 4 ms 13128 KB Output is correct
20 Correct 3 ms 10844 KB Output is correct
21 Correct 3 ms 13120 KB Output is correct
22 Correct 4 ms 12892 KB Output is correct
23 Correct 3 ms 11048 KB Output is correct
24 Correct 183 ms 33216 KB Output is correct
25 Correct 182 ms 39856 KB Output is correct
26 Correct 185 ms 40112 KB Output is correct
27 Correct 172 ms 39860 KB Output is correct
28 Correct 161 ms 39872 KB Output is correct
29 Correct 89 ms 29704 KB Output is correct
30 Correct 363 ms 42836 KB Output is correct
31 Correct 84 ms 29880 KB Output is correct
32 Correct 47 ms 23240 KB Output is correct
33 Correct 233 ms 39600 KB Output is correct
34 Correct 293 ms 40736 KB Output is correct
35 Correct 338 ms 38052 KB Output is correct
36 Correct 324 ms 37796 KB Output is correct
37 Correct 187 ms 44956 KB Output is correct
38 Correct 176 ms 44976 KB Output is correct
39 Correct 293 ms 47004 KB Output is correct
40 Correct 282 ms 47008 KB Output is correct
41 Correct 1 ms 12632 KB Output is correct
42 Correct 355 ms 47520 KB Output is correct
43 Correct 267 ms 44472 KB Output is correct
44 Correct 354 ms 47012 KB Output is correct
45 Correct 370 ms 41240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 1 ms 10588 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 12636 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10584 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 12636 KB Output is correct
11 Correct 1 ms 12636 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 1 ms 12636 KB Output is correct
14 Correct 2 ms 12772 KB Output is correct
15 Correct 1 ms 12636 KB Output is correct
16 Correct 2 ms 12756 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 3 ms 10844 KB Output is correct
19 Correct 4 ms 13128 KB Output is correct
20 Correct 3 ms 10844 KB Output is correct
21 Correct 3 ms 13120 KB Output is correct
22 Correct 4 ms 12892 KB Output is correct
23 Correct 3 ms 11048 KB Output is correct
24 Correct 183 ms 33216 KB Output is correct
25 Correct 182 ms 39856 KB Output is correct
26 Correct 185 ms 40112 KB Output is correct
27 Correct 172 ms 39860 KB Output is correct
28 Correct 161 ms 39872 KB Output is correct
29 Correct 89 ms 29704 KB Output is correct
30 Correct 363 ms 42836 KB Output is correct
31 Correct 84 ms 29880 KB Output is correct
32 Correct 47 ms 23240 KB Output is correct
33 Correct 233 ms 39600 KB Output is correct
34 Correct 293 ms 40736 KB Output is correct
35 Correct 338 ms 38052 KB Output is correct
36 Correct 324 ms 37796 KB Output is correct
37 Correct 187 ms 44956 KB Output is correct
38 Correct 176 ms 44976 KB Output is correct
39 Correct 293 ms 47004 KB Output is correct
40 Correct 282 ms 47008 KB Output is correct
41 Correct 1 ms 12632 KB Output is correct
42 Correct 355 ms 47520 KB Output is correct
43 Correct 267 ms 44472 KB Output is correct
44 Correct 354 ms 47012 KB Output is correct
45 Correct 370 ms 41240 KB Output is correct
46 Correct 1042 ms 174580 KB Output is correct
47 Correct 985 ms 174636 KB Output is correct
48 Correct 1562 ms 184584 KB Output is correct
49 Correct 1515 ms 184656 KB Output is correct
50 Correct 2316 ms 197256 KB Output is correct
51 Correct 1371 ms 168640 KB Output is correct
52 Correct 1703 ms 179256 KB Output is correct
53 Correct 2055 ms 164176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 45044 KB Output is correct
2 Correct 264 ms 42756 KB Output is correct
3 Correct 95 ms 29780 KB Output is correct
4 Correct 208 ms 39340 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 245 ms 40932 KB Output is correct
7 Correct 50 ms 21944 KB Output is correct
8 Correct 46 ms 19792 KB Output is correct
9 Correct 111 ms 30792 KB Output is correct
10 Correct 257 ms 39844 KB Output is correct
11 Correct 73 ms 22608 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 1 ms 10588 KB Output is correct
17 Correct 1 ms 12636 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10584 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 1 ms 12636 KB Output is correct
22 Correct 1 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 1 ms 12636 KB Output is correct
25 Correct 2 ms 12772 KB Output is correct
26 Correct 1 ms 12636 KB Output is correct
27 Correct 2 ms 12756 KB Output is correct
28 Correct 3 ms 10840 KB Output is correct
29 Correct 3 ms 10844 KB Output is correct
30 Correct 4 ms 13128 KB Output is correct
31 Correct 3 ms 10844 KB Output is correct
32 Correct 3 ms 13120 KB Output is correct
33 Correct 4 ms 12892 KB Output is correct
34 Correct 3 ms 11048 KB Output is correct
35 Correct 183 ms 33216 KB Output is correct
36 Correct 182 ms 39856 KB Output is correct
37 Correct 185 ms 40112 KB Output is correct
38 Correct 172 ms 39860 KB Output is correct
39 Correct 161 ms 39872 KB Output is correct
40 Correct 89 ms 29704 KB Output is correct
41 Correct 363 ms 42836 KB Output is correct
42 Correct 84 ms 29880 KB Output is correct
43 Correct 47 ms 23240 KB Output is correct
44 Correct 233 ms 39600 KB Output is correct
45 Correct 293 ms 40736 KB Output is correct
46 Correct 338 ms 38052 KB Output is correct
47 Correct 324 ms 37796 KB Output is correct
48 Correct 187 ms 44956 KB Output is correct
49 Correct 176 ms 44976 KB Output is correct
50 Correct 293 ms 47004 KB Output is correct
51 Correct 282 ms 47008 KB Output is correct
52 Correct 1 ms 12632 KB Output is correct
53 Correct 355 ms 47520 KB Output is correct
54 Correct 267 ms 44472 KB Output is correct
55 Correct 354 ms 47012 KB Output is correct
56 Correct 370 ms 41240 KB Output is correct
57 Correct 186 ms 48564 KB Output is correct
58 Correct 196 ms 46820 KB Output is correct
59 Correct 288 ms 49568 KB Output is correct
60 Correct 294 ms 49836 KB Output is correct
61 Correct 359 ms 48036 KB Output is correct
62 Correct 1 ms 12636 KB Output is correct
63 Correct 382 ms 51364 KB Output is correct
64 Correct 234 ms 40912 KB Output is correct
65 Correct 318 ms 47264 KB Output is correct
66 Correct 342 ms 44200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 45044 KB Output is correct
2 Correct 264 ms 42756 KB Output is correct
3 Correct 95 ms 29780 KB Output is correct
4 Correct 208 ms 39340 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 245 ms 40932 KB Output is correct
7 Correct 50 ms 21944 KB Output is correct
8 Correct 46 ms 19792 KB Output is correct
9 Correct 111 ms 30792 KB Output is correct
10 Correct 257 ms 39844 KB Output is correct
11 Correct 73 ms 22608 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
13 Correct 2 ms 12636 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 1 ms 10588 KB Output is correct
17 Correct 1 ms 12636 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10584 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 1 ms 12636 KB Output is correct
22 Correct 1 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 1 ms 12636 KB Output is correct
25 Correct 2 ms 12772 KB Output is correct
26 Correct 1 ms 12636 KB Output is correct
27 Correct 2 ms 12756 KB Output is correct
28 Correct 3 ms 10840 KB Output is correct
29 Correct 3 ms 10844 KB Output is correct
30 Correct 4 ms 13128 KB Output is correct
31 Correct 3 ms 10844 KB Output is correct
32 Correct 3 ms 13120 KB Output is correct
33 Correct 4 ms 12892 KB Output is correct
34 Correct 3 ms 11048 KB Output is correct
35 Correct 183 ms 33216 KB Output is correct
36 Correct 182 ms 39856 KB Output is correct
37 Correct 185 ms 40112 KB Output is correct
38 Correct 172 ms 39860 KB Output is correct
39 Correct 161 ms 39872 KB Output is correct
40 Correct 89 ms 29704 KB Output is correct
41 Correct 363 ms 42836 KB Output is correct
42 Correct 84 ms 29880 KB Output is correct
43 Correct 47 ms 23240 KB Output is correct
44 Correct 233 ms 39600 KB Output is correct
45 Correct 293 ms 40736 KB Output is correct
46 Correct 338 ms 38052 KB Output is correct
47 Correct 324 ms 37796 KB Output is correct
48 Correct 187 ms 44956 KB Output is correct
49 Correct 176 ms 44976 KB Output is correct
50 Correct 293 ms 47004 KB Output is correct
51 Correct 282 ms 47008 KB Output is correct
52 Correct 1 ms 12632 KB Output is correct
53 Correct 355 ms 47520 KB Output is correct
54 Correct 267 ms 44472 KB Output is correct
55 Correct 354 ms 47012 KB Output is correct
56 Correct 370 ms 41240 KB Output is correct
57 Correct 1042 ms 174580 KB Output is correct
58 Correct 985 ms 174636 KB Output is correct
59 Correct 1562 ms 184584 KB Output is correct
60 Correct 1515 ms 184656 KB Output is correct
61 Correct 2316 ms 197256 KB Output is correct
62 Correct 1371 ms 168640 KB Output is correct
63 Correct 1703 ms 179256 KB Output is correct
64 Correct 2055 ms 164176 KB Output is correct
65 Correct 186 ms 48564 KB Output is correct
66 Correct 196 ms 46820 KB Output is correct
67 Correct 288 ms 49568 KB Output is correct
68 Correct 294 ms 49836 KB Output is correct
69 Correct 359 ms 48036 KB Output is correct
70 Correct 1 ms 12636 KB Output is correct
71 Correct 382 ms 51364 KB Output is correct
72 Correct 234 ms 40912 KB Output is correct
73 Correct 318 ms 47264 KB Output is correct
74 Correct 342 ms 44200 KB Output is correct
75 Correct 1041 ms 176440 KB Output is correct
76 Correct 1037 ms 176536 KB Output is correct
77 Correct 1575 ms 186924 KB Output is correct
78 Correct 1594 ms 187104 KB Output is correct
79 Correct 2388 ms 197724 KB Output is correct
80 Correct 1302 ms 170908 KB Output is correct
81 Correct 1683 ms 178540 KB Output is correct
82 Correct 2238 ms 165088 KB Output is correct
83 Correct 2231 ms 182620 KB Output is correct