답안 #565484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565484 2022-05-21T00:51:40 Z dantoh000 Two Dishes (JOI19_dishes) C++14
65 / 100
1082 ms 103908 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
int n,m;
int a[200005], s[200005], p[200005];
int b[200005], t[200005], q[200005];
int pa[200005], pb[200005];
map<int, int> M[200005];
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 = 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();
        if (s != e){
            l->prop();
            r->prop();
            v = max(l->v, r->v);
        }
        //printf("finding first element > %d, cur %d %d\n",x,s,e);
        if (s == e) {
            if (v <= x) return e+1;
            else return e;
        }
        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].rbegin(); it != M[i].rend(); 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");*/
        for (auto it = M[i].begin(); it != M[i].end(); it++){
            int id, v;

            tie(id,v) = *it;
            if (id) {
                int val = root->qu(id-1);
                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);
            }
        }

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

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



}

Compilation message

dishes.cpp:101:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  101 | main(){
      | ^~~~
dishes.cpp: In function 'int main()':
dishes.cpp:133:9: warning: unused variable 'ans' [-Wunused-variable]
  133 |     int ans = 0;
      |         ^~~
dishes.cpp:102:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
dishes.cpp:104:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         scanf("%lld%lld%lld",&a[i],&s[i],&p[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:108:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         scanf("%lld%lld%lld",&b[i],&t[i],&q[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 80036 KB Output is correct
2 Correct 441 ms 82064 KB Output is correct
3 Correct 359 ms 80860 KB Output is correct
4 Correct 293 ms 71320 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 380 ms 80528 KB Output is correct
7 Correct 250 ms 60860 KB Output is correct
8 Correct 103 ms 30688 KB Output is correct
9 Correct 362 ms 81040 KB Output is correct
10 Correct 352 ms 80856 KB Output is correct
11 Correct 317 ms 80904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9704 KB Output is correct
4 Correct 5 ms 9704 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9724 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9760 KB Output is correct
16 Correct 6 ms 9728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9704 KB Output is correct
4 Correct 5 ms 9704 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9724 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9760 KB Output is correct
16 Correct 6 ms 9728 KB Output is correct
17 Correct 11 ms 10580 KB Output is correct
18 Correct 8 ms 10428 KB Output is correct
19 Correct 14 ms 10580 KB Output is correct
20 Correct 10 ms 10360 KB Output is correct
21 Correct 10 ms 10580 KB Output is correct
22 Correct 12 ms 10580 KB Output is correct
23 Correct 12 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9704 KB Output is correct
4 Correct 5 ms 9704 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9724 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9760 KB Output is correct
16 Correct 6 ms 9728 KB Output is correct
17 Correct 11 ms 10580 KB Output is correct
18 Correct 8 ms 10428 KB Output is correct
19 Correct 14 ms 10580 KB Output is correct
20 Correct 10 ms 10360 KB Output is correct
21 Correct 10 ms 10580 KB Output is correct
22 Correct 12 ms 10580 KB Output is correct
23 Correct 12 ms 10588 KB Output is correct
24 Correct 493 ms 95476 KB Output is correct
25 Correct 331 ms 82864 KB Output is correct
26 Correct 457 ms 95532 KB Output is correct
27 Correct 306 ms 83024 KB Output is correct
28 Correct 476 ms 89380 KB Output is correct
29 Correct 340 ms 89876 KB Output is correct
30 Correct 1026 ms 100816 KB Output is correct
31 Correct 243 ms 65080 KB Output is correct
32 Correct 101 ms 39916 KB Output is correct
33 Correct 574 ms 82288 KB Output is correct
34 Correct 860 ms 96552 KB Output is correct
35 Correct 991 ms 94868 KB Output is correct
36 Correct 974 ms 93968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9704 KB Output is correct
4 Correct 5 ms 9704 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9724 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9760 KB Output is correct
16 Correct 6 ms 9728 KB Output is correct
17 Correct 11 ms 10580 KB Output is correct
18 Correct 8 ms 10428 KB Output is correct
19 Correct 14 ms 10580 KB Output is correct
20 Correct 10 ms 10360 KB Output is correct
21 Correct 10 ms 10580 KB Output is correct
22 Correct 12 ms 10580 KB Output is correct
23 Correct 12 ms 10588 KB Output is correct
24 Correct 493 ms 95476 KB Output is correct
25 Correct 331 ms 82864 KB Output is correct
26 Correct 457 ms 95532 KB Output is correct
27 Correct 306 ms 83024 KB Output is correct
28 Correct 476 ms 89380 KB Output is correct
29 Correct 340 ms 89876 KB Output is correct
30 Correct 1026 ms 100816 KB Output is correct
31 Correct 243 ms 65080 KB Output is correct
32 Correct 101 ms 39916 KB Output is correct
33 Correct 574 ms 82288 KB Output is correct
34 Correct 860 ms 96552 KB Output is correct
35 Correct 991 ms 94868 KB Output is correct
36 Correct 974 ms 93968 KB Output is correct
37 Correct 493 ms 98536 KB Output is correct
38 Correct 325 ms 86056 KB Output is correct
39 Correct 327 ms 89628 KB Output is correct
40 Correct 455 ms 89720 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 1049 ms 103908 KB Output is correct
43 Correct 626 ms 85280 KB Output is correct
44 Correct 845 ms 98948 KB Output is correct
45 Correct 1082 ms 98004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9704 KB Output is correct
4 Correct 5 ms 9704 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9724 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9704 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9760 KB Output is correct
16 Correct 6 ms 9728 KB Output is correct
17 Correct 11 ms 10580 KB Output is correct
18 Correct 8 ms 10428 KB Output is correct
19 Correct 14 ms 10580 KB Output is correct
20 Correct 10 ms 10360 KB Output is correct
21 Correct 10 ms 10580 KB Output is correct
22 Correct 12 ms 10580 KB Output is correct
23 Correct 12 ms 10588 KB Output is correct
24 Correct 493 ms 95476 KB Output is correct
25 Correct 331 ms 82864 KB Output is correct
26 Correct 457 ms 95532 KB Output is correct
27 Correct 306 ms 83024 KB Output is correct
28 Correct 476 ms 89380 KB Output is correct
29 Correct 340 ms 89876 KB Output is correct
30 Correct 1026 ms 100816 KB Output is correct
31 Correct 243 ms 65080 KB Output is correct
32 Correct 101 ms 39916 KB Output is correct
33 Correct 574 ms 82288 KB Output is correct
34 Correct 860 ms 96552 KB Output is correct
35 Correct 991 ms 94868 KB Output is correct
36 Correct 974 ms 93968 KB Output is correct
37 Correct 493 ms 98536 KB Output is correct
38 Correct 325 ms 86056 KB Output is correct
39 Correct 327 ms 89628 KB Output is correct
40 Correct 455 ms 89720 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 1049 ms 103908 KB Output is correct
43 Correct 626 ms 85280 KB Output is correct
44 Correct 845 ms 98948 KB Output is correct
45 Correct 1082 ms 98004 KB Output is correct
46 Runtime error 96 ms 38092 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 80036 KB Output is correct
2 Correct 441 ms 82064 KB Output is correct
3 Correct 359 ms 80860 KB Output is correct
4 Correct 293 ms 71320 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 380 ms 80528 KB Output is correct
7 Correct 250 ms 60860 KB Output is correct
8 Correct 103 ms 30688 KB Output is correct
9 Correct 362 ms 81040 KB Output is correct
10 Correct 352 ms 80856 KB Output is correct
11 Correct 317 ms 80904 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9704 KB Output is correct
15 Correct 5 ms 9704 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9724 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 5 ms 9704 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9684 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 5 ms 9760 KB Output is correct
27 Correct 6 ms 9728 KB Output is correct
28 Correct 11 ms 10580 KB Output is correct
29 Correct 8 ms 10428 KB Output is correct
30 Correct 14 ms 10580 KB Output is correct
31 Correct 10 ms 10360 KB Output is correct
32 Correct 10 ms 10580 KB Output is correct
33 Correct 12 ms 10580 KB Output is correct
34 Correct 12 ms 10588 KB Output is correct
35 Correct 493 ms 95476 KB Output is correct
36 Correct 331 ms 82864 KB Output is correct
37 Correct 457 ms 95532 KB Output is correct
38 Correct 306 ms 83024 KB Output is correct
39 Correct 476 ms 89380 KB Output is correct
40 Correct 340 ms 89876 KB Output is correct
41 Correct 1026 ms 100816 KB Output is correct
42 Correct 243 ms 65080 KB Output is correct
43 Correct 101 ms 39916 KB Output is correct
44 Correct 574 ms 82288 KB Output is correct
45 Correct 860 ms 96552 KB Output is correct
46 Correct 991 ms 94868 KB Output is correct
47 Correct 974 ms 93968 KB Output is correct
48 Correct 493 ms 98536 KB Output is correct
49 Correct 325 ms 86056 KB Output is correct
50 Correct 327 ms 89628 KB Output is correct
51 Correct 455 ms 89720 KB Output is correct
52 Correct 5 ms 9684 KB Output is correct
53 Correct 1049 ms 103908 KB Output is correct
54 Correct 626 ms 85280 KB Output is correct
55 Correct 845 ms 98948 KB Output is correct
56 Correct 1082 ms 98004 KB Output is correct
57 Incorrect 446 ms 98964 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 80036 KB Output is correct
2 Correct 441 ms 82064 KB Output is correct
3 Correct 359 ms 80860 KB Output is correct
4 Correct 293 ms 71320 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 380 ms 80528 KB Output is correct
7 Correct 250 ms 60860 KB Output is correct
8 Correct 103 ms 30688 KB Output is correct
9 Correct 362 ms 81040 KB Output is correct
10 Correct 352 ms 80856 KB Output is correct
11 Correct 317 ms 80904 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9704 KB Output is correct
15 Correct 5 ms 9704 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9724 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 5 ms 9704 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9684 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 5 ms 9760 KB Output is correct
27 Correct 6 ms 9728 KB Output is correct
28 Correct 11 ms 10580 KB Output is correct
29 Correct 8 ms 10428 KB Output is correct
30 Correct 14 ms 10580 KB Output is correct
31 Correct 10 ms 10360 KB Output is correct
32 Correct 10 ms 10580 KB Output is correct
33 Correct 12 ms 10580 KB Output is correct
34 Correct 12 ms 10588 KB Output is correct
35 Correct 493 ms 95476 KB Output is correct
36 Correct 331 ms 82864 KB Output is correct
37 Correct 457 ms 95532 KB Output is correct
38 Correct 306 ms 83024 KB Output is correct
39 Correct 476 ms 89380 KB Output is correct
40 Correct 340 ms 89876 KB Output is correct
41 Correct 1026 ms 100816 KB Output is correct
42 Correct 243 ms 65080 KB Output is correct
43 Correct 101 ms 39916 KB Output is correct
44 Correct 574 ms 82288 KB Output is correct
45 Correct 860 ms 96552 KB Output is correct
46 Correct 991 ms 94868 KB Output is correct
47 Correct 974 ms 93968 KB Output is correct
48 Correct 493 ms 98536 KB Output is correct
49 Correct 325 ms 86056 KB Output is correct
50 Correct 327 ms 89628 KB Output is correct
51 Correct 455 ms 89720 KB Output is correct
52 Correct 5 ms 9684 KB Output is correct
53 Correct 1049 ms 103908 KB Output is correct
54 Correct 626 ms 85280 KB Output is correct
55 Correct 845 ms 98948 KB Output is correct
56 Correct 1082 ms 98004 KB Output is correct
57 Runtime error 96 ms 38092 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -