답안 #170754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170754 2019-12-26T09:24:29 Z gs18103 Two Dishes (JOI19_dishes) C++14
5 / 100
379 ms 37384 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()
#define my_assert cout << "!" << endl;

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int MAX = 1010101;
const int INF = (1 << 30) - 1;
const ll LINF = 1LL << 60;

int n, m;
ll A[MAX], S[MAX], P[MAX];
ll B[MAX], T[MAX], Q[MAX];
ll sumA[MAX], sumB[MAX], ans;
ll tree[4*MAX], lazy[4*MAX];

void update_lazy(int node, int s, int e) {
    tree[node] += lazy[node];
    if(s != e) {
        lazy[node*2] += lazy[node];
        lazy[node*2+1] += lazy[node];
    }
    lazy[node] = 0;
}

void update(int node, int s, int e, int r, ll val, ll mx) {
    update_lazy(node, s, e);
    if(s > r && tree[node] >= mx) return;
    if(e <= r) {
        lazy[node] += val;
        update_lazy(node, s, e);
        return;
    }
    else if(s > r) {
        lazy[node] = mx - tree[node];
        update_lazy(node, s, e);
        return;
    }
    int mi = (s + e) / 2;
    update(node*2, s, mi, r, val, mx);
    mx = max(mx, tree[node*2]);
    update(node*2+1, mi+1, e, r, val, mx);
    tree[node] = tree[node*2+1];
}

ll cal(int node, int s, int e) {
    update_lazy(node, s, e);
    if(s == e) return tree[node];
    int mi = (s + e) / 2;
    return cal(node*2+1, mi+1, e);
}

struct point {
    int x, y; ll val;
    point(int x, int y, ll val) : x(x), y(y), val(val) {}
};
vector <point> po;

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

    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> A[i] >> S[i] >> P[i];
        sumA[i] = sumA[i-1] + A[i];
    }
    for(int i = 1; i <= m; i++) {
        cin >> B[i] >> T[i] >> Q[i];
        sumB[i] = sumB[i-1] + B[i];
        ans += Q[i];
    }
    for(int i = 1; i <= n; i++) {
        int temp = upper_bound(sumB, sumB+m+1, S[i] - sumA[i]) - sumB - 1;
        if(temp >= 0) po.eb(i, temp, P[i]);
    }
    for(int i = 1; i <= m; i++) {
        int temp = upper_bound(sumA, sumA+n+1, T[i] - sumB[i]) - sumA - 1;
        if(temp < 0) ans -= Q[i];
        else if(temp < n) po.eb(temp+1, i-1, -Q[i]);
    }
    sort(all(po), [](point a, point b) {
        if(a.x == b.x) return a.y > b.y;
        return a.x < b.x;
    });

    ll rem = 0;
    for(int i = 0; i < po.size(); i++) {
        if(i+1 < po.size() && po[i].x == po[i+1].x && po[i].y == po[i+1].y) {
            rem += po[i].val;
            continue;
        }
        update(1, 0, m, po[i].y, po[i].val + rem, -LINF);
        rem = 0;
    }
    cout << cal(1, 0, m) + ans;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:94:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < po.size(); i++) {
                    ~~^~~~~~~~~~~
dishes.cpp:95:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i+1 < po.size() && po[i].x == po[i+1].x && po[i].y == po[i+1].y) {
            ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 28812 KB Output is correct
2 Correct 372 ms 28948 KB Output is correct
3 Correct 236 ms 20072 KB Output is correct
4 Correct 310 ms 24980 KB Output is correct
5 Correct 2 ms 420 KB Output is correct
6 Correct 351 ms 37384 KB Output is correct
7 Correct 106 ms 13616 KB Output is correct
8 Correct 122 ms 18040 KB Output is correct
9 Correct 247 ms 31492 KB Output is correct
10 Correct 306 ms 34980 KB Output is correct
11 Correct 166 ms 24980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 416 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 444 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 420 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 416 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 444 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 420 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 416 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 444 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 420 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 416 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 444 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 420 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 416 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 444 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 420 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 28812 KB Output is correct
2 Correct 372 ms 28948 KB Output is correct
3 Correct 236 ms 20072 KB Output is correct
4 Correct 310 ms 24980 KB Output is correct
5 Correct 2 ms 420 KB Output is correct
6 Correct 351 ms 37384 KB Output is correct
7 Correct 106 ms 13616 KB Output is correct
8 Correct 122 ms 18040 KB Output is correct
9 Correct 247 ms 31492 KB Output is correct
10 Correct 306 ms 34980 KB Output is correct
11 Correct 166 ms 24980 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 416 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 444 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Incorrect 2 ms 420 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 28812 KB Output is correct
2 Correct 372 ms 28948 KB Output is correct
3 Correct 236 ms 20072 KB Output is correct
4 Correct 310 ms 24980 KB Output is correct
5 Correct 2 ms 420 KB Output is correct
6 Correct 351 ms 37384 KB Output is correct
7 Correct 106 ms 13616 KB Output is correct
8 Correct 122 ms 18040 KB Output is correct
9 Correct 247 ms 31492 KB Output is correct
10 Correct 306 ms 34980 KB Output is correct
11 Correct 166 ms 24980 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 416 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 444 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Incorrect 2 ms 420 KB Output isn't correct
22 Halted 0 ms 0 KB -