답안 #104720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104720 2019-04-09T03:00:21 Z minhtung0404 Two Dishes (JOI19_dishes) C++17
65 / 100
10000 ms 79140 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] = 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, long long 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;
            if (get(1, 1, n, pos, mid) >= 0) r = mid;
            else l = 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);
}

signed 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 469 ms 15868 KB Output is correct
2 Correct 516 ms 15480 KB Output is correct
3 Correct 181 ms 11640 KB Output is correct
4 Correct 372 ms 15096 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 765 ms 14584 KB Output is correct
7 Correct 105 ms 5216 KB Output is correct
8 Correct 157 ms 6952 KB Output is correct
9 Correct 207 ms 11556 KB Output is correct
10 Correct 1042 ms 16376 KB Output is correct
11 Correct 144 ms 11512 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 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 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 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 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 10 ms 640 KB Output is correct
20 Correct 7 ms 640 KB Output is correct
21 Correct 7 ms 640 KB Output is correct
22 Correct 11 ms 640 KB Output is correct
23 Correct 12 ms 768 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 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 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 10 ms 640 KB Output is correct
20 Correct 7 ms 640 KB Output is correct
21 Correct 7 ms 640 KB Output is correct
22 Correct 11 ms 640 KB Output is correct
23 Correct 12 ms 768 KB Output is correct
24 Correct 441 ms 21168 KB Output is correct
25 Correct 313 ms 17016 KB Output is correct
26 Correct 263 ms 21112 KB Output is correct
27 Correct 472 ms 21612 KB Output is correct
28 Correct 866 ms 21532 KB Output is correct
29 Correct 173 ms 17016 KB Output is correct
30 Correct 2513 ms 21396 KB Output is correct
31 Correct 101 ms 10360 KB Output is correct
32 Correct 213 ms 16044 KB Output is correct
33 Correct 1281 ms 21292 KB Output is correct
34 Correct 1163 ms 20968 KB Output is correct
35 Correct 2181 ms 20284 KB Output is correct
36 Correct 2298 ms 20356 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 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 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 10 ms 640 KB Output is correct
20 Correct 7 ms 640 KB Output is correct
21 Correct 7 ms 640 KB Output is correct
22 Correct 11 ms 640 KB Output is correct
23 Correct 12 ms 768 KB Output is correct
24 Correct 441 ms 21168 KB Output is correct
25 Correct 313 ms 17016 KB Output is correct
26 Correct 263 ms 21112 KB Output is correct
27 Correct 472 ms 21612 KB Output is correct
28 Correct 866 ms 21532 KB Output is correct
29 Correct 173 ms 17016 KB Output is correct
30 Correct 2513 ms 21396 KB Output is correct
31 Correct 101 ms 10360 KB Output is correct
32 Correct 213 ms 16044 KB Output is correct
33 Correct 1281 ms 21292 KB Output is correct
34 Correct 1163 ms 20968 KB Output is correct
35 Correct 2181 ms 20284 KB Output is correct
36 Correct 2298 ms 20356 KB Output is correct
37 Correct 302 ms 20828 KB Output is correct
38 Correct 455 ms 21248 KB Output is correct
39 Correct 1741 ms 21424 KB Output is correct
40 Correct 322 ms 20856 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 2586 ms 21288 KB Output is correct
43 Correct 1248 ms 21168 KB Output is correct
44 Correct 1283 ms 20820 KB Output is correct
45 Correct 2522 ms 21372 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 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 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 10 ms 640 KB Output is correct
20 Correct 7 ms 640 KB Output is correct
21 Correct 7 ms 640 KB Output is correct
22 Correct 11 ms 640 KB Output is correct
23 Correct 12 ms 768 KB Output is correct
24 Correct 441 ms 21168 KB Output is correct
25 Correct 313 ms 17016 KB Output is correct
26 Correct 263 ms 21112 KB Output is correct
27 Correct 472 ms 21612 KB Output is correct
28 Correct 866 ms 21532 KB Output is correct
29 Correct 173 ms 17016 KB Output is correct
30 Correct 2513 ms 21396 KB Output is correct
31 Correct 101 ms 10360 KB Output is correct
32 Correct 213 ms 16044 KB Output is correct
33 Correct 1281 ms 21292 KB Output is correct
34 Correct 1163 ms 20968 KB Output is correct
35 Correct 2181 ms 20284 KB Output is correct
36 Correct 2298 ms 20356 KB Output is correct
37 Correct 302 ms 20828 KB Output is correct
38 Correct 455 ms 21248 KB Output is correct
39 Correct 1741 ms 21424 KB Output is correct
40 Correct 322 ms 20856 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 2586 ms 21288 KB Output is correct
43 Correct 1248 ms 21168 KB Output is correct
44 Correct 1283 ms 20820 KB Output is correct
45 Correct 2522 ms 21372 KB Output is correct
46 Correct 1535 ms 77052 KB Output is correct
47 Correct 2600 ms 79140 KB Output is correct
48 Execution timed out 10028 ms 77988 KB Time limit exceeded
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 469 ms 15868 KB Output is correct
2 Correct 516 ms 15480 KB Output is correct
3 Correct 181 ms 11640 KB Output is correct
4 Correct 372 ms 15096 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 765 ms 14584 KB Output is correct
7 Correct 105 ms 5216 KB Output is correct
8 Correct 157 ms 6952 KB Output is correct
9 Correct 207 ms 11556 KB Output is correct
10 Correct 1042 ms 16376 KB Output is correct
11 Correct 144 ms 11512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 7 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 10 ms 640 KB Output is correct
31 Correct 7 ms 640 KB Output is correct
32 Correct 7 ms 640 KB Output is correct
33 Correct 11 ms 640 KB Output is correct
34 Correct 12 ms 768 KB Output is correct
35 Correct 441 ms 21168 KB Output is correct
36 Correct 313 ms 17016 KB Output is correct
37 Correct 263 ms 21112 KB Output is correct
38 Correct 472 ms 21612 KB Output is correct
39 Correct 866 ms 21532 KB Output is correct
40 Correct 173 ms 17016 KB Output is correct
41 Correct 2513 ms 21396 KB Output is correct
42 Correct 101 ms 10360 KB Output is correct
43 Correct 213 ms 16044 KB Output is correct
44 Correct 1281 ms 21292 KB Output is correct
45 Correct 1163 ms 20968 KB Output is correct
46 Correct 2181 ms 20284 KB Output is correct
47 Correct 2298 ms 20356 KB Output is correct
48 Correct 302 ms 20828 KB Output is correct
49 Correct 455 ms 21248 KB Output is correct
50 Correct 1741 ms 21424 KB Output is correct
51 Correct 322 ms 20856 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 2586 ms 21288 KB Output is correct
54 Correct 1248 ms 21168 KB Output is correct
55 Correct 1283 ms 20820 KB Output is correct
56 Correct 2522 ms 21372 KB Output is correct
57 Correct 383 ms 20552 KB Output is correct
58 Correct 346 ms 20176 KB Output is correct
59 Incorrect 512 ms 20244 KB Output isn't correct
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 469 ms 15868 KB Output is correct
2 Correct 516 ms 15480 KB Output is correct
3 Correct 181 ms 11640 KB Output is correct
4 Correct 372 ms 15096 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 765 ms 14584 KB Output is correct
7 Correct 105 ms 5216 KB Output is correct
8 Correct 157 ms 6952 KB Output is correct
9 Correct 207 ms 11556 KB Output is correct
10 Correct 1042 ms 16376 KB Output is correct
11 Correct 144 ms 11512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 7 ms 640 KB Output is correct
29 Correct 4 ms 640 KB Output is correct
30 Correct 10 ms 640 KB Output is correct
31 Correct 7 ms 640 KB Output is correct
32 Correct 7 ms 640 KB Output is correct
33 Correct 11 ms 640 KB Output is correct
34 Correct 12 ms 768 KB Output is correct
35 Correct 441 ms 21168 KB Output is correct
36 Correct 313 ms 17016 KB Output is correct
37 Correct 263 ms 21112 KB Output is correct
38 Correct 472 ms 21612 KB Output is correct
39 Correct 866 ms 21532 KB Output is correct
40 Correct 173 ms 17016 KB Output is correct
41 Correct 2513 ms 21396 KB Output is correct
42 Correct 101 ms 10360 KB Output is correct
43 Correct 213 ms 16044 KB Output is correct
44 Correct 1281 ms 21292 KB Output is correct
45 Correct 1163 ms 20968 KB Output is correct
46 Correct 2181 ms 20284 KB Output is correct
47 Correct 2298 ms 20356 KB Output is correct
48 Correct 302 ms 20828 KB Output is correct
49 Correct 455 ms 21248 KB Output is correct
50 Correct 1741 ms 21424 KB Output is correct
51 Correct 322 ms 20856 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 2586 ms 21288 KB Output is correct
54 Correct 1248 ms 21168 KB Output is correct
55 Correct 1283 ms 20820 KB Output is correct
56 Correct 2522 ms 21372 KB Output is correct
57 Correct 1535 ms 77052 KB Output is correct
58 Correct 2600 ms 79140 KB Output is correct
59 Execution timed out 10028 ms 77988 KB Time limit exceeded
60 Halted 0 ms 0 KB -