답안 #435801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435801 2021-06-23T18:07:54 Z 2qbingxuan Two Dishes (JOI19_dishes) C++17
74 / 100
2719 ms 259056 KB
#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\n")));
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
 
using namespace std;
const int maxn = 1000025;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
 
struct Item {
    int t;
    int64_t ed;
    int val;
} v[maxn], u[maxn];
int64_t sumv[maxn], sumu[maxn];
int posv[maxn], posu[maxn];
int64_t dp[maxn], dif[maxn], lim[maxn];
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> v[i].t >> v[i].ed >> v[i].val;
    for (int i = 1; i <= m; i++)
        cin >> u[i].t >> u[i].ed >> u[i].val;
    /*
    // int T = time(0);
    // debug(T);
    // srand(T);
    srand(230);
    for (int i = 1; i <= n; i++)
        v[i].t = rand() % 10000, v[i].ed = rand() % (10000 * i), v[i].val = rand() % 100 - 50;
    for (int i = 1; i <= m; i++)
        u[i].t = rand() % 10000, u[i].ed = rand() % (10000 * i), u[i].val = rand() % 100 - 50;
    */
 
    for (int i = 1; i <= n; i++)
        sumv[i] = sumv[i-1] + v[i].t;
    for (int i = 1; i <= m; i++)
        sumu[i] = sumu[i-1] + u[i].t;
 
    for (int i = 1; i <= n; i++)
        posv[i] = upper_bound(sumu, sumu+m+1, v[i].ed - sumv[i]) - sumu - 1;
    for (int i = 1; i <= m; i++)
        posu[i] = upper_bound(sumv, sumv+n+1, u[i].ed - sumu[i]) - sumv - 1;
 
    for (int j = 1; j <= m; j++) dp[j] = dp[j-1] + (posu[j] >= 0 ? u[j].val : 0);
    for (int j = 1; j <= m; j++) lim[j] = dif[j] = (posu[j] >= 0 ? u[j].val : 0);
 
    /*
    cerr << "posu:\t";
    cerr << 0 << ' ';
    for (int i = 1; i <= m; i++) cerr << posu[i] << ' ';
    cerr << '\n';
    cerr << "u.val:\t";
    cerr << 0 << ' ';
    for (int i = 1; i <= m; i++) cerr << u[i].val << ' ';
    cerr << '\n';
    */
 
    set<int> st;
    min_heap<pair<int,int>> pq;
    for (int j = 1; j <= m; j++) if (posu[j] >= 0) pq.emplace(posu[j], -j);
    // for (int j = 1; j <= m; j++) debug(j, posu[j], u[j].val);
 
    function<void(int,int,int64_t)> update = [&](int i, int j, int64_t val) {
        if (j == m+1) return;
        dif[j] -= val;
        debug(i, j, val);
        if (dif[j] <= lim[j]) {
            int64_t c = lim[j] - dif[j];
            dif[j] = lim[j];
            st.erase(j);
            auto it = st.lower_bound(j);
            if (it != st.end() && c)
                update(i, *it, c);
        } else {
            st.insert(j);
        }
        // int64_t c = max<int64_t>(0, (j != 0 && i <= posu[j] ? u[j].val : 0) - dif[j]);
    };
    for (int i = 1; i <= n; i++) {
        // vector<int> tmp;
        while (!pq.empty() && i > pq.top().first) {
            int j = -pq.top().second;
            pq.pop();
            lim[j] = 0;
            if (dif[j] > lim[j]) {
                debug(j, "ins");
                st.insert(j);
            } else {
                update(i, j, 0);
            }
        }
        if (posv[i] >= 0)
            dif[0] += v[i].val, update(i, posv[i]+1, v[i].val);
 
        /*
        for (int j = 0; j <= posv[i]; j++) dp[j] += v[i].val;
        for (int j = 1; j <= m; j++) {
            dp[j] = max(dp[j], dp[j-1] + (i <= posu[j] ? u[j].val : 0));
            for (int j = 0; j <= m; j++) cerr << (dp[j] - (j ? dp[j-1] : 0)) << ' ';
            cerr << '\n';
        }
 
        cerr << posv[i] << ';' << v[i].val << ";\n";
        for (int j = 0; j <= m; j++) cerr << (dp[j] - (j ? dp[j-1] : 0)) << ' ';
        cerr << '\n';
        for (int j = 0; j <= m; j++) cerr << dif[j] << ' ';
        cerr << '\n';
        for (int j = 0; j <= m; j++) cerr << lim[j] << ' ';
        cerr << '\n';
        for (int j = 0; j <= m; j++)
            cerr << (i<=posu[j]?u[j].val:0)<<' ';
        cerr<<'\n';
        for (int j = 0; j <= m; j++) assert (dif[j] == dp[j] - (j ? dp[j-1] : 0));
        */
    }
    debug(dp[m]);
    int64_t sum = 0;
    for (int i = 0; i <= m; i++) sum += dif[i];
    cout << sum << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 29864 KB Output is correct
