답안 #246909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246909 2020-07-10T14:00:15 Z sealnot123 Two Dishes (JOI19_dishes) C++14
82 / 100
10000 ms 190948 KB
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

const LL inf = 1e18;
const int N = 1000005;
LL n;
LL seg[N<<2], lazy[N<<2], label[N<<2];
LL fastMax(LL x, LL y) { return (((y-x)>>(63))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
void push_add(int l, int r, int nw){
    seg[nw] += lazy[nw];
    if(l != r){
        lazy[nw<<1] += lazy[nw], lazy[nw<<1|1] += lazy[nw];
    }
    lazy[nw] = 0;
}
void push_label(int l, int r, int nw){
    seg[nw] = label[nw];
    if(l != r){
        lazy[nw<<1] = lazy[nw<<1|1] = 0;
        label[nw<<1] = label[nw<<1|1] = label[nw];
    }
    label[nw] = inf;
}
void paste(int ll, int rr, LL v, int l = 0, int r = n, int nw = 1){
    if(label[nw] != inf) push_label(l, r, nw);
    if(lazy[nw] != 0) push_add(l, r, nw);
    if(ll > rr || l > rr || r < ll) return ;
    if(l >= ll && r <= rr){
        label[nw] = v;
        push_label(l, r, nw); 
        return ;
    }
    int m = (l+r)>>1;
    paste(ll, rr, v, l, m, nw<<1);
    paste(ll, rr, v, m+1, r, nw<<1|1);
    seg[nw] = fastMax(seg[nw<<1], seg[nw<<1|1]);
}
void add(int ll, int rr, LL v, int l = 0, int r = n, int nw = 1){
    if(label[nw] != inf) push_label(l, r, nw);
    if(lazy[nw] != 0) push_add(l, r, nw);
    if(l > r || ll > rr || l > rr || r < ll) return ;
    if(l >= ll && r <= rr){
        lazy[nw] = v;
        push_add(l, r, nw);
        return ;
    }
    int m = (l+r)>>1;
    add(ll, rr, v, l, m, nw<<1);
    add(ll, rr, v, m+1, r, nw<<1|1);
    seg[nw] = fastMax(seg[nw<<1], seg[nw<<1|1]);
}
int search(int ll, int rr, LL v, int l = 0, int r = n, int nw = 1){
    if(label[nw] != inf) push_label(l, r, nw);
    if(lazy[nw] != 0) push_add(l, r, nw);
    if(l > rr || r < ll) return rr+1;
    if(l == r){
        if(seg[nw] >= v) return l;
        return rr+1;
    }
    int m = (l+r)>>1;
    if(l >= ll && r <= rr){
        if(label[nw<<1] != inf) push_label(l, m, nw<<1);
        if(lazy[nw<<1] != 0) push_add(l, m, nw<<1);
        if(seg[nw<<1] >= v) return search(ll, rr, v, l, m, nw<<1);
        return search(ll, rr, v, m+1, r, nw<<1|1);
    }
    return fastMin( search(ll, rr, v, l, m, nw<<1), search(ll, rr, v, m+1, r, nw<<1|1));
}
LL get(int idx, int l = 0, int r = n, int nw = 1){
    if(label[nw] != inf) push_label(l, r, nw);
    if(lazy[nw] != 0) push_add(l, r, nw);
    if(l == r) return seg[nw];
    int m = (l+r)>>1;
    if(idx <= m) return get(idx, l, m, nw<<1);
    return get(idx, m+1, r, nw<<1|1);
}

LL A[N], B[N];
LL S[N], T[N];
LL P[N], Q[N];
vector< PLL > sweep[N];
LL m;
void fastscan(LL &x)
{
    bool neg=false;
    register LL c;
    c=getchar();
    if(c=='-')
    {
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
} 
void evaluate(PLL a, PLL b){
    int now = a.x;
    LL upd = a.y;
    int nxt = b.x;
    add(now+1, n, upd);
    // printf("##"); seg.print(); puts("");
    if(now == nxt) return ;
    LL value = get(now);
    int stop_point = search(now+1, nxt, value)-1;
    //printf("j %d (%d, %d) %lld stop = %d\n",j,now,nxt,value,stop_point);
    if(stop_point > now) paste(now+1, stop_point, value);
}
int main(){
    fastscan(n); fastscan(m);
    FOR(i, 1, n) fastscan(A[i]), fastscan(S[i]), fastscan(P[i]), A[i] += A[i-1];
    FOR(i, 1, m) fastscan(B[i]), fastscan(T[i]), fastscan(Q[i]), B[i] += B[i-1];
    FOR(i, 1, (n+1)<<2) label[i] = inf;
    LL ans = 0;
    FOR(i, 1, n){
        int pA = upper_bound(B, B+1+m, S[i]-A[i]) - B - 1;
        if(pA == -1) continue;
        if(pA == n){
            ans += P[i]; continue;
        }
        sweep[pA+1].pb(PLL(i-1, P[i]));
    }
    //seg.print(); puts("");
    FOR(i, 1, m){
        int pB = upper_bound(A, A+1+n, T[i]-B[i]) - A - 1;
        int ch = 0;
        if(pB != -1) add(0, pB, Q[i]), ch = 1;
        //printf("#"); seg.print(); puts("");
        sweep[i].pb( PLL(n, 0) );
        //printf("sweep: "); for(PLL e : sweep[i]) printf("(%lld, %lld) ",e.x,e.y);
        //puts("");
        if(ch && sweep[i][0].x > pB){
            evaluate(PLL(pB, 0), sweep[i][0]);
            ch = 0;
        }
        FOR(j, 0, SZ(sweep[i])-2){
            if(ch && sweep[i][j].x < pB && pB < sweep[i][j+1].x){
                evaluate(sweep[i][j], PLL(pB, 0));
                evaluate(PLL(pB, 0), sweep[i][j+1]);
                ch = 0;
            }else{
                evaluate(sweep[i][j], sweep[i][j+1]);
            }
        }
        sweep[i].clear();
        //seg.print(); puts("");
    }
    //puts("");
    for(PLL e : sweep[m+1]) add(e.x+1, n, e.y);
    printf("%lld",ans+get(n));
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 634 ms 63724 KB Output is correct
2 Correct 528 ms 64108 KB Output is correct
3 Correct 225 ms 52472 KB Output is correct
4 Correct 469 ms 59640 KB Output is correct
5 Correct 18 ms 23808 KB Output is correct
6 Correct 503 ms 63464 KB Output is correct
7 Correct 123 ms 39280 KB Output is correct
8 Correct 174 ms 50780 KB Output is correct
9 Correct 235 ms 52472 KB Output is correct
10 Correct 481 ms 61816 KB Output is correct
11 Correct 152 ms 50296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 18 ms 23936 KB Output is correct
4 Correct 19 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 19 ms 23808 KB Output is correct
8 Correct 19 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 18 ms 23808 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 19 ms 23936 KB Output is correct
14 Correct 19 ms 24064 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 18 ms 23936 KB Output is correct
4 Correct 19 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 19 ms 23808 KB Output is correct
8 Correct 19 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 18 ms 23808 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 19 ms 23936 KB Output is correct
14 Correct 19 ms 24064 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 21 ms 24320 KB Output is correct
18 Correct 22 ms 24192 KB Output is correct
19 Correct 25 ms 24320 KB Output is correct
20 Correct 22 ms 24192 KB Output is correct
21 Correct 23 ms 24320 KB Output is correct
22 Correct 24 ms 24192 KB Output is correct
23 Correct 24 ms 24192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 18 ms 23936 KB Output is correct
4 Correct 19 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 19 ms 23808 KB Output is correct
8 Correct 19 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 18 ms 23808 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 19 ms 23936 KB Output is correct
14 Correct 19 ms 24064 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 21 ms 24320 KB Output is correct
18 Correct 22 ms 24192 KB Output is correct
19 Correct 25 ms 24320 KB Output is correct
20 Correct 22 ms 24192 KB Output is correct
21 Correct 23 ms 24320 KB Output is correct
22 Correct 24 ms 24192 KB Output is correct
23 Correct 24 ms 24192 KB Output is correct
24 Correct 302 ms 63196 KB Output is correct
25 Correct 604 ms 61668 KB Output is correct
26 Correct 413 ms 63352 KB Output is correct
27 Correct 548 ms 60212 KB Output is correct
28 Correct 520 ms 61304 KB Output is correct
29 Correct 195 ms 52672 KB Output is correct
30 Correct 1594 ms 63992 KB Output is correct
31 Correct 113 ms 39672 KB Output is correct
32 Correct 190 ms 50984 KB Output is correct
33 Correct 808 ms 61944 KB Output is correct
34 Correct 1094 ms 64364 KB Output is correct
35 Correct 1584 ms 62204 KB Output is correct
36 Correct 1455 ms 61920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 18 ms 23936 KB Output is correct
4 Correct 19 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 19 ms 23808 KB Output is correct
8 Correct 19 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 18 ms 23808 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 19 ms 23936 KB Output is correct
14 Correct 19 ms 24064 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 21 ms 24320 KB Output is correct
18 Correct 22 ms 24192 KB Output is correct
19 Correct 25 ms 24320 KB Output is correct
20 Correct 22 ms 24192 KB Output is correct
21 Correct 23 ms 24320 KB Output is correct
22 Correct 24 ms 24192 KB Output is correct
23 Correct 24 ms 24192 KB Output is correct
24 Correct 302 ms 63196 KB Output is correct
25 Correct 604 ms 61668 KB Output is correct
26 Correct 413 ms 63352 KB Output is correct
27 Correct 548 ms 60212 KB Output is correct
28 Correct 520 ms 61304 KB Output is correct
29 Correct 195 ms 52672 KB Output is correct
30 Correct 1594 ms 63992 KB Output is correct
31 Correct 113 ms 39672 KB Output is correct
32 Correct 190 ms 50984 KB Output is correct
33 Correct 808 ms 61944 KB Output is correct
34 Correct 1094 ms 64364 KB Output is correct
35 Correct 1584 ms 62204 KB Output is correct
36 Correct 1455 ms 61920 KB Output is correct
37 Correct 472 ms 64664 KB Output is correct
38 Correct 667 ms 61688 KB Output is correct
39 Correct 606 ms 64760 KB Output is correct
40 Correct 463 ms 64608 KB Output is correct
41 Correct 19 ms 23808 KB Output is correct
42 Correct 1487 ms 65656 KB Output is correct
43 Correct 859 ms 63736 KB Output is correct
44 Correct 1111 ms 66208 KB Output is correct
45 Correct 1442 ms 63492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 18 ms 23936 KB Output is correct
4 Correct 19 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 19 ms 23808 KB Output is correct
8 Correct 19 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 18 ms 23808 KB Output is correct
11 Correct 18 ms 23808 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 19 ms 23936 KB Output is correct
14 Correct 19 ms 24064 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 21 ms 24320 KB Output is correct
18 Correct 22 ms 24192 KB Output is correct
19 Correct 25 ms 24320 KB Output is correct
20 Correct 22 ms 24192 KB Output is correct
21 Correct 23 ms 24320 KB Output is correct
22 Correct 24 ms 24192 KB Output is correct
23 Correct 24 ms 24192 KB Output is correct
24 Correct 302 ms 63196 KB Output is correct
25 Correct 604 ms 61668 KB Output is correct
26 Correct 413 ms 63352 KB Output is correct
27 Correct 548 ms 60212 KB Output is correct
28 Correct 520 ms 61304 KB Output is correct
29 Correct 195 ms 52672 KB Output is correct
30 Correct 1594 ms 63992 KB Output is correct
31 Correct 113 ms 39672 KB Output is correct
32 Correct 190 ms 50984 KB Output is correct
33 Correct 808 ms 61944 KB Output is correct
34 Correct 1094 ms 64364 KB Output is correct
35 Correct 1584 ms 62204 KB Output is correct
36 Correct 1455 ms 61920 KB Output is correct
37 Correct 472 ms 64664 KB Output is correct
38 Correct 667 ms 61688 KB Output is correct
39 Correct 606 ms 64760 KB Output is correct
40 Correct 463 ms 64608 KB Output is correct
41 Correct 19 ms 23808 KB Output is correct
42 Correct 1487 ms 65656 KB Output is correct
43 Correct 859 ms 63736 KB Output is correct
44 Correct 1111 ms 66208 KB Output is correct
45 Correct 1442 ms 63492 KB Output is correct
46 Correct 2418 ms 183444 KB Output is correct
47 Correct 2966 ms 167928 KB Output is correct
48 Correct 3432 ms 190948 KB Output is correct
49 Correct 2538 ms 190584 KB Output is correct
50 Execution timed out 10051 ms 183200 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 634 ms 63724 KB Output is correct
2 Correct 528 ms 64108 KB Output is correct
3 Correct 225 ms 52472 KB Output is correct
4 Correct 469 ms 59640 KB Output is correct
5 Correct 18 ms 23808 KB Output is correct
6 Correct 503 ms 63464 KB Output is correct
7 Correct 123 ms 39280 KB Output is correct
8 Correct 174 ms 50780 KB Output is correct
9 Correct 235 ms 52472 KB Output is correct
10 Correct 481 ms 61816 KB Output is correct
11 Correct 152 ms 50296 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 18 ms 23808 KB Output is correct
14 Correct 18 ms 23936 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 19 ms 23808 KB Output is correct
18 Correct 19 ms 23808 KB Output is correct
19 Correct 19 ms 23936 KB Output is correct
20 Correct 18 ms 23808 KB Output is correct
21 Correct 18 ms 23808 KB Output is correct
22 Correct 18 ms 23808 KB Output is correct
23 Correct 18 ms 23808 KB Output is correct
24 Correct 19 ms 23936 KB Output is correct
25 Correct 19 ms 24064 KB Output is correct
26 Correct 19 ms 23808 KB Output is correct
27 Correct 19 ms 23808 KB Output is correct
28 Correct 21 ms 24320 KB Output is correct
29 Correct 22 ms 24192 KB Output is correct
30 Correct 25 ms 24320 KB Output is correct
31 Correct 22 ms 24192 KB Output is correct
32 Correct 23 ms 24320 KB Output is correct
33 Correct 24 ms 24192 KB Output is correct
34 Correct 24 ms 24192 KB Output is correct
35 Correct 302 ms 63196 KB Output is correct
36 Correct 604 ms 61668 KB Output is correct
37 Correct 413 ms 63352 KB Output is correct
38 Correct 548 ms 60212 KB Output is correct
39 Correct 520 ms 61304 KB Output is correct
40 Correct 195 ms 52672 KB Output is correct
41 Correct 1594 ms 63992 KB Output is correct
42 Correct 113 ms 39672 KB Output is correct
43 Correct 190 ms 50984 KB Output is correct
44 Correct 808 ms 61944 KB Output is correct
45 Correct 1094 ms 64364 KB Output is correct
46 Correct 1584 ms 62204 KB Output is correct
47 Correct 1455 ms 61920 KB Output is correct
48 Correct 472 ms 64664 KB Output is correct
49 Correct 667 ms 61688 KB Output is correct
50 Correct 606 ms 64760 KB Output is correct
51 Correct 463 ms 64608 KB Output is correct
52 Correct 19 ms 23808 KB Output is correct
53 Correct 1487 ms 65656 KB Output is correct
54 Correct 859 ms 63736 KB Output is correct
55 Correct 1111 ms 66208 KB Output is correct
56 Correct 1442 ms 63492 KB Output is correct
57 Correct 554 ms 65576 KB Output is correct
58 Correct 483 ms 62584 KB Output is correct
59 Correct 485 ms 65144 KB Output is correct
60 Correct 612 ms 65124 KB Output is correct
61 Correct 1371 ms 64684 KB Output is correct
62 Correct 19 ms 23808 KB Output is correct
63 Correct 1507 ms 66168 KB Output is correct
64 Correct 993 ms 64036 KB Output is correct
65 Correct 1124 ms 65956 KB Output is correct
66 Correct 1468 ms 63352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 634 ms 63724 KB Output is correct
2 Correct 528 ms 64108 KB Output is correct
3 Correct 225 ms 52472 KB Output is correct
4 Correct 469 ms 59640 KB Output is correct
5 Correct 18 ms 23808 KB Output is correct
6 Correct 503 ms 63464 KB Output is correct
7 Correct 123 ms 39280 KB Output is correct
8 Correct 174 ms 50780 KB Output is correct
9 Correct 235 ms 52472 KB Output is correct
10 Correct 481 ms 61816 KB Output is correct
11 Correct 152 ms 50296 KB Output is correct
12 Correct 18 ms 23808 KB Output is correct
13 Correct 18 ms 23808 KB Output is correct
14 Correct 18 ms 23936 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 19 ms 23808 KB Output is correct
18 Correct 19 ms 23808 KB Output is correct
19 Correct 19 ms 23936 KB Output is correct
20 Correct 18 ms 23808 KB Output is correct
21 Correct 18 ms 23808 KB Output is correct
22 Correct 18 ms 23808 KB Output is correct
23 Correct 18 ms 23808 KB Output is correct
24 Correct 19 ms 23936 KB Output is correct
25 Correct 19 ms 24064 KB Output is correct
26 Correct 19 ms 23808 KB Output is correct
27 Correct 19 ms 23808 KB Output is correct
28 Correct 21 ms 24320 KB Output is correct
29 Correct 22 ms 24192 KB Output is correct
30 Correct 25 ms 24320 KB Output is correct
31 Correct 22 ms 24192 KB Output is correct
32 Correct 23 ms 24320 KB Output is correct
33 Correct 24 ms 24192 KB Output is correct
34 Correct 24 ms 24192 KB Output is correct
35 Correct 302 ms 63196 KB Output is correct
36 Correct 604 ms 61668 KB Output is correct
37 Correct 413 ms 63352 KB Output is correct
38 Correct 548 ms 60212 KB Output is correct
39 Correct 520 ms 61304 KB Output is correct
40 Correct 195 ms 52672 KB Output is correct
41 Correct 1594 ms 63992 KB Output is correct
42 Correct 113 ms 39672 KB Output is correct
43 Correct 190 ms 50984 KB Output is correct
44 Correct 808 ms 61944 KB Output is correct
45 Correct 1094 ms 64364 KB Output is correct
46 Correct 1584 ms 62204 KB Output is correct
47 Correct 1455 ms 61920 KB Output is correct
48 Correct 472 ms 64664 KB Output is correct
49 Correct 667 ms 61688 KB Output is correct
50 Correct 606 ms 64760 KB Output is correct
51 Correct 463 ms 64608 KB Output is correct
52 Correct 19 ms 23808 KB Output is correct
53 Correct 1487 ms 65656 KB Output is correct
54 Correct 859 ms 63736 KB Output is correct
55 Correct 1111 ms 66208 KB Output is correct
56 Correct 1442 ms 63492 KB Output is correct
57 Correct 2418 ms 183444 KB Output is correct
58 Correct 2966 ms 167928 KB Output is correct
59 Correct 3432 ms 190948 KB Output is correct
60 Correct 2538 ms 190584 KB Output is correct
61 Execution timed out 10051 ms 183200 KB Time limit exceeded
62 Halted 0 ms 0 KB -