Submission #104724

# Submission time Handle Problem Language Result Execution time Memory
104724 2019-04-09T03:11:02 Z minhtung0404 Two Dishes (JOI19_dishes) C++17
74 / 100
7401 ms 81404 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);
}

int Find(int i, int l, int r, int pos, long long k){
    dolazy(i, l, r);
    if (r < pos || sum[i] < k) return -1;
    if (l == r) return l;
    int mid = (l + r) >> 1;
    int ans = Find(i << 1, l, mid, pos, k);
    if (ans == -1) ans = Find(i << 1 | 1, mid+1, r, pos, k - sum[i << 1]);
    return ans;
}

void change(int pos){
    int x = Find(1, 1, n, pos, get(1, 1, n, 1, pos-1));
    if (x == pos) return;
    if (x == -1) x = n+1;
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 451 ms 25720 KB Output is correct
2 Correct 424 ms 24152 KB Output is correct
3 Correct 223 ms 20580 KB Output is correct
4 Correct 345 ms 23160 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 382 ms 23416 KB Output is correct
7 Correct 97 ms 11516 KB Output is correct
8 Correct 108 ms 13240 KB Output is correct
9 Correct 218 ms 20364 KB Output is correct
10 Correct 430 ms 23116 KB Output is correct
11 Correct 160 ms 18680 KB Output is correct
# Verdict Execution time Memory 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 428 KB Output is correct
5 Correct 3 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 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory 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 428 KB Output is correct
5 Correct 3 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 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 7 ms 640 KB Output is correct
22 Correct 7 ms 640 KB Output is correct
23 Correct 9 ms 640 KB Output is correct
# Verdict Execution time Memory 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 428 KB Output is correct
5 Correct 3 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 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 7 ms 640 KB Output is correct
22 Correct 7 ms 640 KB Output is correct
23 Correct 9 ms 640 KB Output is correct
24 Correct 426 ms 26032 KB Output is correct
25 Correct 301 ms 21256 KB Output is correct
26 Correct 286 ms 25040 KB Output is correct
27 Correct 343 ms 25856 KB Output is correct
28 Correct 378 ms 25800 KB Output is correct
29 Correct 161 ms 20872 KB Output is correct
30 Correct 1016 ms 25688 KB Output is correct
31 Correct 115 ms 10104 KB Output is correct
32 Correct 223 ms 15916 KB Output is correct
33 Correct 681 ms 25840 KB Output is correct
34 Correct 721 ms 25428 KB Output is correct
35 Correct 1000 ms 20216 KB Output is correct
36 Correct 1052 ms 20344 KB Output is correct
# Verdict Execution time Memory 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 428 KB Output is correct
5 Correct 3 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 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 7 ms 640 KB Output is correct
22 Correct 7 ms 640 KB Output is correct
23 Correct 9 ms 640 KB Output is correct
24 Correct 426 ms 26032 KB Output is correct
25 Correct 301 ms 21256 KB Output is correct
26 Correct 286 ms 25040 KB Output is correct
27 Correct 343 ms 25856 KB Output is correct
28 Correct 378 ms 25800 KB Output is correct
29 Correct 161 ms 20872 KB Output is correct
30 Correct 1016 ms 25688 KB Output is correct
31 Correct 115 ms 10104 KB Output is correct
32 Correct 223 ms 15916 KB Output is correct
33 Correct 681 ms 25840 KB Output is correct
34 Correct 721 ms 25428 KB Output is correct
35 Correct 1000 ms 20216 KB Output is correct
36 Correct 1052 ms 20344 KB Output is correct
37 Correct 279 ms 24788 KB Output is correct
38 Correct 467 ms 25116 KB Output is correct
39 Correct 636 ms 25468 KB Output is correct
40 Correct 471 ms 25100 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1168 ms 25100 KB Output is correct
43 Correct 607 ms 24652 KB Output is correct
44 Correct 714 ms 24272 KB Output is correct
45 Correct 970 ms 23160 KB Output is correct
# Verdict Execution time Memory 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 428 KB Output is correct
5 Correct 3 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 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 7 ms 640 KB Output is correct
22 Correct 7 ms 640 KB Output is correct
23 Correct 9 ms 640 KB Output is correct
24 Correct 426 ms 26032 KB Output is correct
25 Correct 301 ms 21256 KB Output is correct
26 Correct 286 ms 25040 KB Output is correct
27 Correct 343 ms 25856 KB Output is correct
28 Correct 378 ms 25800 KB Output is correct
29 Correct 161 ms 20872 KB Output is correct
30 Correct 1016 ms 25688 KB Output is correct
31 Correct 115 ms 10104 KB Output is correct
32 Correct 223 ms 15916 KB Output is correct
33 Correct 681 ms 25840 KB Output is correct
34 Correct 721 ms 25428 KB Output is correct
35 Correct 1000 ms 20216 KB Output is correct
36 Correct 1052 ms 20344 KB Output is correct
37 Correct 279 ms 24788 KB Output is correct
38 Correct 467 ms 25116 KB Output is correct
39 Correct 636 ms 25468 KB Output is correct
40 Correct 471 ms 25100 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1168 ms 25100 KB Output is correct
43 Correct 607 ms 24652 KB Output is correct
44 Correct 714 ms 24272 KB Output is correct
45 Correct 970 ms 23160 KB Output is correct
46 Correct 1822 ms 79304 KB Output is correct
47 Correct 2349 ms 81148 KB Output is correct
48 Correct 3382 ms 79460 KB Output is correct
49 Correct 2383 ms 77684 KB Output is correct
50 Correct 7401 ms 81404 KB Output is correct
51 Correct 4114 ms 78824 KB Output is correct
52 Correct 4829 ms 76616 KB Output is correct
53 Correct 6785 ms 77244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 25720 KB Output is correct
2 Correct 424 ms 24152 KB Output is correct
3 Correct 223 ms 20580 KB Output is correct
4 Correct 345 ms 23160 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 382 ms 23416 KB Output is correct
7 Correct 97 ms 11516 KB Output is correct
8 Correct 108 ms 13240 KB Output is correct
9 Correct 218 ms 20364 KB Output is correct
10 Correct 430 ms 23116 KB Output is correct
11 Correct 160 ms 18680 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 428 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 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 2 ms 384 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 8 ms 640 KB Output is correct
30 Correct 7 ms 640 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 7 ms 640 KB Output is correct
33 Correct 7 ms 640 KB Output is correct
34 Correct 9 ms 640 KB Output is correct
35 Correct 426 ms 26032 KB Output is correct
36 Correct 301 ms 21256 KB Output is correct
37 Correct 286 ms 25040 KB Output is correct
38 Correct 343 ms 25856 KB Output is correct
39 Correct 378 ms 25800 KB Output is correct
40 Correct 161 ms 20872 KB Output is correct
41 Correct 1016 ms 25688 KB Output is correct
42 Correct 115 ms 10104 KB Output is correct
43 Correct 223 ms 15916 KB Output is correct
44 Correct 681 ms 25840 KB Output is correct
45 Correct 721 ms 25428 KB Output is correct
46 Correct 1000 ms 20216 KB Output is correct
47 Correct 1052 ms 20344 KB Output is correct
48 Correct 279 ms 24788 KB Output is correct
49 Correct 467 ms 25116 KB Output is correct
50 Correct 636 ms 25468 KB Output is correct
51 Correct 471 ms 25100 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1168 ms 25100 KB Output is correct
54 Correct 607 ms 24652 KB Output is correct
55 Correct 714 ms 24272 KB Output is correct
56 Correct 970 ms 23160 KB Output is correct
57 Correct 408 ms 25124 KB Output is correct
58 Correct 416 ms 23764 KB Output is correct
59 Incorrect 470 ms 24184 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 451 ms 25720 KB Output is correct
2 Correct 424 ms 24152 KB Output is correct
3 Correct 223 ms 20580 KB Output is correct
4 Correct 345 ms 23160 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 382 ms 23416 KB Output is correct
7 Correct 97 ms 11516 KB Output is correct
8 Correct 108 ms 13240 KB Output is correct
9 Correct 218 ms 20364 KB Output is correct
10 Correct 430 ms 23116 KB Output is correct
11 Correct 160 ms 18680 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 428 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 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 2 ms 384 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 6 ms 640 KB Output is correct
29 Correct 8 ms 640 KB Output is correct
30 Correct 7 ms 640 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 7 ms 640 KB Output is correct
33 Correct 7 ms 640 KB Output is correct
34 Correct 9 ms 640 KB Output is correct
35 Correct 426 ms 26032 KB Output is correct
36 Correct 301 ms 21256 KB Output is correct
37 Correct 286 ms 25040 KB Output is correct
38 Correct 343 ms 25856 KB Output is correct
39 Correct 378 ms 25800 KB Output is correct
40 Correct 161 ms 20872 KB Output is correct
41 Correct 1016 ms 25688 KB Output is correct
42 Correct 115 ms 10104 KB Output is correct
43 Correct 223 ms 15916 KB Output is correct
44 Correct 681 ms 25840 KB Output is correct
45 Correct 721 ms 25428 KB Output is correct
46 Correct 1000 ms 20216 KB Output is correct
47 Correct 1052 ms 20344 KB Output is correct
48 Correct 279 ms 24788 KB Output is correct
49 Correct 467 ms 25116 KB Output is correct
50 Correct 636 ms 25468 KB Output is correct
51 Correct 471 ms 25100 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1168 ms 25100 KB Output is correct
54 Correct 607 ms 24652 KB Output is correct
55 Correct 714 ms 24272 KB Output is correct
56 Correct 970 ms 23160 KB Output is correct
57 Correct 1822 ms 79304 KB Output is correct
58 Correct 2349 ms 81148 KB Output is correct
59 Correct 3382 ms 79460 KB Output is correct
60 Correct 2383 ms 77684 KB Output is correct
61 Correct 7401 ms 81404 KB Output is correct
62 Correct 4114 ms 78824 KB Output is correct
63 Correct 4829 ms 76616 KB Output is correct
64 Correct 6785 ms 77244 KB Output is correct
65 Correct 408 ms 25124 KB Output is correct
66 Correct 416 ms 23764 KB Output is correct
67 Incorrect 470 ms 24184 KB Output isn't correct
68 Halted 0 ms 0 KB -