2 Correct 256 ms 23516 KB Output is correct
3 Correct 215 ms 23792 KB Output is correct
4 Correct 274 ms 28040 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 262 ms 22932 KB Output is correct
7 Correct 111 ms 16868 KB Output is correct
8 Correct 99 ms 9808 KB Output is correct
9 Correct 227 ms 23800 KB Output is correct
10 Correct 218 ms 23744 KB Output is correct
11 Correct 176 ms 23772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 4 ms 580 KB Output is correct
20 Correct 3 ms 588 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 4 ms 588 KB Output is correct
23 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 4 ms 580 KB Output is correct
20 Correct 3 ms 588 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 4 ms 588 KB Output is correct
23 Correct 4 ms 588 KB Output is correct
24 Correct 189 ms 21236 KB Output is correct
25 Correct 257 ms 32564 KB Output is correct
26 Correct 194 ms 22732 KB Output is correct
27 Correct 260 ms 32588 KB Output is correct
28 Correct 250 ms 23792 KB Output is correct
29 Correct 194 ms 23764 KB Output is correct
30 Correct 383 ms 23892 KB Output is correct
31 Correct 135 ms 20636 KB Output is correct
32 Correct 94 ms 9568 KB Output is correct
33 Correct 274 ms 22596 KB Output is correct
34 Correct 338 ms 26680 KB Output is correct
35 Correct 313 ms 23592 KB Output is correct
36 Correct 326 ms 23500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 4 ms 580 KB Output is correct
20 Correct 3 ms 588 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 4 ms 588 KB Output is correct
23 Correct 4 ms 588 KB Output is correct
24 Correct 189 ms 21236 KB Output is correct
25 Correct 257 ms 32564 KB Output is correct
26 Correct 194 ms 22732 KB Output is correct
27 Correct 260 ms 32588 KB Output is correct
28 Correct 250 ms 23792 KB Output is correct
29 Correct 194 ms 23764 KB Output is correct
30 Correct 383 ms 23892 KB Output is correct
31 Correct 135 ms 20636 KB Output is correct
32 Correct 94 ms 9568 KB Output is correct
33 Correct 274 ms 22596 KB Output is correct
34 Correct 338 ms 26680 KB Output is correct
35 Correct 313 ms 23592 KB Output is correct
36 Correct 326 ms 23500 KB Output is correct
37 Correct 234 ms 22792 KB Output is correct
38 Correct 292 ms 32500 KB Output is correct
39 Correct 346 ms 54464 KB Output is correct
40 Correct 228 ms 23704 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 424 ms 23852 KB Output is correct
43 Correct 307 ms 22488 KB Output is correct
44 Correct 387 ms 26544 KB Output is correct
45 Correct 374 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 4 ms 580 KB Output is correct
20 Correct 3 ms 588 KB Output is correct
21 Correct 3 ms 716 KB Output is correct
22 Correct 4 ms 588 KB Output is correct
23 Correct 4 ms 588 KB Output is correct
24 Correct 189 ms 21236 KB Output is correct
25 Correct 257 ms 32564 KB Output is correct
26 Correct 194 ms 22732 KB Output is correct
27 Correct 260 ms 32588 KB Output is correct
28 Correct 250 ms 23792 KB Output is correct
29 Correct 194 ms 23764 KB Output is correct
30 Correct 383 ms 23892 KB Output is correct
31 Correct 135 ms 20636 KB Output is correct
32 Correct 94 ms 9568 KB Output is correct
33 Correct 274 ms 22596 KB Output is correct
34 Correct 338 ms 26680 KB Output is correct
35 Correct 313 ms 23592 KB Output is correct
36 Correct 326 ms 23500 KB Output is correct
37 Correct 234 ms 22792 KB Output is correct
38 Correct 292 ms 32500 KB Output is correct
39 Correct 346 ms 54464 KB Output is correct
40 Correct 228 ms 23704 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 424 ms 23852 KB Output is correct
43 Correct 307 ms 22488 KB Output is correct
44 Correct 387 ms 26544 KB Output is correct
45 Correct 374 ms 23756 KB Output is correct
46 Correct 1148 ms 99488 KB Output is correct
47 Correct 1614 ms 150156 KB Output is correct
48 Correct 1898 ms 259056 KB Output is correct
49 Correct 1155 ms 103308 KB Output is correct
50 Correct 2719 ms 103604 KB Output is correct
51 Correct 1816 ms 97120 KB Output is correct
52 Correct 2408 ms 114856 KB Output is correct
53 Correct 2604 ms 103336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 29864 KB Output is correct
2 Correct 256 ms 23516 KB Output is correct
3 Correct 215 ms 23792 KB Output is correct
4 Correct 274 ms 28040 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 262 ms 22932 KB Output is correct
7 Correct 111 ms 16868 KB Output is correct
8 Correct 99 ms 9808 KB Output is correct
9 Correct 227 ms 23800 KB Output is correct
10 Correct 218 ms 23744 KB Output is correct
11 Correct 176 ms 23772 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 4 ms 580 KB Output is correct
31 Correct 3 ms 588 KB Output is correct
32 Correct 3 ms 716 KB Output is correct
33 Correct 4 ms 588 KB Output is correct
34 Correct 4 ms 588 KB Output is correct
35 Correct 189 ms 21236 KB Output is correct
36 Correct 257 ms 32564 KB Output is correct
37 Correct 194 ms 22732 KB Output is correct
38 Correct 260 ms 32588 KB Output is correct
39 Correct 250 ms 23792 KB Output is correct
40 Correct 194 ms 23764 KB Output is correct
41 Correct 383 ms 23892 KB Output is correct
42 Correct 135 ms 20636 KB Output is correct
43 Correct 94 ms 9568 KB Output is correct
44 Correct 274 ms 22596 KB Output is correct
45 Correct 338 ms 26680 KB Output is correct
46 Correct 313 ms 23592 KB Output is correct
47 Correct 326 ms 23500 KB Output is correct
48 Correct 234 ms 22792 KB Output is correct
49 Correct 292 ms 32500 KB Output is correct
50 Correct 346 ms 54464 KB Output is correct
51 Correct 228 ms 23704 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 424 ms 23852 KB Output is correct
54 Correct 307 ms 22488 KB Output is correct
55 Correct 387 ms 26544 KB Output is correct
56 Correct 374 ms 23756 KB Output is correct
57 Correct 302 ms 31040 KB Output is correct
58 Correct 275 ms 23100 KB Output is correct
59 Incorrect 232 ms 22940 KB Output isn't correct
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 29864 KB Output is correct
2 Correct 256 ms 23516 KB Output is correct
3 Correct 215 ms 23792 KB Output is correct
4 Correct 274 ms 28040 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 262 ms 22932 KB Output is correct
7 Correct 111 ms 16868 KB Output is correct
8 Correct 99 ms 9808 KB Output is correct
9 Correct 227 ms 23800 KB Output is correct
10 Correct 218 ms 23744 KB Output is correct
11 Correct 176 ms 23772 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 4 ms 580 KB Output is correct
31 Correct 3 ms 588 KB Output is correct
32 Correct 3 ms 716 KB Output is correct
33 Correct 4 ms 588 KB Output is correct
34 Correct 4 ms 588 KB Output is correct
35 Correct 189 ms 21236 KB Output is correct
36 Correct 257 ms 32564 KB Output is correct
37 Correct 194 ms 22732 KB Output is correct
38 Correct 260 ms 32588 KB Output is correct
39 Correct 250 ms 23792 KB Output is correct
40 Correct 194 ms 23764 KB Output is correct
41 Correct 383 ms 23892 KB Output is correct
42 Correct 135 ms 20636 KB Output is correct
43 Correct 94 ms 9568 KB Output is correct
44 Correct 274 ms 22596 KB Output is correct
45 Correct 338 ms 26680 KB Output is correct
46 Correct 313 ms 23592 KB Output is correct
47 Correct 326 ms 23500 KB Output is correct
48 Correct 234 ms 22792 KB Output is correct
49 Correct 292 ms 32500 KB Output is correct
50 Correct 346 ms 54464 KB Output is correct
51 Correct 228 ms 23704 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 424 ms 23852 KB Output is correct
54 Correct 307 ms 22488 KB Output is correct
55 Correct 387 ms 26544 KB Output is correct
56 Correct 374 ms 23756 KB Output is correct
57 Correct 1148 ms 99488 KB Output is correct
58 Correct 1614 ms 150156 KB Output is correct
59 Correct 1898 ms 259056 KB Output is correct
60 Correct 1155 ms 103308 KB Output is correct
61 Correct 2719 ms 103604 KB Output is correct
62 Correct 1816 ms 97120 KB Output is correct
63 Correct 2408 ms 114856 KB Output is correct
64 Correct 2604 ms 103336 KB Output is correct
65 Correct 302 ms 31040 KB Output is correct
66 Correct 275 ms 23100 KB Output is correct
67 Incorrect 232 ms 22940 KB Output isn't correct
68 Halted 0 ms 0 KB -