답안 #104714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104714 2019-04-09T02:38:27 Z minhtung0404 Two Dishes (JOI19_dishes) C++17
0 / 100
554 ms 21400 KB
//https://oj.uz/problem/view/JOI19_dishes

#include<bits/stdc++.h>
const int N = 1e6 + 5;
using namespace std;

int n, m;
long long S, sum[N << 2], a[N], b[N], s[N], t[N], p[N], q[N], per[N];
bool lazy[N << 2];

void dolazy(int i, int l, int r){
    if (!lazy[i]) return;
    if (l != r){
        lazy[i << 1] = lazy[i << 1 | 1] = 1;
    }
    sum[i] = 0;
    lazy[i] = 0;
}

void update(int i, int l, int r, int L, int R){
    dolazy(i, l, r);
    if (L > r || l > R || L > R) return;
    if (L <= l && r <= R){
        lazy[i] = 1;
        dolazy(i, l, r);
        return;
    }
    int mid = (l + r) >> 1;
    update(i << 1, l, mid, L, R); update(i << 1 | 1, mid+1, r, L, R);
    sum[i] = sum[i << 1] + sum[i << 1 | 1];
}

void update_pos(int i, int l, int r, int pos, int val){
    dolazy(i, l, r);
    if (l > pos || pos > r) return;
    if (l == r){
        sum[i] += val;
        return;
    }
    int mid = (l + r) >> 1;
    update_pos(i << 1, l, mid, pos, val); update_pos(i << 1 | 1, mid+1, r, pos, val);
    sum[i] = sum[i << 1] + sum[i << 1 | 1];
}

long long get(int i, int l, int r, int L, int R){
    dolazy(i, l, r);
    if (L > r || l > R || L > R) return 0;
    if (L <= l && r <= R) return sum[i];
    int mid = (l + r) >> 1;
    return get(i << 1, l, mid, L, R) + get(i << 1 | 1, mid+1, r, L, R);
}

void change(int pos){
    if (get(1, 1, n, pos, pos) >= 0) return;
    int x = -1;
    if (get(1, 1, n, pos, n) < 0) x = n + 1;
    else{
        int l = pos, r = n;
        while (l != r){
            int mid = (l + r + 1) >> 1;
            if (get(1, 1, n, pos, mid) >= 0) l = mid;
            else r = mid-1;
        }
        x = l;
    }
    long long sum = get(1, 1, n, pos, x-1);
    update(1, 1, n, pos, x-1);
    if (x <= n) update_pos(1, 1, n, x, sum);
}

int main(){
    ios_base::sync_with_stdio(false); 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], s[i] -= a[i], per[i] = i;
    for (int i = 1; i <= m; i++) cin >> b[i] >> t[i] >> q[i], b[i] += b[i-1];
    sort(per+1, per+1+n, [](int x, int y){return s[x] < s[y];});
    int cnt = 1;
    while (cnt <= n && s[per[cnt]] < 0) p[per[cnt++]] = 0;
    for (int i = 1; i <= m; i++){
        while (cnt <= n && s[per[cnt]] < b[i]){
            int id = per[cnt++];
            update_pos(1, 1, n, id, p[id]); p[id] = 0;
            change(id);
        }
        if (b[i] > t[i]) continue;
        int l = 0, r = n;
        while (l != r){
            int mid = (l + r + 1) >> 1;
            if (b[i] + a[mid] <= t[i]) l = mid;
            else r = mid-1;
        }
        S += q[i];
        if (l != n){
            update_pos(1, 1, n, l+1, -q[i]);
            change(l+1);
        }
    }
    long long ans = S + sum[1];
    for (int i = 1; i <= n; i++) ans += p[i];
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 554 ms 21400 KB Output is correct
2 Incorrect 533 ms 20728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 3 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 3 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 3 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 3 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Incorrect 3 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 554 ms 21400 KB Output is correct
2 Incorrect 533 ms 20728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 554 ms 21400 KB Output is correct
2 Incorrect 533 ms 20728 KB Output isn't correct
3 Halted 0 ms 0 KB -