Submission #157262

# Submission time Handle Problem Language Result Execution time Memory
157262 2019-10-10T09:05:54 Z atoiz Two Dishes (JOI19_dishes) C++14
10 / 100
10000 ms 48192 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <numeric>
#include <tuple>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <ios>
#include <iomanip>
#include <random>
#include <chrono>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORA(i, a) for (auto &i : a)
#define FORB(i, a, b) for (int i = a; i >= b; --i)
#define SZ(a) ((int) a.size());
#define ALL(a) begin(a), end(a)

const int MAXN = 1000007;
const ll INF = 1e16;
int N, M;
ll A[MAXN], B[MAXN], S[MAXN], T[MAXN], P[MAXN], Q[MAXN];
vector<int> ids[MAXN];

ll lazy[MAXN << 2], tree[MAXN << 2];

void push(int root, int lo, int hi)
{
    if (lo < hi) {
        tree[root << 1] += lazy[root];
        tree[root << 1 | 1] += lazy[root];
        lazy[root << 1] += lazy[root];
        lazy[root << 1 | 1] += lazy[root];
    }
    lazy[root] = 0;
}

void add(int l, int r, ll x, int root = 1, int lo = 0, int hi = M)
{
    FOR(i, l, r) tree[i] += x;
    return;
    if (r < lo || hi < l) return;
    push(root, lo, hi);
    if (l <= lo && hi <= r) {
        lazy[root] += x;
        tree[root] += x;
        return;
    }

    int mid = (lo + hi) >> 1;
    add(l, r, x, root << 1, lo, mid);
    add(l, r, x, root << 1 | 1, mid + 1, hi);
}

void upd(int l, int r, ll x, int root = 1, int lo = 0, int hi = M)
{
    FOR(i, l, r) tree[i] = max(tree[i], x);
    return;
    if (r < lo || hi < l) return;
    push(root, lo, hi);
    if (l <= lo && hi <= r) {
        tree[root] = max(tree[root], x);
        return;
    }

    int mid = (lo + hi) >> 1;
    upd(l, r, x, root << 1, lo, mid);
    upd(l, r, x, root << 1 | 1, mid + 1, hi);
}

ll get(int id, int root = 1, int lo = 0, int hi = M)
{
    return tree[id];
    push(root, lo, hi);
    if (lo == hi) return tree[root];

    int mid = (lo + hi) >> 1;
    if (id <= mid) return max(tree[root], get(id, root << 1, lo, mid));
    return max(tree[root], get(id, root << 1 | 1, mid + 1, hi));
}

