답안 #565507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565507 2022-05-21T02:46:51 Z dantoh000 Two Dishes (JOI19_dishes) C++14
100 / 100
6713 ms 521684 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
int n,m;
int a[1000005], s[1000005], p[1000005];
int b[1000005], t[1000005], q[1000005];
int pa[1000005], pb[1000005];
map<int, int> M[1000005];
struct node{
    int s,e,m,v;
    int la, lu, marked;
    node *l, *r;
    node (int _s, int _e){
        s = _s, e = _e, m = (s+e)/2;
        v = 0;
        la = lu = marked = 0;
        if (s != e){
            l = new node(s,m);
            r = new node(m+1,e);
        }
    }
    void prop(){
        if (marked){
            v = lu;
            if (s != e){
                l->lu = r->lu = lu;
                l->marked = r->marked = true;
                l->la = r->la = 0;
            }
            marked = lu = 0;
        }
        if (la){
            v += la;
            if (s != e){
                l->la += la;
                r->la += la;
            }
            la = 0;
        }

    }
    void SET(int qs, int qe, int nv){
        prop();
        if (qs == s && qe == e){
            marked = true;
            lu = nv;
            la = 0;
            return;
        }
        if (qs > m) r->SET(qs,qe,nv);
        else if (qe <= m) l->SET(qs,qe,nv);
        else{
            l->SET(qs,m,nv);
            r->SET(m+1,qe,nv);
        }
        l->prop();
        r->prop();
        v = max(l->v, r->v);
    }
    void ADD(int qs, int qe, int nv){
        prop();
        if (qs == s && qe == e){
            la += nv;
            return;
        }
        if (qs > m) r->ADD(qs,qe,nv);
        else if (qe <= m) l->ADD(qs,qe,nv);
        else{
            l->ADD(qs,m,nv);
            r->ADD(m+1,qe,nv);
        }
        l->prop();
        r->prop();
        v = max(l->v, r->v);
    }
    int qu(int x){
        prop();
        if (s == e) return v;
        if (x > m) return r->qu(x);
        else return l->qu(x);
    }
    int fin(int x){
        prop();
        //printf("finding first element > %d, cur %d %d\n",x,s,e);
        if (s == e) {
            if (v <= x) return e+1;
            else return e;
        }
        l->prop();
        r->prop();
        if (l->v > x) return l->fin(x);
        else return r->fin(x);
    }
} *root;


main(){
    scanf("%lld%lld",&n,&m);
    for (int i = 1; i <= n; i++){
        scanf("%lld%lld%lld",&a[i],&s[i],&p[i]);
        pa[i] = pa[i-1] + a[i];
    }
    for (int i = 1; i <= m; i++){
        scanf("%lld%lld%lld",&b[i],&t[i],&q[i]);
        pb[i] = pb[i-1] + b[i];
    }

    for (int i = 1; i <= n; i++){
        int Ta = upper_bound(pb, pb+m+1, s[i]-pa[i])-pb-1;
        //printf("A row %d needs col <= %d\n",i,Ta);
        if (Ta != -1) {
            M[i][0] += p[i];
            if (Ta+1 <= m) M[i][Ta+1] -= p[i];
            //printf("%d %d +%d\n",i,0,p[i]);
            //printf("%d %d -%d\n",i,Ta+1,p[i]);
        }

    }
    for (int i = 1; i <= m; i++){
        int Tb = upper_bound(pa, pa+n+1, t[i]-pb[i])-pa-1;
        //printf("B col %d needs row <= %d\n",i,Tb);
        if (Tb != -1) {
            M[Tb+1][i] += q[i];
            //printf("%d %d +%d\n",Tb+1,i,q[i]);
        }

    }
    root = new node(0, m);
    int ans = 0;
    for (int i = 0; i <= n+1; i++){
        //printf("at %d\n",i);
        for (auto it = M[i].begin(); it != M[i].end(); it++){
            int id, v;
            tie(id,v) = *it;
            //printf("updating %d %d %d\n",id,m,v);
            root->ADD(id, m, v);
        }

        /*for (int i = 0; i <= m; i++){
            printf("%d ",root->qu(i));
        }
        printf("\n");*/
        if (i != n+1){
            for (auto it = M[i].begin(); it != M[i].end(); it++){
                int id, v;
                tie(id,v) = *it;
                int mx = -INF;
                if (id) {
                    int val = root->qu(id-1);
                    if (val <= mx) continue;
                    int id2 = root->fin(val)-1;
                    //printf("id1 = %d, id2 = %d, setting to %d\n",id,id2,val);
                    if (id2 < id) continue;
                    root->SET(id, id2, val);
                    mx = val;
                }
            }

            /*
            for (int i = 0; i <= m; i++){
                printf("%d ",root->qu(i));
            }
            printf("\n");*/
        }

    }
    printf("%lld\n",root->qu(m));



}

