답안 #789992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789992 2023-07-22T08:47:06 Z someone Two Dishes (JOI19_dishes) C++14
100 / 100
2897 ms 174124 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct Point {
    int x, y, val;
};

const int M = 1 << 20, N = 2 * M, INF = 1e18 + 42;

int maxi[N], tag[N];

inline void applyOp(int i, int add) {
    tag[i] += add;
    maxi[i] += add;
}

inline void propage(int i) {
    applyOp(i*2, tag[i]);
    applyOp(i*2+1, tag[i]);
    tag[i] = 0;
}

void setVal(int i, int deb, int fin, int pos, int val) {
    if(pos < deb || fin <= pos)
        return;
    if(fin - deb == 1) {
        maxi[i] = val;
        return;
    }
    propage(i);
    int mid = ((deb + fin) >> 1);
    setVal(i*2, deb, mid, pos, val);
    setVal(i*2+1, mid, fin, pos, val);
    maxi[i] = max(maxi[i*2], maxi[i*2+1]);
}

int update(int i, int deb, int fin, int l, int r, int add) {
    if(r <= deb || fin <= l)
        return -2*INF;
    if(l <= deb && fin <= r) {
        applyOp(i, add);
        return maxi[i];
    }
    propage(i);
    int mid = ((deb + fin) >> 1),
        ans = max(update(i*2, deb, mid, l, r, add),
                  update(i*2+1, mid, fin, l, r, add));
    maxi[i] = max(maxi[i*2], maxi[i*2+1]);
    return ans;
}

vector<Point> point;
int score = 0, ans = 0, sz[2], a[2][M], t[2][M], pt[2][M], pos[2][M];