ll read()
{
    ll ans = 0; bool pos = 1; register char ch = getchar();
    for (; ch == ' ' || ch == '\n'; ch = getchar());
    if (ch == '-') pos = 0, ch = getchar();
    for (; 47 < ch && ch < 58; ch = getchar()) ans = ans * 10 + ch - 48;
    return (pos ? ans : -ans);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    N = read(), M = read();
    FOR(i, 1, N) A[i] = A[i - 1] + read(), S[i] = read(), P[i] = read(); A[N + 1] = INF;
    FOR(i, 1, M) B[i] = B[i - 1] + read(), T[i] = read(), Q[i] = read(); B[M + 1] = INF;

    FOR(j, 1, M) ids[upper_bound(A, A + N + 1, T[j] - B[j]) - A].push_back(j);

    FOR(i, 1, N + 1) {
        int j = upper_bound(B, B + M + 1, S[i] - A[i]) - B - 1;
        if (j >= 0) add(0, j, P[i]);

        vector<int> &vec = ids[i];
        FORA(id, vec) add(id, M, Q[id]);

        if (0 <= j && j < M) vec.insert(lower_bound(vec.begin(), vec.end(), j + 1), j + 1);
        FORA(id, vec) upd(id, M, get(id - 1));
        // FOR(id, 1, M) tree[id] = max(tree[id], tree[id - 1]);
        // FOR(j, 0, M) {
        //     cerr << i << ' ' << j << ": " << get(j) << endl;
        // }
    }

    cout << get(M) << endl;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:28:22: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
 #define FOR(i, a, b) for (int i = a; i <= b; ++i)
                      ^
dishes.cpp:110:5: note: in expansion of macro 'FOR'
     FOR(i, 1, N) A[i] = A[i - 1] + read(), S[i] = read(), P[i] = read(); A[N + 1] = INF;
     ^~~
dishes.cpp:110:74: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     FOR(i, 1, N) A[i] = A[i - 1] + read(), S[i] = read(), P[i] = read(); A[N + 1] = INF;
                                                                          ^
dishes.cpp:28:22: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
 #define FOR(i, a, b) for (int i = a; i <= b; ++i)
                      ^
dishes.cpp:111:5: note: in expansion of macro 'FOR'
     FOR(i, 1, M) B[i] = B[i - 1] + read(), T[i] = read(), Q[i] = read(); B[M + 1] = INF;
     ^~~
dishes.cpp:111:74: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     FOR(i, 1, M) B[i] = B[i - 1] + read(), T[i] = read(), Q[i] = read(); B[M + 1] = INF;
                                                                          ^
# Verdict Execution time Memory Grader output
1 Execution timed out 10042 ms 39496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23932 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 22 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 22 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23848 KB Output is correct
14 Correct 23 ms 23928 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23932 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 22 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 22 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23848 KB Output is correct
14 Correct 23 ms 23928 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23928 KB Output is correct
17 Correct 30 ms 24184 KB Output is correct
18 Correct 30 ms 24176 KB Output is correct
19 Correct 32 ms 24184 KB Output is correct
20 Correct 27 ms 24056 KB Output is correct
21 Correct 31 ms 24188 KB Output is correct
22 Correct 31 ms 24028 KB Output is correct
23 Correct 30 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23932 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 22 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 22 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23848 KB Output is correct
14 Correct 23 ms 23928 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23928 KB Output is correct
17 Correct 30 ms 24184 KB Output is correct
18 Correct 30 ms 24176 KB Output is correct
19 Correct 32 ms 24184 KB Output is correct
20 Correct 27 ms 24056 KB Output is correct
21 Correct 31 ms 24188 KB Output is correct
22 Correct 31 ms 24028 KB Output is correct
23 Correct 30 ms 24056 KB Output is correct
24 Execution timed out 10019 ms 48192 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23932 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 22 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 22 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23848 KB Output is correct
14 Correct 23 ms 23928 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23928 KB Output is correct
17 Correct 30 ms 24184 KB Output is correct
18 Correct 30 ms 24176 KB Output is correct
19 Correct 32 ms 24184 KB Output is correct
20 Correct 27 ms 24056 KB Output is correct
21 Correct 31 ms 24188 KB Output is correct
22 Correct 31 ms 24028 KB Output is correct
23 Correct 30 ms 24056 KB Output is correct
24 Execution timed out 10019 ms 48192 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 23 ms 23932 KB Output is correct
7 Correct 23 ms 23928 KB Output is correct
8 Correct 22 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 22 ms 23928 KB Output is correct
11 Correct 23 ms 23928 KB Output is correct
12 Correct 23 ms 23928 KB Output is correct
13 Correct 24 ms 23848 KB Output is correct
14 Correct 23 ms 23928 KB Output is correct
15 Correct 23 ms 23928 KB Output is correct
16 Correct 23 ms 23928 KB Output is correct
17 Correct 30 ms 24184 KB Output is correct
18 Correct 30 ms 24176 KB Output is correct
19 Correct 32 ms 24184 KB Output is correct
20 Correct 27 ms 24056 KB Output is correct
21 Correct 31 ms 24188 KB Output is correct
22 Correct 31 ms 24028 KB Output is correct
23 Correct 30 ms 24056 KB Output is correct
24 Execution timed out 10019 ms 48192 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10042 ms 39496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10042 ms 39496 KB Time limit exceeded
2 Halted 0 ms 0 KB -