Compilation message

dishes.cpp:98:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   98 | main(){
      | ^~~~
dishes.cpp: In function 'int main()':
dishes.cpp:130:9: warning: unused variable 'ans' [-Wunused-variable]
  130 |     int ans = 0;
      |         ^~~
dishes.cpp:99:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
dishes.cpp:101:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         scanf("%lld%lld%lld",&a[i],&s[i],&p[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:105:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         scanf("%lld%lld%lld",&b[i],&t[i],&q[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 117356 KB Output is correct
2 Correct 487 ms 119312 KB Output is correct
3 Correct 331 ms 116188 KB Output is correct
4 Correct 311 ms 106536 KB Output is correct
5 Correct 23 ms 47316 KB Output is correct
6 Correct 373 ms 115824 KB Output is correct
7 Correct 235 ms 96076 KB Output is correct
8 Correct 121 ms 66084 KB Output is correct
9 Correct 319 ms 116068 KB Output is correct
10 Correct 391 ms 116188 KB Output is correct
11 Correct 275 ms 116224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 47308 KB Output is correct
2 Correct 23 ms 47316 KB Output is correct
3 Correct 24 ms 47316 KB Output is correct
4 Correct 22 ms 47276 KB Output is correct
5 Correct 25 ms 47316 KB Output is correct
6 Correct 21 ms 47308 KB Output is correct
7 Correct 23 ms 47328 KB Output is correct
8 Correct 22 ms 47220 KB Output is correct
9 Correct 21 ms 47316 KB Output is correct
10 Correct 23 ms 47312 KB Output is correct
11 Correct 22 ms 47316 KB Output is correct
12 Correct 27 ms 47308 KB Output is correct
13 Correct 24 ms 47308 KB Output is correct
14 Correct 25 ms 47236 KB Output is correct
15 Correct 24 ms 47324 KB Output is correct
16 Correct 26 ms 47328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 47308 KB Output is correct
2 Correct 23 ms 47316 KB Output is correct
3 Correct 24 ms 47316 KB Output is correct
4 Correct 22 ms 47276 KB Output is correct
5 Correct 25 ms 47316 KB Output is correct
6 Correct 21 ms 47308 KB Output is correct
7 Correct 23 ms 47328 KB Output is correct
8 Correct 22 ms 47220 KB Output is correct
9 Correct 21 ms 47316 KB Output is correct
10 Correct 23 ms 47312 KB Output is correct
11 Correct 22 ms 47316 KB Output is correct
12 Correct 27 ms 47308 KB Output is correct
13 Correct 24 ms 47308 KB Output is correct
14 Correct 25 ms 47236 KB Output is correct
15 Correct 24 ms 47324 KB Output is correct
16 Correct 26 ms 47328 KB Output is correct
17 Correct 26 ms 48064 KB Output is correct
18 Correct 26 ms 47828 KB Output is correct
19 Correct 28 ms 48104 KB Output is correct
20 Correct 27 ms 47836 KB Output is correct
21 Correct 27 ms 48084 KB Output is correct
22 Correct 36 ms 48116 KB Output is correct
23 Correct 29 ms 48068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 47308 KB Output is correct
2 Correct 23 ms 47316 KB Output is correct
3 Correct 24 ms 47316 KB Output is correct
4 Correct 22 ms 47276 KB Output is correct
5 Correct 25 ms 47316 KB Output is correct
6 Correct 21 ms 47308 KB Output is correct
7 Correct 23 ms 47328 KB Output is correct
8 Correct 22 ms 47220 KB Output is correct
9 Correct 21 ms 47316 KB Output is correct
10 Correct 23 ms 47312 KB Output is correct
11 Correct 22 ms 47316 KB Output is correct
12 Correct 27 ms 47308 KB Output is correct
13 Correct 24 ms 47308 KB Output is correct
14 Correct 25 ms 47236 KB Output is correct
15 Correct 24 ms 47324 KB Output is correct
16 Correct 26 ms 47328 KB Output is correct
17 Correct 26 ms 48064 KB Output is correct
18 Correct 26 ms 47828 KB Output is correct
19 Correct 28 ms 48104 KB Output is correct
20 Correct 27 ms 47836 KB Output is correct
21 Correct 27 ms 48084 KB Output is correct
22 Correct 36 ms 48116 KB Output is correct
23 Correct 29 ms 48068 KB Output is correct
24 Correct 467 ms 122472 KB Output is correct
25 Correct 340 ms 109892 KB Output is correct
26 Correct 443 ms 122340 KB Output is correct
27 Correct 304 ms 109840 KB Output is correct
28 Correct 453 ms 116324 KB Output is correct
29 Correct 292 ms 116296 KB Output is correct
30 Correct 998 ms 127652 KB Output is correct
31 Correct 229 ms 97432 KB Output is correct
32 Correct 117 ms 72396 KB Output is correct
33 Correct 589 ms 109376 KB Output is correct
34 Correct 781 ms 123468 KB Output is correct
35 Correct 972 ms 128240 KB Output is correct
36 Correct 936 ms 127208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 47308 KB Output is correct
2 Correct 23 ms 47316 KB Output is correct
3 Correct 24 ms 47316 KB Output is correct
4 Correct 22 ms 47276 KB Output is correct
5 Correct 25 ms 47316 KB Output is correct
6 Correct 21 ms 47308 KB Output is correct
7 Correct 23 ms 47328 KB Output is correct
8 Correct 22 ms 47220 KB Output is correct
9 Correct 21 ms 47316 KB Output is correct
10 Correct 23 ms 47312 KB Output is correct
11 Correct 22 ms 47316 KB Output is correct
12 Correct 27 ms 47308 KB Output is correct
13 Correct 24 ms 47308 KB Output is correct
14 Correct 25 ms 47236 KB Output is correct
15 Correct 24 ms 47324 KB Output is correct
16 Correct 26 ms 47328 KB Output is correct
17 Correct 26 ms 48064 KB Output is correct
18 Correct 26 ms 47828 KB Output is correct
19 Correct 28 ms 48104 KB Output is correct
20 Correct 27 ms 47836 KB Output is correct
21 Correct 27 ms 48084 KB Output is correct
22 Correct 36 ms 48116 KB Output is correct
23 Correct 29 ms 48068 KB Output is correct
24 Correct 467 ms 122472 KB Output is correct
25 Correct 340 ms 109892 KB Output is correct
26 Correct 443 ms 122340 KB Output is correct
27 Correct 304 ms 109840 KB Output is correct
28 Correct 453 ms 116324 KB Output is correct
29 Correct 292 ms 116296 KB Output is correct
30 Correct 998 ms 127652 KB Output is correct
31 Correct 229 ms 97432 KB Output is correct
32 Correct 117 ms 72396 KB Output is correct
33 Correct 589 ms 109376 KB Output is correct
34 Correct 781 ms 123468 KB Output is correct
35 Correct 972 ms 128240 KB Output is correct
36 Correct 936 ms 127208 KB Output is correct
37 Correct 472 ms 122444 KB Output is correct
38 Correct 332 ms 109840 KB Output is correct
39 Correct 334 ms 116280 KB Output is correct
40 Correct 449 ms 116192 KB Output is correct
41 Correct 21 ms 47232 KB Output is correct
42 Correct 1010 ms 127792 KB Output is correct
43 Correct 602 ms 109332 KB Output is correct
44 Correct 801 ms 122912 KB Output is correct
45 Correct 1008 ms 128216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 47308 KB Output is correct
2 Correct 23 ms 47316 KB Output is correct
3 Correct 24 ms 47316 KB Output is correct
4 Correct 22 ms 47276 KB Output is correct
5 Correct 25 ms 47316 KB Output is correct
6 Correct 21 ms 47308 KB Output is correct
7 Correct 23 ms 47328 KB Output is correct
8 Correct 22 ms 47220 KB Output is correct
9 Correct 21 ms 47316 KB Output is correct
10 Correct 23 ms 47312 KB Output is correct
11 Correct 22 ms 47316 KB Output is correct
12 Correct 27 ms 47308 KB Output is correct
13 Correct 24 ms 47308 KB Output is correct
14 Correct 25 ms 47236 KB Output is correct
15 Correct 24 ms 47324 KB Output is correct
16 Correct 26 ms 47328 KB Output is correct
17 Correct 26 ms 48064 KB Output is correct
18 Correct 26 ms 47828 KB Output is correct
19 Correct 28 ms 48104 KB Output is correct
20 Correct 27 ms 47836 KB Output is correct
21 Correct 27 ms 48084 KB Output is correct
22 Correct 36 ms 48116 KB Output is correct
23 Correct 29 ms 48068 KB Output is correct
24 Correct 467 ms 122472 KB Output is correct
25 Correct 340 ms 109892 KB Output is correct
26 Correct 443 ms 122340 KB Output is correct
27 Correct 304 ms 109840 KB Output is correct
28 Correct 453 ms 116324 KB Output is correct
29 Correct 292 ms 116296 KB Output is correct
30 Correct 998 ms 127652 KB Output is correct
31 Correct 229 ms 97432 KB Output is correct
32 Correct 117 ms 72396 KB Output is correct
33 Correct 589 ms 109376 KB Output is correct
34 Correct 781 ms 123468 KB Output is correct
35 Correct 972 ms 128240 KB Output is correct
36 Correct 936 ms 127208 KB Output is correct
37 Correct 472 ms 122444 KB Output is correct
38 Correct 332 ms 109840 KB Output is correct
39 Correct 334 ms 116280 KB Output is correct
40 Correct 449 ms 116192 KB Output is correct
41 Correct 21 ms 47232 KB Output is correct
42 Correct 1010 ms 127792 KB Output is correct
43 Correct 602 ms 109332 KB Output is correct
44 Correct 801 ms 122912 KB Output is correct
45 Correct 1008 ms 128216 KB Output is correct
46 Correct 2498 ms 423192 KB Output is correct
47 Correct 1633 ms 360664 KB Output is correct
48 Correct 1639 ms 391728 KB Output is correct
49 Correct 2276 ms 391788 KB Output is correct
50 Correct 6713 ms 452120 KB Output is correct
51 Correct 3596 ms 354332 KB Output is correct
52 Correct 4404 ms 402516 KB Output is correct
53 Correct 6189 ms 447264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 117356 KB Output is correct
2 Correct 487 ms 119312 KB Output is correct
3 Correct 331 ms 116188 KB Output is correct
4 Correct 311 ms 106536 KB Output is correct
5 Correct 23 ms 47316 KB Output is correct
6 Correct 373 ms 115824 KB Output is correct
7 Correct 235 ms 96076 KB Output is correct
8 Correct 121 ms 66084 KB Output is correct
9 Correct 319 ms 116068 KB Output is correct
10 Correct 391 ms 116188 KB Output is correct
11 Correct 275 ms 116224 KB Output is correct
12 Correct 26 ms 47308 KB Output is correct
13 Correct 23 ms 47316 KB Output is correct
14 Correct 24 ms 47316 KB Output is correct
15 Correct 22 ms 47276 KB Output is correct
16 Correct 25 ms 47316 KB Output is correct
17 Correct 21 ms 47308 KB Output is correct
18 Correct 23 ms 47328 KB Output is correct
19 Correct 22 ms 47220 KB Output is correct
20 Correct 21 ms 47316 KB Output is correct
21 Correct 23 ms 47312 KB Output is correct
22 Correct 22 ms 47316 KB Output is correct
23 Correct 27 ms 47308 KB Output is correct
24 Correct 24 ms 47308 KB Output is correct
25 Correct 25 ms 47236 KB Output is correct
26 Correct 24 ms 47324 KB Output is correct
27 Correct 26 ms 47328 KB Output is correct
28 Correct 26 ms 48064 KB Output is correct
29 Correct 26 ms 47828 KB Output is correct
30 Correct 28 ms 48104 KB Output is correct
31 Correct 27 ms 47836 KB Output is correct
32 Correct 27 ms 48084 KB Output is correct
33 Correct 36 ms 48116 KB Output is correct
34 Correct 29 ms 48068 KB Output is correct
35 Correct 467 ms 122472 KB Output is correct
36 Correct 340 ms 109892 KB Output is correct
37 Correct 443 ms 122340 KB Output is correct
38 Correct 304 ms 109840 KB Output is correct
39 Correct 453 ms 116324 KB Output is correct
40 Correct 292 ms 116296 KB Output is correct
41 Correct 998 ms 127652 KB Output is correct
42 Correct 229 ms 97432 KB Output is correct
43 Correct 117 ms 72396 KB Output is correct
44 Correct 589 ms 109376 KB Output is correct
45 Correct 781 ms 123468 KB Output is correct
46 Correct 972 ms 128240 KB Output is correct
47 Correct 936 ms 127208 KB Output is correct
48 Correct 472 ms 122444 KB Output is correct
49 Correct 332 ms 109840 KB Output is correct
50 Correct 334 ms 116280 KB Output is correct
51 Correct 449 ms 116192 KB Output is correct
52 Correct 21 ms 47232 KB Output is correct
53 Correct 1010 ms 127792 KB Output is correct
54 Correct 602 ms 109332 KB Output is correct
55 Correct 801 ms 122912 KB Output is correct
56 Correct 1008 ms 128216 KB Output is correct
57 Correct 394 ms 122804 KB Output is correct
58 Correct 419 ms 124100 KB Output is correct
59 Correct 464 ms 128356 KB Output is correct
60 Correct 346 ms 128168 KB Output is correct
61 Correct 982 ms 139572 KB Output is correct
62 Correct 24 ms 47316 KB Output is correct
63 Correct 1022 ms 141792 KB Output is correct
64 Correct 588 ms 121500 KB Output is correct
65 Correct 830 ms 138804 KB Output is correct
66 Correct 958 ms 134840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 117356 KB Output is correct
2 Correct 487 ms 119312 KB Output is correct
3 Correct 331 ms 116188 KB Output is correct
4 Correct 311 ms 106536 KB Output is correct
5 Correct 23 ms 47316 KB Output is correct
6 Correct 373 ms 115824 KB Output is correct
7 Correct 235 ms 96076 KB Output is correct
8 Correct 121 ms 66084 KB Output is correct
9 Correct 319 ms 116068 KB Output is correct
10 Correct 391 ms 116188 KB Output is correct
11 Correct 275 ms 116224 KB Output is correct
12 Correct 26 ms 47308 KB Output is correct
13 Correct 23 ms 47316 KB Output is correct
14 Correct 24 ms 47316 KB Output is correct
15 Correct 22 ms 47276 KB Output is correct
16 Correct 25 ms 47316 KB Output is correct
17 Correct 21 ms 47308 KB Output is correct
18 Correct 23 ms 47328 KB Output is correct
19 Correct 22 ms 47220 KB Output is correct
20 Correct 21 ms 47316 KB Output is correct
21 Correct 23 ms 47312 KB Output is correct
22 Correct 22 ms 47316 KB Output is correct
23 Correct 27 ms 47308 KB Output is correct
24 Correct 24 ms 47308 KB Output is correct
25 Correct 25 ms 47236 KB Output is correct
26 Correct 24 ms 47324 KB Output is correct
27 Correct 26 ms 47328 KB Output is correct
28 Correct 26 ms 48064 KB Output is correct
29 Correct 26 ms 47828 KB Output is correct
30 Correct 28 ms 48104 KB Output is correct
31 Correct 27 ms 47836 KB Output is correct
32 Correct 27 ms 48084 KB Output is correct
33 Correct 36 ms 48116 KB Output is correct
34 Correct 29 ms 48068 KB Output is correct
35 Correct 467 ms 122472 KB Output is correct
36 Correct 340 ms 109892 KB Output is correct
37 Correct 443 ms 122340 KB Output is correct
38 Correct 304 ms 109840 KB Output is correct
39 Correct 453 ms 116324 KB Output is correct
40 Correct 292 ms 116296 KB Output is correct
41 Correct 998 ms 127652 KB Output is correct
42 Correct 229 ms 97432 KB Output is correct
43 Correct 117 ms 72396 KB Output is correct
44 Correct 589 ms 109376 KB Output is correct
45 Correct 781 ms 123468 KB Output is correct
46 Correct 972 ms 128240 KB Output is correct
47 Correct 936 ms 127208 KB Output is correct
48 Correct 472 ms 122444 KB Output is correct
49 Correct 332 ms 109840 KB Output is correct
50 Correct 334 ms 116280 KB Output is correct
51 Correct 449 ms 116192 KB Output is correct
52 Correct 21 ms 47232 KB Output is correct
53 Correct 1010 ms 127792 KB Output is correct
54 Correct 602 ms 109332 KB Output is correct
55 Correct 801 ms 122912 KB Output is correct
56 Correct 1008 ms 128216 KB Output is correct
57 Correct 2498 ms 423192 KB Output is correct
58 Correct 1633 ms 360664 KB Output is correct
59 Correct 1639 ms 391728 KB Output is correct
60 Correct 2276 ms 391788 KB Output is correct
61 Correct 6713 ms 452120 KB Output is correct
62 Correct 3596 ms 354332 KB Output is correct
63 Correct 4404 ms 402516 KB Output is correct
64 Correct 6189 ms 447264 KB Output is correct
65 Correct 394 ms 122804 KB Output is correct
66 Correct 419 ms 124100 KB Output is correct
67 Correct 464 ms 128356 KB Output is correct
68 Correct 346 ms 128168 KB Output is correct
69 Correct 982 ms 139572 KB Output is correct
70 Correct 24 ms 47316 KB Output is correct
71 Correct 1022 ms 141792 KB Output is correct
72 Correct 588 ms 121500 KB Output is correct
73 Correct 830 ms 138804 KB Output is correct
74 Correct 958 ms 134840 KB Output is correct
75 Correct 2005 ms 494604 KB Output is correct
76 Correct 2135 ms 432064 KB Output is correct
77 Correct 2371 ms 450444 KB Output is correct
78 Correct 1694 ms 450396 KB Output is correct
79 Correct 6532 ms 521684 KB Output is correct
80 Correct 3544 ms 411584 KB Output is correct
81 Correct 4807 ms 490564 KB Output is correct
82 Correct 6462 ms 487084 KB Output is correct
83 Correct 6166 ms 499864 KB Output is correct