답안 #157340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157340 2019-10-11T00:14:39 Z combi1k1 Two Dishes (JOI19_dishes) C++14
100 / 100
6717 ms 218964 KB
#include<bits/stdc++.h>

using namespace std;

#define X       first
#define Y       second
#define int     long long
#define pb      push_back
#define lch     i << 1
#define rch     i << 1 | 1

const int   N   = 1e6 + 5;
const int   inf = 1e18;

typedef pair<int,int>  ii;

ii  operator + (const ii &a,const ii &b)    {
    return  ii(a.X + b.X,max(a.Y + b.X,b.Y));
}

int n, m;
int res = 0;

int tr[N << 2];
ii  lz[N << 2];

int push(int i,int l,int r) {
    tr[i] = max(tr[i] + lz[i].X,lz[i].Y);
    if (l < r)  {
        lz[lch] = lz[lch] + lz[i];
        lz[rch] = lz[rch] + lz[i];
    }
    lz[i] = ii(0,-inf);
}
int _upd(int i,int l,int r,int L,int R,ii  v)   {
    push(i,l,r);
    if (R <  l || r <  L)   return  0;
    if (L <= l && r <= R)   {
        lz[i] = v;
        push(i,l,r);
        return  1;
    }
    int m = (l + r) / 2;
    _upd(lch,l,m,L,R,v);    ++m;
    _upd(rch,m,r,L,R,v);
    tr[i] = max(tr[lch],tr[rch]);
}
int _get(int i,int l,int r,int p)   {
    push(i,l,r);
    if (l == r) return  tr[i];
    int m = (l + r) / 2;
    if (p <= m) return  _get(lch,l,m,p);
    else    return ++m, _get(rch,m,r,p);
}

int a[N], s[N], p[N];
int b[N], t[N], q[N];

vector<ii>  v[N];

signed main()   {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> m;

    for(int i = 1 ; i <= n ; ++i)   cin >> a[i] >> s[i] >> p[i], a[i] += a[i - 1];
    for(int i = 1 ; i <= m ; ++i)   cin >> b[i] >> t[i] >> q[i], b[i] += b[i - 1];

    for(int i = 1 ; i <= n ; ++i)   {
        int x = upper_bound(b,b + 1 + m,s[i] - a[i]) - b;
        if (x >= 1) v[x - 1].pb({i,p[i]});
    }
    for(int i = 1 ; i <= m ; ++i)   {
        res  += q[i];
        q[i] = -q[i];
        int x = upper_bound(a,a + 1 + n,t[i] - b[i]) - a;
        if (x <= n) v[i - 1].pb({x,q[i]});
    }

    n++;
    fill(lz,lz + N * 4,ii(0,-inf));

    for(int i = 0 ; i < m ; ++i)    {
        for(ii  x : v[i])
            _upd(1,1,n,x.X + 1,n,{x.Y,-inf});
        for(ii  x : v[i])   if (x.X)
            _upd(1,1,n,x.X + 1,n,{0,_get(1,1,n,x.X)});
    }
    for(ii  x : v[m])   _upd(1,1,n,x.X + 1,n,{x.Y,-inf});

    cout << res + _get(1,1,n,n);
}

Compilation message