void solve() {
    for(int i = 0; i < N; i++)
        tag[i] = 0, maxi[i] = -INF;
    for(int i = 0; i < 2; i++)
        for(int j = 1; j <= sz[i]; j++)
            a[i][j] += a[i][j-1];
    a[0][sz[0]+1] = a[1][sz[1]+1] = INF;

    for(int i = 0; i < 2; i++)
        for(int j = 1; j <= sz[i]; j++)
            pos[i][j] = (int)(upper_bound(a[1-i], a[1-i] + sz[1-i] + 1, t[i][j] - a[i][j]) - a[1-i]) - 1;

    for(int j = 0; j <= sz[0]; j++)
        if(pos[0][j] != -1)
            point.push_back({j, pos[0][j], pt[0][j]});
    for(int j = 1; j <= sz[1]; j++) {
        if(pos[1][j] != -1) {
            score += pt[1][j];
            if(pos[1][j] != sz[0])
                point.push_back({pos[1][j]+1, j-1, -pt[1][j]});
        }
    }

    point.push_back({sz[0], sz[1], 0});
    sort(point.begin(), point.end(),
    [](Point p1, Point p2) {
        if(p1.x == p2.x)
            return p1.y < p2.y;
        return p1.x > p2.x;
    });
    for(int i = 1; i < (int)point.size(); i++)
        if(point[i].x == point[i-1].x && point[i].y == point[i-1].y) {
            point[i-1].x = point[i-1].y = -1;
            point[i].val += point[i-1].val;
            point[i-1].val = 0;
        }

    for(int i = 0; i < (int)point.size(); i++) {
        if(point[i].x != -1) {
            int val = update(1, 0, M, point[i].y, M, 0);
            if(point[i].x == sz[0])
                val = 0;
            setVal(1, 0, M, point[i].y, val);
            update(1, 0, M, 0, point[i].y+1, point[i].val);
            if(point[i].x == 0 && point[i].y == 0)
                ans = val;
        }
    }

    cout << ans + score << '\n';
}

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

    cin >> sz[0] >> sz[1];
    for(int i = 0; i < 2; i++)
        for(int j = 1; j <= sz[i]; j++)
            cin >> a[i][j] >> t[i][j] >> pt[i][j];
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 313 ms 64236 KB Output is correct
2 Correct 311 ms 64056 KB Output is correct
3 Correct 241 ms 58044 KB Output is correct
4 Correct 232 ms 57792 KB Output is correct
5 Correct 12 ms 33108 KB Output is correct
6 Correct 291 ms 63544 KB Output is correct
7 Correct 63 ms 45396 KB Output is correct
8 Correct 221 ms 51692 KB Output is correct
9 Correct 231 ms 57940 KB Output is correct
10 Correct 268 ms 64056 KB Output is correct
11 Correct 205 ms 58024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33108 KB Output is correct
2 Correct 11 ms 33176 KB Output is correct
3 Correct 11 ms 33192 KB Output is correct
4 Correct 11 ms 33144 KB Output is correct
5 Correct 12 ms 33108 KB Output is correct
6 Correct 12 ms 33172 KB Output is correct
7 Correct 12 ms 33108 KB Output is correct
8 Correct 12 ms 33108 KB Output is correct
9 Correct 12 ms 33080 KB Output is correct
10 Correct 12 ms 33140 KB Output is correct
11 Correct 11 ms 33188 KB Output is correct
12 Correct 12 ms 33156 KB Output is correct
13 Correct 11 ms 33160 KB Output is correct
14 Correct 12 ms 33108 KB Output is correct
15 Correct 11 ms 33108 KB Output is correct
16 Correct 11 ms 33200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33108 KB Output is correct
2 Correct 11 ms 33176 KB Output is correct
3 Correct 11 ms 33192 KB Output is correct
4 Correct 11 ms 33144 KB Output is correct
5 Correct 12 ms 33108 KB Output is correct
6 Correct 12 ms 33172 KB Output is correct
7 Correct 12 ms 33108 KB Output is correct
8 Correct 12 ms 33108 KB Output is correct
9 Correct 12 ms 33080 KB Output is correct
10 Correct 12 ms 33140 KB Output is correct
11 Correct 11 ms 33188 KB Output is correct
12 Correct 12 ms 33156 KB Output is correct
13 Correct 11 ms 33160 KB Output is correct
14 Correct 12 ms 33108 KB Output is correct
15 Correct 11 ms 33108 KB Output is correct
16 Correct 11 ms 33200 KB Output is correct
17 Correct 14 ms 33504 KB Output is correct
18 Correct 15 ms 33568 KB Output is correct
19 Correct 15 ms 33620 KB Output is correct
20 Correct 15 ms 33492 KB Output is correct
21 Correct 15 ms 33508 KB Output is correct
22 Correct 16 ms 33572 KB Output is correct
23 Correct 14 ms 33492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33108 KB Output is correct
2 Correct 11 ms 33176 KB Output is correct
3 Correct 11 ms 33192 KB Output is correct
4 Correct 11 ms 33144 KB Output is correct
5 Correct 12 ms 33108 KB Output is correct
6 Correct 12 ms 33172 KB Output is correct
7 Correct 12 ms 33108 KB Output is correct
8 Correct 12 ms 33108 KB Output is correct
9 Correct 12 ms 33080 KB Output is correct
10 Correct 12 ms 33140 KB Output is correct
11 Correct 11 ms 33188 KB Output is correct
12 Correct 12 ms 33156 KB Output is correct
13 Correct 11 ms 33160 KB Output is correct
14 Correct 12 ms 33108 KB Output is correct
15 Correct 11 ms 33108 KB Output is correct
16 Correct 11 ms 33200 KB Output is correct
17 Correct 14 ms 33504 KB Output is correct
18 Correct 15 ms 33568 KB Output is correct
19 Correct 15 ms 33620 KB Output is correct
20 Correct 15 ms 33492 KB Output is correct
21 Correct 15 ms 33508 KB Output is correct
22 Correct 16 ms 33572 KB Output is correct
23 Correct 14 ms 33492 KB Output is correct
24 Correct 212 ms 58124 KB Output is correct
25 Correct 302 ms 64060 KB Output is correct
26 Correct 238 ms 57916 KB Output is correct
27 Correct 308 ms 64108 KB Output is correct
28 Correct 293 ms 57976 KB Output is correct
29 Correct 272 ms 58356 KB Output is correct
30 Correct 444 ms 64580 KB Output is correct
31 Correct 137 ms 47904 KB Output is correct
32 Correct 193 ms 50892 KB Output is correct
33 Correct 319 ms 58300 KB Output is correct
34 Correct 410 ms 64324 KB Output is correct
35 Correct 430 ms 62352 KB Output is correct
36 Correct 462 ms 62408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33108 KB Output is correct
2 Correct 11 ms 33176 KB Output is correct
3 Correct 11 ms 33192 KB Output is correct
4 Correct 11 ms 33144 KB Output is correct
5 Correct 12 ms 33108 KB Output is correct
6 Correct 12 ms 33172 KB Output is correct
7 Correct 12 ms 33108 KB Output is correct
8 Correct 12 ms 33108 KB Output is correct
9 Correct 12 ms 33080 KB Output is correct
10 Correct 12 ms 33140 KB Output is correct
11 Correct 11 ms 33188 KB Output is correct
12 Correct 12 ms 33156 KB Output is correct
13 Correct 11 ms 33160 KB Output is correct
14 Correct 12 ms 33108 KB Output is correct
15 Correct 11 ms 33108 KB Output is correct
16 Correct 11 ms 33200 KB Output is correct
17 Correct 14 ms 33504 KB Output is correct
18 Correct 15 ms 33568 KB Output is correct
19 Correct 15 ms 33620 KB Output is correct
20 Correct 15 ms 33492 KB Output is correct
21 Correct 15 ms 33508 KB Output is correct
22 Correct 16 ms 33572 KB Output is correct
23 Correct 14 ms 33492 KB Output is correct
24 Correct 212 ms 58124 KB Output is correct
25 Correct 302 ms 64060 KB Output is correct
26 Correct 238 ms 57916 KB Output is correct
27 Correct 308 ms 64108 KB Output is correct
28 Correct 293 ms 57976 KB Output is correct
29 Correct 272 ms 58356 KB Output is correct
30 Correct 444 ms 64580 KB Output is correct
31 Correct 137 ms 47904 KB Output is correct
32 Correct 193 ms 50892 KB Output is correct
33 Correct 319 ms 58300 KB Output is correct
34 Correct 410 ms 64324 KB Output is correct
35 Correct 430 ms 62352 KB Output is correct
36 Correct 462 ms 62408 KB Output is correct
37 Correct 266 ms 58504 KB Output is correct
38 Correct 347 ms 64668 KB Output is correct
39 Correct 291 ms 64640 KB Output is correct
40 Correct 302 ms 64588 KB Output is correct
41 Correct 11 ms 33108 KB Output is correct
42 Correct 481 ms 64572 KB Output is correct
43 Correct 303 ms 58196 KB Output is correct
44 Correct 414 ms 64300 KB Output is correct
45 Correct 447 ms 64744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 33108 KB Output is correct
2 Correct 11 ms 33176 KB Output is correct
3 Correct 11 ms 33192 KB Output is correct
4 Correct 11 ms 33144 KB Output is correct
5 Correct 12 ms 33108 KB Output is correct
6 Correct 12 ms 33172 KB Output is correct
7 Correct 12 ms 33108 KB Output is correct
8 Correct 12 ms 33108 KB Output is correct
9 Correct 12 ms 33080 KB Output is correct
10 Correct 12 ms 33140 KB Output is correct
11 Correct 11 ms 33188 KB Output is correct
12 Correct 12 ms 33156 KB Output is correct
13 Correct 11 ms 33160 KB Output is correct
14 Correct 12 ms 33108 KB Output is correct
15 Correct 11 ms 33108 KB Output is correct
16 Correct 11 ms 33200 KB Output is correct
17 Correct 14 ms 33504 KB Output is correct
18 Correct 15 ms 33568 KB Output is correct
19 Correct 15 ms 33620 KB Output is correct
20 Correct 15 ms 33492 KB Output is correct
21 Correct 15 ms 33508 KB Output is correct
22 Correct 16 ms 33572 KB Output is correct
23 Correct 14 ms 33492 KB Output is correct
24 Correct 212 ms 58124 KB Output is correct
25 Correct 302 ms 64060 KB Output is correct
26 Correct 238 ms 57916 KB Output is correct
27 Correct 308 ms 64108 KB Output is correct
28 Correct 293 ms 57976 KB Output is correct
29 Correct 272 ms 58356 KB Output is correct
30 Correct 444 ms 64580 KB Output is correct
31 Correct 137 ms 47904 KB Output is correct
32 Correct 193 ms 50892 KB Output is correct
33 Correct 319 ms 58300 KB Output is correct
34 Correct 410 ms 64324 KB Output is correct
35 Correct 430 ms 62352 KB Output is correct
36 Correct 462 ms 62408 KB Output is correct
37 Correct 266 ms 58504 KB Output is correct
38 Correct 347 ms 64668 KB Output is correct
39 Correct 291 ms 64640 KB Output is correct
40 Correct 302 ms 64588 KB Output is correct
41 Correct 11 ms 33108 KB Output is correct
42 Correct 481 ms 64572 KB Output is correct
43 Correct 303 ms 58196 KB Output is correct
44 Correct 414 ms 64300 KB Output is correct
45 Correct 447 ms 64744 KB Output is correct
46 Correct 1211 ms 123628 KB Output is correct
47 Correct 1539 ms 146688 KB Output is correct
48 Correct 1454 ms 146620 KB Output is correct
49 Correct 1440 ms 146548 KB Output is correct
50 Correct 2863 ms 146784 KB Output is correct
51 Correct 1677 ms 119708 KB Output is correct
52 Correct 2269 ms 142712 KB Output is correct
53 Correct 2584 ms 150844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 313 ms 64236 KB Output is correct
2 Correct 311 ms 64056 KB Output is correct
3 Correct 241 ms 58044 KB Output is correct
4 Correct 232 ms 57792 KB Output is correct
5 Correct 12 ms 33108 KB Output is correct
6 Correct 291 ms 63544 KB Output is correct
7 Correct 63 ms 45396 KB Output is correct
8 Correct 221 ms 51692 KB Output is correct
9 Correct 231 ms 57940 KB Output is correct
10 Correct 268 ms 64056 KB Output is correct
11 Correct 205 ms 58024 KB Output is correct
12 Correct 12 ms 33108 KB Output is correct
13 Correct 11 ms 33176 KB Output is correct
14 Correct 11 ms 33192 KB Output is correct
15 Correct 11 ms 33144 KB Output is correct
16 Correct 12 ms 33108 KB Output is correct
17 Correct 12 ms 33172 KB Output is correct
18 Correct 12 ms 33108 KB Output is correct
19 Correct 12 ms 33108 KB Output is correct
20 Correct 12 ms 33080 KB Output is correct
21 Correct 12 ms 33140 KB Output is correct
22 Correct 11 ms 33188 KB Output is correct
23 Correct 12 ms 33156 KB Output is correct
24 Correct 11 ms 33160 KB Output is correct
25 Correct 12 ms 33108 KB Output is correct
26 Correct 11 ms 33108 KB Output is correct
27 Correct 11 ms 33200 KB Output is correct
28 Correct 14 ms 33504 KB Output is correct
29 Correct 15 ms 33568 KB Output is correct
30 Correct 15 ms 33620 KB Output is correct
31 Correct 15 ms 33492 KB Output is correct
32 Correct 15 ms 33508 KB Output is correct
33 Correct 16 ms 33572 KB Output is correct
34 Correct 14 ms 33492 KB Output is correct
35 Correct 212 ms 58124 KB Output is correct
36 Correct 302 ms 64060 KB Output is correct
37 Correct 238 ms 57916 KB Output is correct
38 Correct 308 ms 64108 KB Output is correct
39 Correct 293 ms 57976 KB Output is correct
40 Correct 272 ms 58356 KB Output is correct
41 Correct 444 ms 64580 KB Output is correct
42 Correct 137 ms 47904 KB Output is correct
43 Correct 193 ms 50892 KB Output is correct
44 Correct 319 ms 58300 KB Output is correct
45 Correct 410 ms 64324 KB Output is correct
46 Correct 430 ms 62352 KB Output is correct
47 Correct 462 ms 62408 KB Output is correct
48 Correct 266 ms 58504 KB Output is correct
49 Correct 347 ms 64668 KB Output is correct
50 Correct 291 ms 64640 KB Output is correct
51 Correct 302 ms 64588 KB Output is correct
52 Correct 11 ms 33108 KB Output is correct
53 Correct 481 ms 64572 KB Output is correct
54 Correct 303 ms 58196 KB Output is correct
55 Correct 414 ms 64300 KB Output is correct
56 Correct 447 ms 64744 KB Output is correct
57 Correct 261 ms 57504 KB Output is correct
58 Correct 324 ms 72196 KB Output is correct
59 Correct 298 ms 70136 KB Output is correct
60 Correct 302 ms 70172 KB Output is correct
61 Correct 457 ms 68844 KB Output is correct
62 Correct 14 ms 33108 KB Output is correct
63 Correct 459 ms 71996 KB Output is correct
64 Correct 301 ms 65212 KB Output is correct
65 Correct 401 ms 71440 KB Output is correct
66 Correct 433 ms 65624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 313 ms 64236 KB Output is correct
2 Correct 311 ms 64056 KB Output is correct
3 Correct 241 ms 58044 KB Output is correct
4 Correct 232 ms 57792 KB Output is correct
5 Correct 12 ms 33108 KB Output is correct
6 Correct 291 ms 63544 KB Output is correct
7 Correct 63 ms 45396 KB Output is correct
8 Correct 221 ms 51692 KB Output is correct
9 Correct 231 ms 57940 KB Output is correct
10 Correct 268 ms 64056 KB Output is correct
11 Correct 205 ms 58024 KB Output is correct
12 Correct 12 ms 33108 KB Output is correct
13 Correct 11 ms 33176 KB Output is correct
14 Correct 11 ms 33192 KB Output is correct
15 Correct 11 ms 33144 KB Output is correct
16 Correct 12 ms 33108 KB Output is correct
17 Correct 12 ms 33172 KB Output is correct
18 Correct 12 ms 33108 KB Output is correct
19 Correct 12 ms 33108 KB Output is correct
20 Correct 12 ms 33080 KB Output is correct
21 Correct 12 ms 33140 KB Output is correct
22 Correct 11 ms 33188 KB Output is correct
23 Correct 12 ms 33156 KB Output is correct
24 Correct 11 ms 33160 KB Output is correct
25 Correct 12 ms 33108 KB Output is correct
26 Correct 11 ms 33108 KB Output is correct
27 Correct 11 ms 33200 KB Output is correct
28 Correct 14 ms 33504 KB Output is correct
29 Correct 15 ms 33568 KB Output is correct
30 Correct 15 ms 33620 KB Output is correct
31 Correct 15 ms 33492 KB Output is correct
32 Correct 15 ms 33508 KB Output is correct
33 Correct 16 ms 33572 KB Output is correct
34 Correct 14 ms 33492 KB Output is correct
35 Correct 212 ms 58124 KB Output is correct
36 Correct 302 ms 64060 KB Output is correct
37 Correct 238 ms 57916 KB Output is correct
38 Correct 308 ms 64108 KB Output is correct
39 Correct 293 ms 57976 KB Output is correct
40 Correct 272 ms 58356 KB Output is correct
41 Correct 444 ms 64580 KB Output is correct
42 Correct 137 ms 47904 KB Output is correct
43 Correct 193 ms 50892 KB Output is correct
44 Correct 319 ms 58300 KB Output is correct
45 Correct 410 ms 64324 KB Output is correct
46 Correct 430 ms 62352 KB Output is correct
47 Correct 462 ms 62408 KB Output is correct
48 Correct 266 ms 58504 KB Output is correct
49 Correct 347 ms 64668 KB Output is correct
50 Correct 291 ms 64640 KB Output is correct
51 Correct 302 ms 64588 KB Output is correct
52 Correct 11 ms 33108 KB Output is correct
53 Correct 481 ms 64572 KB Output is correct
54 Correct 303 ms 58196 KB Output is correct
55 Correct 414 ms 64300 KB Output is correct
56 Correct 447 ms 64744 KB Output is correct
57 Correct 1211 ms 123628 KB Output is correct
58 Correct 1539 ms 146688 KB Output is correct
59 Correct 1454 ms 146620 KB Output is correct
60 Correct 1440 ms 146548 KB Output is correct
61 Correct 2863 ms 146784 KB Output is correct
62 Correct 1677 ms 119708 KB Output is correct
63 Correct 2269 ms 142712 KB Output is correct
64 Correct 2584 ms 150844 KB Output is correct
65 Correct 261 ms 57504 KB Output is correct
66 Correct 324 ms 72196 KB Output is correct
67 Correct 298 ms 70136 KB Output is correct
68 Correct 302 ms 70172 KB Output is correct
69 Correct 457 ms 68844 KB Output is correct
70 Correct 14 ms 33108 KB Output is correct
71 Correct 459 ms 71996 KB Output is correct
72 Correct 301 ms 65212 KB Output is correct
73 Correct 401 ms 71440 KB Output is correct
74 Correct 433 ms 65624 KB Output is correct
75 Correct 1256 ms 149712 KB Output is correct
76 Correct 1598 ms 174124 KB Output is correct
77 Correct 1497 ms 168404 KB Output is correct
78 Correct 1523 ms 168360 KB Output is correct
79 Correct 2791 ms 173052 KB Output is correct
80 Correct 1593 ms 141620 KB Output is correct
81 Correct 2232 ms 161680 KB Output is correct
82 Correct 2720 ms 151828 KB Output is correct
83 Correct 2897 ms 151852 KB Output is correct