Submission #679510

# Submission time Handle Problem Language Result Execution time Memory
679510 2023-01-08T12:36:59 Z keta_tsimakuridze Two Dishes (JOI19_dishes) C++14
82 / 100
6236 ms 136980 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7, inf = 1e18; // !
int lazy[4 * N][2], a[N][2], c[N][2], s[N][2], n[2];
vector<pii> x[N];
pii t[4 * N];
pii merge(pii x, pii y) {
    return (x.f < y.f ? y : x);
}
void push(int u, int l, int r) {
    if(lazy[u][0] != -inf) {
        t[u].f = lazy[u][0];
        if(l < r) {
            lazy[2 * u][1] = lazy[2 * u + 1][1] = 0;
            lazy[2 * u][0] = lazy[2 * u + 1][0] = lazy[u][0];
        }
        lazy[u][0] = -inf;
    }
    if(lazy[u][1] != 0) {
        t[u].f += lazy[u][1];
        if(l < r) {
            lazy[2 * u][1] += lazy[u][1];
            lazy[2 * u + 1][1] += lazy[u][1];
        }
        lazy[u][1] = 0;
    }
}
void upd(int u, int st, int en, int l, int r, int x, int T) {
    push(u, l, r);
    if(l > en || r < st) return;
    if(st <= l && r <= en) {
        lazy[u][T] = x;
        push(u, l, r);
        return;
    }
    int mid = (l + r) / 2;
    upd(2 * u, st, en, l, mid, x, T); upd(2 * u + 1, st, en, mid + 1, r, x, T);
    t[u] = merge(t[2 * u], t[2 * u + 1]);
}
pii get(int u, int st, int en, int l, int r) {
    push(u, l, r);
    if(l > en || r < st) return {-inf, 0};
    if(st <= l && r <= en) return t[u];
    int mid = (l + r) / 2;

    pii x = merge(get(2 * u, st, en, l, mid), get(2 * u + 1, st, en, mid + 1, r));
    t[u] = merge(t[2 * u], t[2 * u + 1]);
    return x;
}
void build(int u, int l, int r) {
    t[u].s = l; lazy[u][0] = -inf;
    if(l == r) return;
    build(2 * u, l, (l + r) / 2); build(2 * u + 1, (l + r)/ 2 + 1, r);
}
main(){
    int  m;
    cin >> n[0] >> n[1];
    for(int t = 0; t < 2; t++) {
        for(int i = 1; i <= n[t]; i++) {
            cin >> a[i][t] >> s[i][t] >> c[i][t];
            a[i][t] += a[i - 1][t];
        }
    }
    int ans = 0;
    for(int t = 0; t < 2; t++) {
        int R = n[t^1];
        for(int i = 1; i <= n[t]; i++) {

            int l = 0, r = n[t^1], R = -1;

            while(l <= r) {
                int mid = (l + r) / 2;
                if(a[i][t] + a[mid][t^1] <= s[i][t]) R = mid, l = mid + 1;
                else r = mid - 1;
            }
            if(!t) {
                // R tu aris i - s win mashin ver vigebt
                ++R;
                ans += c[i][t];
                if(R == n[1] + 1) continue;
                x[i].push_back({R, -c[i][t]});
                continue;
            }
            ++R;
            if(R == n[0] + 1) {
                ans += c[i][t];
                continue;
            }
            // R tu aris i - s shemdeg mashin vigebt
            // i tu aris R - is win mashin vigebt

            x[R].push_back({i, c[i][t]});
        }
    }
/*
    vector<int> dp(n[1] + 1);
    for(int i = 1; i <= n[0]; i++) {
        for(int j = 1; j <= n[1]; j++) dp[j] = max(dp[j], dp[j - 1]);
        sort(x[i].begin(), x[i].end());

        for(int k = 0; k < x[i].size(); k++) {
            for(int j = x[i][k].f; j <= n[1]; j++) dp[j] += x[i][k].s;
        }
    }
    int mn = -inf;
    for(int i = 0; i <= n[1]; i++) mn = max(mn, dp[i]);
    cout << ans + mn << "\n";
    return 0; */
    build(1, 0, n[1]);
    for(int i = 1; i <= n[0]; i++) {
        x[i].push_back({0, 0});
        x[i].push_back({n[1] + 1, 0});
        sort(x[i].begin(), x[i].end());
        int c = 0, mx = -inf;
        vector<int> v;
        for(int j = 0; j + 1 < x[i].size(); j++) {
            c += x[i][j].s;
            if(x[i][j + 1].f != x[i][j].f) {
                upd(1, x[i][j].f, -1 + x[i][j + 1].f, 0, n[1], c, 1);
                int mx = get(1, 0, x[i][j].f - 1, 0, n[1]).f;
                int l = x[i][j].f, r = -1 + x[i][j + 1].f, id = x[i][j].f - 1;
                while(l <= r) {
                    int mid = (l + r) / 2;
                    if(get(1, mid, mid, 0, n[1]).f <= mx) id = mid, l = mid + 1;
                    else r = mid - 1;
                }
                upd(1, x[i][j].f, id, 0, n[1], mx, 0);
            }
        }
    }
    cout << t[1].f + ans;

 }