dishes.cpp: In function 'long long int push(long long int, long long int, long long int)':
dishes.cpp:34:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
dishes.cpp: In function 'long long int _upd(long long int, long long int, long long int, long long int, long long int, ii)':
dishes.cpp:47:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 770 ms 119868 KB Output is correct
2 Correct 748 ms 120180 KB Output is correct
3 Correct 419 ms 115448 KB Output is correct
4 Correct 622 ms 117744 KB Output is correct
5 Correct 77 ms 86520 KB Output is correct
6 Correct 685 ms 120012 KB Output is correct
7 Correct 184 ms 98564 KB Output is correct
8 Correct 294 ms 105568 KB Output is correct
9 Correct 418 ms 114372 KB Output is correct
10 Correct 730 ms 116984 KB Output is correct
11 Correct 342 ms 111176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 86520 KB Output is correct
2 Correct 75 ms 86548 KB Output is correct
3 Correct 75 ms 86452 KB Output is correct
4 Correct 76 ms 86520 KB Output is correct
5 Correct 76 ms 86632 KB Output is correct
6 Correct 76 ms 86420 KB Output is correct
7 Correct 76 ms 86504 KB Output is correct
8 Correct 76 ms 86428 KB Output is correct
9 Correct 76 ms 86520 KB Output is correct
10 Correct 75 ms 86520 KB Output is correct
11 Correct 75 ms 86520 KB Output is correct
12 Correct 77 ms 86648 KB Output is correct
13 Correct 76 ms 86520 KB Output is correct
14 Correct 76 ms 86520 KB Output is correct
15 Correct 76 ms 86548 KB Output is correct
16 Correct 88 ms 86492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 86520 KB Output is correct
2 Correct 75 ms 86548 KB Output is correct
3 Correct 75 ms 86452 KB Output is correct
4 Correct 76 ms 86520 KB Output is correct
5 Correct 76 ms 86632 KB Output is correct
6 Correct 76 ms 86420 KB Output is correct
7 Correct 76 ms 86504 KB Output is correct
8 Correct 76 ms 86428 KB Output is correct
9 Correct 76 ms 86520 KB Output is correct
10 Correct 75 ms 86520 KB Output is correct
11 Correct 75 ms 86520 KB Output is correct
12 Correct 77 ms 86648 KB Output is correct
13 Correct 76 ms 86520 KB Output is correct
14 Correct 76 ms 86520 KB Output is correct
15 Correct 76 ms 86548 KB Output is correct
16 Correct 88 ms 86492 KB Output is correct
17 Correct 87 ms 86820 KB Output is correct
18 Correct 80 ms 86840 KB Output is correct
19 Correct 81 ms 86800 KB Output is correct
20 Correct 79 ms 86776 KB Output is correct
21 Correct 83 ms 86904 KB Output is correct
22 Correct 80 ms 86776 KB Output is correct
23 Correct 81 ms 86776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 86520 KB Output is correct
2 Correct 75 ms 86548 KB Output is correct
3 Correct 75 ms 86452 KB Output is correct
4 Correct 76 ms 86520 KB Output is correct
5 Correct 76 ms 86632 KB Output is correct
6 Correct 76 ms 86420 KB Output is correct
7 Correct 76 ms 86504 KB Output is correct
8 Correct 76 ms 86428 KB Output is correct
9 Correct 76 ms 86520 KB Output is correct
10 Correct 75 ms 86520 KB Output is correct
11 Correct 75 ms 86520 KB Output is correct
12 Correct 77 ms 86648 KB Output is correct
13 Correct 76 ms 86520 KB Output is correct
14 Correct 76 ms 86520 KB Output is correct
15 Correct 76 ms 86548 KB Output is correct
16 Correct 88 ms 86492 KB Output is correct
17 Correct 87 ms 86820 KB Output is correct
18 Correct 80 ms 86840 KB Output is correct
19 Correct 81 ms 86800 KB Output is correct
20 Correct 79 ms 86776 KB Output is correct
21 Correct 83 ms 86904 KB Output is correct
22 Correct 80 ms 86776 KB Output is correct
23 Correct 81 ms 86776 KB Output is correct
24 Correct 544 ms 116820 KB Output is correct
25 Correct 634 ms 118356 KB Output is correct
26 Correct 570 ms 119660 KB Output is correct
27 Correct 591 ms 118536 KB Output is correct
28 Correct 572 ms 116288 KB Output is correct
29 Correct 386 ms 114600 KB Output is correct
30 Correct 1111 ms 120664 KB Output is correct
31 Correct 186 ms 99704 KB Output is correct
32 Correct 360 ms 103908 KB Output is correct
33 Correct 735 ms 118396 KB Output is correct
34 Correct 930 ms 119532 KB Output is correct
35 Correct 1039 ms 114424 KB Output is correct
36 Correct 1008 ms 114216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 86520 KB Output is correct
2 Correct 75 ms 86548 KB Output is correct
3 Correct 75 ms 86452 KB Output is correct
4 Correct 76 ms 86520 KB Output is correct
5 Correct 76 ms 86632 KB Output is correct
6 Correct 76 ms 86420 KB Output is correct
7 Correct 76 ms 86504 KB Output is correct
8 Correct 76 ms 86428 KB Output is correct
9 Correct 76 ms 86520 KB Output is correct
10 Correct 75 ms 86520 KB Output is correct
11 Correct 75 ms 86520 KB Output is correct
12 Correct 77 ms 86648 KB Output is correct
13 Correct 76 ms 86520 KB Output is correct
14 Correct 76 ms 86520 KB Output is correct
15 Correct 76 ms 86548 KB Output is correct
16 Correct 88 ms 86492 KB Output is correct
17 Correct 87 ms 86820 KB Output is correct
18 Correct 80 ms 86840 KB Output is correct
19 Correct 81 ms 86800 KB Output is correct
20 Correct 79 ms 86776 KB Output is correct
21 Correct 83 ms 86904 KB Output is correct
22 Correct 80 ms 86776 KB Output is correct
23 Correct 81 ms 86776 KB Output is correct
24 Correct 544 ms 116820 KB Output is correct
25 Correct 634 ms 118356 KB Output is correct
26 Correct 570 ms 119660 KB Output is correct
27 Correct 591 ms 118536 KB Output is correct
28 Correct 572 ms 116288 KB Output is correct
29 Correct 386 ms 114600 KB Output is correct
30 Correct 1111 ms 120664 KB Output is correct
31 Correct 186 ms 99704 KB Output is correct
32 Correct 360 ms 103908 KB Output is correct
33 Correct 735 ms 118396 KB Output is correct
34 Correct 930 ms 119532 KB Output is correct
35 Correct 1039 ms 114424 KB Output is correct
36 Correct 1008 ms 114216 KB Output is correct
37 Correct 580 ms 119732 KB Output is correct
38 Correct 612 ms 118556 KB Output is correct
39 Correct 796 ms 120564 KB Output is correct
40 Correct 789 ms 120556 KB Output is correct
41 Correct 89 ms 86520 KB Output is correct
42 Correct 1143 ms 121324 KB Output is correct
43 Correct 729 ms 118776 KB Output is correct
44 Correct 946 ms 119784 KB Output is correct
45 Correct 1268 ms 117624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 86520 KB Output is correct
2 Correct 75 ms 86548 KB Output is correct
3 Correct 75 ms 86452 KB Output is correct
4 Correct 76 ms 86520 KB Output is correct
5 Correct 76 ms 86632 KB Output is correct
6 Correct 76 ms 86420 KB Output is correct
7 Correct 76 ms 86504 KB Output is correct
8 Correct 76 ms 86428 KB Output is correct
9 Correct 76 ms 86520 KB Output is correct
10 Correct 75 ms 86520 KB Output is correct
11 Correct 75 ms 86520 KB Output is correct
12 Correct 77 ms 86648 KB Output is correct
13 Correct 76 ms 86520 KB Output is correct
14 Correct 76 ms 86520 KB Output is correct
15 Correct 76 ms 86548 KB Output is correct
16 Correct 88 ms 86492 KB Output is correct
17 Correct 87 ms 86820 KB Output is correct
18 Correct 80 ms 86840 KB Output is correct
19 Correct 81 ms 86800 KB Output is correct
20 Correct 79 ms 86776 KB Output is correct
21 Correct 83 ms 86904 KB Output is correct
22 Correct 80 ms 86776 KB Output is correct
23 Correct 81 ms 86776 KB Output is correct
24 Correct 544 ms 116820 KB Output is correct
25 Correct 634 ms 118356 KB Output is correct
26 Correct 570 ms 119660 KB Output is correct
27 Correct 591 ms 118536 KB Output is correct
28 Correct 572 ms 116288 KB Output is correct
29 Correct 386 ms 114600 KB Output is correct
30 Correct 1111 ms 120664 KB Output is correct
31 Correct 186 ms 99704 KB Output is correct
32 Correct 360 ms 103908 KB Output is correct
33 Correct 735 ms 118396 KB Output is correct
34 Correct 930 ms 119532 KB Output is correct
35 Correct 1039 ms 114424 KB Output is correct
36 Correct 1008 ms 114216 KB Output is correct
37 Correct 580 ms 119732 KB Output is correct
38 Correct 612 ms 118556 KB Output is correct
39 Correct 796 ms 120564 KB Output is correct
40 Correct 789 ms 120556 KB Output is correct
41 Correct 89 ms 86520 KB Output is correct
42 Correct 1143 ms 121324 KB Output is correct
43 Correct 729 ms 118776 KB Output is correct
44 Correct 946 ms 119784 KB Output is correct
45 Correct 1268 ms 117624 KB Output is correct
46 Correct 2773 ms 214372 KB Output is correct
47 Correct 2969 ms 209720 KB Output is correct
48 Correct 4014 ms 213068 KB Output is correct
49 Correct 3953 ms 212924 KB Output is correct
50 Correct 6717 ms 218224 KB Output is correct
51 Correct 3834 ms 205420 KB Output is correct
52 Correct 4938 ms 207964 KB Output is correct
53 Correct 6290 ms 210960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 770 ms 119868 KB Output is correct
2 Correct 748 ms 120180 KB Output is correct
3 Correct 419 ms 115448 KB Output is correct
4 Correct 622 ms 117744 KB Output is correct
5 Correct 77 ms 86520 KB Output is correct
6 Correct 685 ms 120012 KB Output is correct
7 Correct 184 ms 98564 KB Output is correct
8 Correct 294 ms 105568 KB Output is correct
9 Correct 418 ms 114372 KB Output is correct
10 Correct 730 ms 116984 KB Output is correct
11 Correct 342 ms 111176 KB Output is correct
12 Correct 75 ms 86520 KB Output is correct
13 Correct 75 ms 86548 KB Output is correct
14 Correct 75 ms 86452 KB Output is correct
15 Correct 76 ms 86520 KB Output is correct
16 Correct 76 ms 86632 KB Output is correct
17 Correct 76 ms 86420 KB Output is correct
18 Correct 76 ms 86504 KB Output is correct
19 Correct 76 ms 86428 KB Output is correct
20 Correct 76 ms 86520 KB Output is correct
21 Correct 75 ms 86520 KB Output is correct
22 Correct 75 ms 86520 KB Output is correct
23 Correct 77 ms 86648 KB Output is correct
24 Correct 76 ms 86520 KB Output is correct
25 Correct 76 ms 86520 KB Output is correct
26 Correct 76 ms 86548 KB Output is correct
27 Correct 88 ms 86492 KB Output is correct
28 Correct 87 ms 86820 KB Output is correct
29 Correct 80 ms 86840 KB Output is correct
30 Correct 81 ms 86800 KB Output is correct
31 Correct 79 ms 86776 KB Output is correct
32 Correct 83 ms 86904 KB Output is correct
33 Correct 80 ms 86776 KB Output is correct
34 Correct 81 ms 86776 KB Output is correct
35 Correct 544 ms 116820 KB Output is correct
36 Correct 634 ms 118356 KB Output is correct
37 Correct 570 ms 119660 KB Output is correct
38 Correct 591 ms 118536 KB Output is correct
39 Correct 572 ms 116288 KB Output is correct
40 Correct 386 ms 114600 KB Output is correct
41 Correct 1111 ms 120664 KB Output is correct
42 Correct 186 ms 99704 KB Output is correct
43 Correct 360 ms 103908 KB Output is correct
44 Correct 735 ms 118396 KB Output is correct
45 Correct 930 ms 119532 KB Output is correct
46 Correct 1039 ms 114424 KB Output is correct
47 Correct 1008 ms 114216 KB Output is correct
48 Correct 580 ms 119732 KB Output is correct
49 Correct 612 ms 118556 KB Output is correct
50 Correct 796 ms 120564 KB Output is correct
51 Correct 789 ms 120556 KB Output is correct
52 Correct 89 ms 86520 KB Output is correct
53 Correct 1143 ms 121324 KB Output is correct
54 Correct 729 ms 118776 KB Output is correct
55 Correct 946 ms 119784 KB Output is correct
56 Correct 1268 ms 117624 KB Output is correct
57 Correct 584 ms 121724 KB Output is correct
58 Correct 634 ms 117068 KB Output is correct
59 Correct 794 ms 119824 KB Output is correct
60 Correct 798 ms 119660 KB Output is correct
61 Correct 1146 ms 120524 KB Output is correct
62 Correct 77 ms 86520 KB Output is correct
63 Correct 1123 ms 119240 KB Output is correct
64 Correct 718 ms 116972 KB Output is correct
65 Correct 935 ms 117828 KB Output is correct
66 Correct 1034 ms 117388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 770 ms 119868 KB Output is correct
2 Correct 748 ms 120180 KB Output is correct
3 Correct 419 ms 115448 KB Output is correct
4 Correct 622 ms 117744 KB Output is correct
5 Correct 77 ms 86520 KB Output is correct
6 Correct 685 ms 120012 KB Output is correct
7 Correct 184 ms 98564 KB Output is correct
8 Correct 294 ms 105568 KB Output is correct
9 Correct 418 ms 114372 KB Output is correct
10 Correct 730 ms 116984 KB Output is correct
11 Correct 342 ms 111176 KB Output is correct
12 Correct 75 ms 86520 KB Output is correct
13 Correct 75 ms 86548 KB Output is correct
14 Correct 75 ms 86452 KB Output is correct
15 Correct 76 ms 86520 KB Output is correct
16 Correct 76 ms 86632 KB Output is correct
17 Correct 76 ms 86420 KB Output is correct
18 Correct 76 ms 86504 KB Output is correct
19 Correct 76 ms 86428 KB Output is correct
20 Correct 76 ms 86520 KB Output is correct
21 Correct 75 ms 86520 KB Output is correct
22 Correct 75 ms 86520 KB Output is correct
23 Correct 77 ms 86648 KB Output is correct
24 Correct 76 ms 86520 KB Output is correct
25 Correct 76 ms 86520 KB Output is correct
26 Correct 76 ms 86548 KB Output is correct
27 Correct 88 ms 86492 KB Output is correct
28 Correct 87 ms 86820 KB Output is correct
29 Correct 80 ms 86840 KB Output is correct
30 Correct 81 ms 86800 KB Output is correct
31 Correct 79 ms 86776 KB Output is correct
32 Correct 83 ms 86904 KB Output is correct
33 Correct 80 ms 86776 KB Output is correct
34 Correct 81 ms 86776 KB Output is correct
35 Correct 544 ms 116820 KB Output is correct
36 Correct 634 ms 118356 KB Output is correct
37 Correct 570 ms 119660 KB Output is correct
38 Correct 591 ms 118536 KB Output is correct
39 Correct 572 ms 116288 KB Output is correct
40 Correct 386 ms 114600 KB Output is correct
41 Correct 1111 ms 120664 KB Output is correct
42 Correct 186 ms 99704 KB Output is correct
43 Correct 360 ms 103908 KB Output is correct
44 Correct 735 ms 118396 KB Output is correct
45 Correct 930 ms 119532 KB Output is correct
46 Correct 1039 ms 114424 KB Output is correct
47 Correct 1008 ms 114216 KB Output is correct
48 Correct 580 ms 119732 KB Output is correct
49 Correct 612 ms 118556 KB Output is correct
50 Correct 796 ms 120564 KB Output is correct
51 Correct 789 ms 120556 KB Output is correct
52 Correct 89 ms 86520 KB Output is correct
53 Correct 1143 ms 121324 KB Output is correct
54 Correct 729 ms 118776 KB Output is correct
55 Correct 946 ms 119784 KB Output is correct
56 Correct 1268 ms 117624 KB Output is correct
57 Correct 2773 ms 214372 KB Output is correct
58 Correct 2969 ms 209720 KB Output is correct
59 Correct 4014 ms 213068 KB Output is correct
60 Correct 3953 ms 212924 KB Output is correct
61 Correct 6717 ms 218224 KB Output is correct
62 Correct 3834 ms 205420 KB Output is correct
63 Correct 4938 ms 207964 KB Output is correct
64 Correct 6290 ms 210960 KB Output is correct
65 Correct 584 ms 121724 KB Output is correct
66 Correct 634 ms 117068 KB Output is correct
67 Correct 794 ms 119824 KB Output is correct
68 Correct 798 ms 119660 KB Output is correct
69 Correct 1146 ms 120524 KB Output is correct
70 Correct 77 ms 86520 KB Output is correct
71 Correct 1123 ms 119240 KB Output is correct
72 Correct 718 ms 116972 KB Output is correct
73 Correct 935 ms 117828 KB Output is correct
74 Correct 1034 ms 117388 KB Output is correct
75 Correct 2800 ms 212652 KB Output is correct
76 Correct 2981 ms 208952 KB Output is correct
77 Correct 4032 ms 212600 KB Output is correct
78 Correct 3986 ms 212740 KB Output is correct
79 Correct 6658 ms 218964 KB Output is correct
80 Correct 3807 ms 203156 KB Output is correct
81 Correct 4917 ms 203816 KB Output is correct
82 Correct 6322 ms 209104 KB Output is correct
83 Correct 6201 ms 211440 KB Output is correct