Compilation message

dishes.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main(){
      | ^~~~
dishes.cpp: In function 'int main()':
dishes.cpp:70:13: warning: unused variable 'R' [-Wunused-variable]
   70 |         int R = n[t^1];
      |             ^
dishes.cpp:120:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |         for(int j = 0; j + 1 < x[i].size(); j++) {
      |                        ~~~~~~^~~~~~~~~~~~~
dishes.cpp:118:20: warning: unused variable 'mx' [-Wunused-variable]
  118 |         int c = 0, mx = -inf;
      |                    ^~
dishes.cpp:60:10: warning: unused variable 'm' [-Wunused-variable]
   60 |     int  m;
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 3055 ms 50824 KB Output is correct
2 Correct 2927 ms 62892 KB Output is correct
3 Correct 1592 ms 53552 KB Output is correct
4 Correct 2472 ms 61384 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2698 ms 60508 KB Output is correct
7 Correct 249 ms 38056 KB Output is correct
8 Correct 279 ms 30668 KB Output is correct
9 Correct 1614 ms 54508 KB Output is correct
10 Correct 2909 ms 53968 KB Output is correct
11 Correct 1419 ms 47948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 13 ms 5372 KB Output is correct
18 Correct 12 ms 5332 KB Output is correct
19 Correct 23 ms 5340 KB Output is correct
20 Correct 17 ms 5372 KB Output is correct
21 Correct 22 ms 5332 KB Output is correct
22 Correct 25 ms 5444 KB Output is correct
23 Correct 22 ms 5412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 13 ms 5372 KB Output is correct
18 Correct 12 ms 5332 KB Output is correct
19 Correct 23 ms 5340 KB Output is correct
20 Correct 17 ms 5372 KB Output is correct
21 Correct 22 ms 5332 KB Output is correct
22 Correct 25 ms 5444 KB Output is correct
23 Correct 22 ms 5412 KB Output is correct
24 Correct 1869 ms 48048 KB Output is correct
25 Correct 1749 ms 57116 KB Output is correct
26 Correct 2893 ms 58788 KB Output is correct
27 Correct 2988 ms 57176 KB Output is correct
28 Correct 2679 ms 55092 KB Output is correct
29 Correct 1507 ms 51556 KB Output is correct
30 Correct 5670 ms 61812 KB Output is correct
31 Correct 352 ms 37692 KB Output is correct
32 Correct 246 ms 32048 KB Output is correct
33 Correct 3693 ms 60256 KB Output is correct
34 Correct 4477 ms 59560 KB Output is correct
35 Correct 5473 ms 55428 KB Output is correct
36 Correct 5873 ms 55244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 13 ms 5372 KB Output is correct
18 Correct 12 ms 5332 KB Output is correct
19 Correct 23 ms 5340 KB Output is correct
20 Correct 17 ms 5372 KB Output is correct
21 Correct 22 ms 5332 KB Output is correct
22 Correct 25 ms 5444 KB Output is correct
23 Correct 22 ms 5412 KB Output is correct
24 Correct 1869 ms 48048 KB Output is correct
25 Correct 1749 ms 57116 KB Output is correct
26 Correct 2893 ms 58788 KB Output is correct
27 Correct 2988 ms 57176 KB Output is correct
28 Correct 2679 ms 55092 KB Output is correct
29 Correct 1507 ms 51556 KB Output is correct
30 Correct 5670 ms 61812 KB Output is correct
31 Correct 352 ms 37692 KB Output is correct
32 Correct 246 ms 32048 KB Output is correct
33 Correct 3693 ms 60256 KB Output is correct
34 Correct 4477 ms 59560 KB Output is correct
35 Correct 5473 ms 55428 KB Output is correct
36 Correct 5873 ms 55244 KB Output is correct
37 Correct 3209 ms 61640 KB Output is correct
38 Correct 3110 ms 60132 KB Output is correct
39 Correct 3002 ms 57700 KB Output is correct
40 Correct 3098 ms 57548 KB Output is correct
41 Correct 3 ms 5032 KB Output is correct
42 Correct 5811 ms 64896 KB Output is correct
43 Correct 3799 ms 63028 KB Output is correct
44 Correct 4563 ms 62564 KB Output is correct
45 Correct 5553 ms 58548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 13 ms 5372 KB Output is correct
18 Correct 12 ms 5332 KB Output is correct
19 Correct 23 ms 5340 KB Output is correct
20 Correct 17 ms 5372 KB Output is correct
21 Correct 22 ms 5332 KB Output is correct
22 Correct 25 ms 5444 KB Output is correct
23 Correct 22 ms 5412 KB Output is correct
24 Correct 1869 ms 48048 KB Output is correct
25 Correct 1749 ms 57116 KB Output is correct
26 Correct 2893 ms 58788 KB Output is correct
27 Correct 2988 ms 57176 KB Output is correct
28 Correct 2679 ms 55092 KB Output is correct
29 Correct 1507 ms 51556 KB Output is correct
30 Correct 5670 ms 61812 KB Output is correct
31 Correct 352 ms 37692 KB Output is correct
32 Correct 246 ms 32048 KB Output is correct
33 Correct 3693 ms 60256 KB Output is correct
34 Correct 4477 ms 59560 KB Output is correct
35 Correct 5473 ms 55428 KB Output is correct
36 Correct 5873 ms 55244 KB Output is correct
37 Correct 3209 ms 61640 KB Output is correct
38 Correct 3110 ms 60132 KB Output is correct
39 Correct 3002 ms 57700 KB Output is correct
40 Correct 3098 ms 57548 KB Output is correct
41 Correct 3 ms 5032 KB Output is correct
42 Correct 5811 ms 64896 KB Output is correct
43 Correct 3799 ms 63028 KB Output is correct
44 Correct 4563 ms 62564 KB Output is correct
45 Correct 5553 ms 58548 KB Output is correct
46 Runtime error 2517 ms 136980 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3055 ms 50824 KB Output is correct
2 Correct 2927 ms 62892 KB Output is correct
3 Correct 1592 ms 53552 KB Output is correct
4 Correct 2472 ms 61384 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2698 ms 60508 KB Output is correct
7 Correct 249 ms 38056 KB Output is correct
8 Correct 279 ms 30668 KB Output is correct
9 Correct 1614 ms 54508 KB Output is correct
10 Correct 2909 ms 53968 KB Output is correct
11 Correct 1419 ms 47948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 13 ms 5372 KB Output is correct
29 Correct 12 ms 5332 KB Output is correct
30 Correct 23 ms 5340 KB Output is correct
31 Correct 17 ms 5372 KB Output is correct
32 Correct 22 ms 5332 KB Output is correct
33 Correct 25 ms 5444 KB Output is correct
34 Correct 22 ms 5412 KB Output is correct
35 Correct 1869 ms 48048 KB Output is correct
36 Correct 1749 ms 57116 KB Output is correct
37 Correct 2893 ms 58788 KB Output is correct
38 Correct 2988 ms 57176 KB Output is correct
39 Correct 2679 ms 55092 KB Output is correct
40 Correct 1507 ms 51556 KB Output is correct
41 Correct 5670 ms 61812 KB Output is correct
42 Correct 352 ms 37692 KB Output is correct
43 Correct 246 ms 32048 KB Output is correct
44 Correct 3693 ms 60256 KB Output is correct
45 Correct 4477 ms 59560 KB Output is correct
46 Correct 5473 ms 55428 KB Output is correct
47 Correct 5873 ms 55244 KB Output is correct
48 Correct 3209 ms 61640 KB Output is correct
49 Correct 3110 ms 60132 KB Output is correct
50 Correct 3002 ms 57700 KB Output is correct
51 Correct 3098 ms 57548 KB Output is correct
52 Correct 3 ms 5032 KB Output is correct
53 Correct 5811 ms 64896 KB Output is correct
54 Correct 3799 ms 63028 KB Output is correct
55 Correct 4563 ms 62564 KB Output is correct
56 Correct 5553 ms 58548 KB Output is correct
57 Correct 2989 ms 62276 KB Output is correct
58 Correct 3030 ms 60708 KB Output is correct
59 Correct 3274 ms 58480 KB Output is correct
60 Correct 3204 ms 58444 KB Output is correct
61 Correct 5473 ms 62068 KB Output is correct
62 Correct 3 ms 4948 KB Output is correct
63 Correct 6236 ms 64964 KB Output is correct
64 Correct 3732 ms 63336 KB Output is correct
65 Correct 4687 ms 62164 KB Output is correct
66 Correct 5522 ms 58504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3055 ms 50824 KB Output is correct
2 Correct 2927 ms 62892 KB Output is correct
3 Correct 1592 ms 53552 KB Output is correct
4 Correct 2472 ms 61384 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2698 ms 60508 KB Output is correct
7 Correct 249 ms 38056 KB Output is correct
8 Correct 279 ms 30668 KB Output is correct
9 Correct 1614 ms 54508 KB Output is correct
10 Correct 2909 ms 53968 KB Output is correct
11 Correct 1419 ms 47948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 13 ms 5372 KB Output is correct
29 Correct 12 ms 5332 KB Output is correct
30 Correct 23 ms 5340 KB Output is correct
31 Correct 17 ms 5372 KB Output is correct
32 Correct 22 ms 5332 KB Output is correct
33 Correct 25 ms 5444 KB Output is correct
34 Correct 22 ms 5412 KB Output is correct
35 Correct 1869 ms 48048 KB Output is correct
36 Correct 1749 ms 57116 KB Output is correct
37 Correct 2893 ms 58788 KB Output is correct
38 Correct 2988 ms 57176 KB Output is correct
39 Correct 2679 ms 55092 KB Output is correct
40 Correct 1507 ms 51556 KB Output is correct
41 Correct 5670 ms 61812 KB Output is correct
42 Correct 352 ms 37692 KB Output is correct
43 Correct 246 ms 32048 KB Output is correct
44 Correct 3693 ms 60256 KB Output is correct
45 Correct 4477 ms 59560 KB Output is correct
46 Correct 5473 ms 55428 KB Output is correct
47 Correct 5873 ms 55244 KB Output is correct
48 Correct 3209 ms 61640 KB Output is correct
49 Correct 3110 ms 60132 KB Output is correct
50 Correct 3002 ms 57700 KB Output is correct
51 Correct 3098 ms 57548 KB Output is correct
52 Correct 3 ms 5032 KB Output is correct
53 Correct 5811 ms 64896 KB Output is correct
54 Correct 3799 ms 63028 KB Output is correct
55 Correct 4563 ms 62564 KB Output is correct
56 Correct 5553 ms 58548 KB Output is correct
57 Runtime error 2517 ms 136980 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -