답안 #475314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475314 2021-09-21T20:28:04 Z nafis_shifat 푸드 코트 (JOI21_foodcourt) C++14
7 / 100
1000 ms 39368 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define f first
#define s second
using namespace std;
const int mxn=3e5+5;
const int inf=1e9;

int n,m,q;


struct segtree {
    
    ll removed[4 * mxn] = {};
    ll added[4 * mxn] = {};
    pii tree[4 * mxn];

    void init(int n) {
        for(int i = 0; i < 4 * mxn; i++) tree[i] = {0,0};
    }

    pii merge(pii a, pii b) {
        return { b.f + max(0ll, a.f - b.s), a.s + max(0ll,b.s - a.f) };
    }


    void propogate(int node) {
        int left = node << 1;
        int right = left | 1;

        removed[left] += min(tree[node].f,tree[left].s);
        removed[right] += min(tree[node].f,tree[right].s);

        tree[left] = merge(tree[node], tree[left]);
        tree[right] = merge(tree[node], tree[right]);

        removed[left] += removed[node];
        removed[right] += removed[node];
        removed[node] = 0;

        

        added[left] += added[node];
        added[right] += added[node];
        added[node] = 0;

        tree[node] = {0,0};
    }

    void update(int node,int b,int e,int l,int r, pii v) {
        if(e < l || b > r) return;
        if(b >= l && e <= r) {

            removed[node] += min(v.first, tree[node].s);
            added[node] += v.s;
            tree[node] = merge(v, tree[node]);
            // cout<<"After update ("<<b<<" "<<e<<") ("<<v.f<<" - "<<v.s<<") ("<<tree[node].f<<" "<<tree[node].s<<") "<<removed[node]<<endl;
            return;
        }
        propogate(node);

        int mid = b + e >>1;
        int left = node << 1;
        int right = left | 1;

        update(left, b, mid, l, r, v);
        update(right, mid + 1, e, l, r, v);
    }

    int query(int node,int b,int e,int p) {
        if(b == e) return node;

        int mid = b + e >> 1;
        int left = node << 1;
        int right = left | 1;

        propogate(node);

        if(p <= mid) return query(left,b,mid,p);
        return query(right, mid + 1,e,p);
    }
} st;

int type[mxn],l[mxn],r[mxn],c[mxn];
ll k[mxn];

ll a[mxn],b[mxn];
int res[mxn];

ll pos[mxn];
int main() {
    memset(res,-1,sizeof res);
    cin >> n >> m >> q;
    st.init(n);


    for(int i = 1; i <= q; i++) {
        scanf("%d",&type[i]);

        if(type[i] == 1) {
            scanf("%d%d%d %lld",&l[i],&r[i],&c[i],&k[i]);
            st.update(1,1,n,l[i],r[i],{0,k[i]});
        } else if(type[i] == 2) {
            scanf("%d%d %lld",&l[i],&r[i],&k[i]);
            st.update(1,1,n,l[i],r[i],{k[i],0});

        } else {
            scanf("%lld %lld",&a[i],&b[i]);

            int node = st.query(1,1,n,a[i]);
            if(st.tree[node].s >= b[i]) {
                pos[i] = st.removed[node] + b[i];
            }
            else res[i] = 0;
        }
    }


    for(int i = 1; i <= q; i++) {
        if(type[i] != 3) continue;

        if(res[i] == 0) {
            printf("0\n");
            continue;
        }
        ll sum = 0;

        for(int j = 1; j < i; j++) {
            if(type[j] == 1 && l[j] <= a[i] && a[i] <= r[j]) {
                sum += k[j];

                if(sum >= pos[i]) {
                    printf("%d\n",c[j]);
                    break;
                }
            }
        }
    }


}

Compilation message

foodcourt.cpp: In member function 'void segtree::update(int, int, int, int, int, std::pair<long long int, long long int>)':
foodcourt.cpp:63:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   63 |         int mid = b + e >>1;
      |                   ~~^~~
foodcourt.cpp: In member function 'int segtree::query(int, int, int, int)':
foodcourt.cpp:74:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |         int mid = b + e >> 1;
      |                   ~~^~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         scanf("%d",&type[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
foodcourt.cpp:102:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |             scanf("%d%d%d %lld",&l[i],&r[i],&c[i],&k[i]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:105:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |             scanf("%d%d %lld",&l[i],&r[i],&k[i]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:109:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |             scanf("%lld %lld",&a[i],&b[i]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 20428 KB Output is correct
2 Correct 13 ms 20468 KB Output is correct
3 Correct 11 ms 20428 KB Output is correct
4 Correct 14 ms 20420 KB Output is correct
5 Correct 12 ms 20300 KB Output is correct
6 Correct 12 ms 20392 KB Output is correct
7 Correct 14 ms 20428 KB Output is correct
8 Correct 12 ms 20448 KB Output is correct
9 Correct 13 ms 20428 KB Output is correct
10 Correct 13 ms 20428 KB Output is correct
11 Correct 12 ms 20484 KB Output is correct
12 Correct 12 ms 20428 KB Output is correct
13 Correct 11 ms 20408 KB Output is correct
14 Correct 11 ms 20428 KB Output is correct
15 Correct 11 ms 20556 KB Output is correct
16 Correct 12 ms 20428 KB Output is correct
17 Correct 12 ms 20412 KB Output is correct
18 Correct 13 ms 20428 KB Output is correct
19 Correct 14 ms 20428 KB Output is correct
20 Correct 12 ms 20428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 20428 KB Output is correct
2 Correct 13 ms 20468 KB Output is correct
3 Correct 11 ms 20428 KB Output is correct
4 Correct 14 ms 20420 KB Output is correct
5 Correct 12 ms 20300 KB Output is correct
6 Correct 12 ms 20392 KB Output is correct
7 Correct 14 ms 20428 KB Output is correct
8 Correct 12 ms 20448 KB Output is correct
9 Correct 13 ms 20428 KB Output is correct
10 Correct 13 ms 20428 KB Output is correct
11 Correct 12 ms 20484 KB Output is correct
12 Correct 12 ms 20428 KB Output is correct
13 Correct 11 ms 20408 KB Output is correct
14 Correct 11 ms 20428 KB Output is correct
15 Correct 11 ms 20556 KB Output is correct
16 Correct 12 ms 20428 KB Output is correct
17 Correct 12 ms 20412 KB Output is correct
18 Correct 13 ms 20428 KB Output is correct
19 Correct 14 ms 20428 KB Output is correct
20 Correct 12 ms 20428 KB Output is correct
21 Correct 13 ms 20428 KB Output is correct
22 Correct 13 ms 20528 KB Output is correct
23 Correct 12 ms 20428 KB Output is correct
24 Correct 14 ms 20428 KB Output is correct
25 Correct 11 ms 20408 KB Output is correct
26 Correct 11 ms 20300 KB Output is correct
27 Correct 13 ms 20428 KB Output is correct
28 Correct 13 ms 20432 KB Output is correct
29 Correct 15 ms 20500 KB Output is correct
30 Correct 13 ms 20524 KB Output is correct
31 Correct 13 ms 20440 KB Output is correct
32 Correct 13 ms 20436 KB Output is correct
33 Correct 11 ms 20368 KB Output is correct
34 Correct 12 ms 20428 KB Output is correct
35 Correct 12 ms 20428 KB Output is correct
36 Correct 14 ms 20476 KB Output is correct
37 Correct 11 ms 20416 KB Output is correct
38 Correct 11 ms 20432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 24936 KB Output is correct
2 Correct 96 ms 26180 KB Output is correct
3 Correct 98 ms 26280 KB Output is correct
4 Correct 85 ms 26132 KB Output is correct
5 Correct 89 ms 26272 KB Output is correct
6 Correct 87 ms 26176 KB Output is correct
7 Correct 874 ms 24040 KB Output is correct
8 Execution timed out 1085 ms 24112 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 39368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 20428 KB Output is correct
2 Correct 13 ms 20468 KB Output is correct
3 Correct 11 ms 20428 KB Output is correct
4 Correct 14 ms 20420 KB Output is correct
5 Correct 12 ms 20300 KB Output is correct
6 Correct 12 ms 20392 KB Output is correct
7 Correct 14 ms 20428 KB Output is correct
8 Correct 12 ms 20448 KB Output is correct
9 Correct 13 ms 20428 KB Output is correct
10 Correct 13 ms 20428 KB Output is correct
11 Correct 12 ms 20484 KB Output is correct
12 Correct 12 ms 20428 KB Output is correct
13 Correct 11 ms 20408 KB Output is correct
14 Correct 11 ms 20428 KB Output is correct
15 Correct 11 ms 20556 KB Output is correct
16 Correct 12 ms 20428 KB Output is correct
17 Correct 12 ms 20412 KB Output is correct
18 Correct 13 ms 20428 KB Output is correct
19 Correct 14 ms 20428 KB Output is correct
20 Correct 12 ms 20428 KB Output is correct
21 Correct 82 ms 24936 KB Output is correct
22 Correct 96 ms 26180 KB Output is correct
23 Correct 98 ms 26280 KB Output is correct
24 Correct 85 ms 26132 KB Output is correct
25 Correct 89 ms 26272 KB Output is correct
26 Correct 87 ms 26176 KB Output is correct
27 Correct 874 ms 24040 KB Output is correct
28 Execution timed out 1085 ms 24112 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 25356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 20428 KB Output is correct
2 Correct 13 ms 20468 KB Output is correct
3 Correct 11 ms 20428 KB Output is correct
4 Correct 14 ms 20420 KB Output is correct
5 Correct 12 ms 20300 KB Output is correct
6 Correct 12 ms 20392 KB Output is correct
7 Correct 14 ms 20428 KB Output is correct
8 Correct 12 ms 20448 KB Output is correct
9 Correct 13 ms 20428 KB Output is correct
10 Correct 13 ms 20428 KB Output is correct
11 Correct 12 ms 20484 KB Output is correct
12 Correct 12 ms 20428 KB Output is correct
13 Correct 11 ms 20408 KB Output is correct
14 Correct 11 ms 20428 KB Output is correct
15 Correct 11 ms 20556 KB Output is correct
16 Correct 12 ms 20428 KB Output is correct
17 Correct 12 ms 20412 KB Output is correct
18 Correct 13 ms 20428 KB Output is correct
19 Correct 14 ms 20428 KB Output is correct
20 Correct 12 ms 20428 KB Output is correct
21 Correct 13 ms 20428 KB Output is correct
22 Correct 13 ms 20528 KB Output is correct
23 Correct 12 ms 20428 KB Output is correct
24 Correct 14 ms 20428 KB Output is correct
25 Correct 11 ms 20408 KB Output is correct
26 Correct 11 ms 20300 KB Output is correct
27 Correct 13 ms 20428 KB Output is correct
28 Correct 13 ms 20432 KB Output is correct
29 Correct 15 ms 20500 KB Output is correct
30 Correct 13 ms 20524 KB Output is correct
31 Correct 13 ms 20440 KB Output is correct
32 Correct 13 ms 20436 KB Output is correct
33 Correct 11 ms 20368 KB Output is correct
34 Correct 12 ms 20428 KB Output is correct
35 Correct 12 ms 20428 KB Output is correct
36 Correct 14 ms 20476 KB Output is correct
37 Correct 11 ms 20416 KB Output is correct
38 Correct 11 ms 20432 KB Output is correct
39 Correct 82 ms 24936 KB Output is correct
40 Correct 96 ms 26180 KB Output is correct
41 Correct 98 ms 26280 KB Output is correct
42 Correct 85 ms 26132 KB Output is correct
43 Correct 89 ms 26272 KB Output is correct
44 Correct 87 ms 26176 KB Output is correct
45 Correct 874 ms 24040 KB Output is correct
46 Execution timed out 1085 ms 24112 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 20428 KB Output is correct
2 Correct 13 ms 20468 KB Output is correct
3 Correct 11 ms 20428 KB Output is correct
4 Correct 14 ms 20420 KB Output is correct
5 Correct 12 ms 20300 KB Output is correct
6 Correct 12 ms 20392 KB Output is correct
7 Correct 14 ms 20428 KB Output is correct
8 Correct 12 ms 20448 KB Output is correct
9 Correct 13 ms 20428 KB Output is correct
10 Correct 13 ms 20428 KB Output is correct
11 Correct 12 ms 20484 KB Output is correct
12 Correct 12 ms 20428 KB Output is correct
13 Correct 11 ms 20408 KB Output is correct
14 Correct 11 ms 20428 KB Output is correct
15 Correct 11 ms 20556 KB Output is correct
16 Correct 12 ms 20428 KB Output is correct
17 Correct 12 ms 20412 KB Output is correct
18 Correct 13 ms 20428 KB Output is correct
19 Correct 14 ms 20428 KB Output is correct
20 Correct 12 ms 20428 KB Output is correct
21 Correct 13 ms 20428 KB Output is correct
22 Correct 13 ms 20528 KB Output is correct
23 Correct 12 ms 20428 KB Output is correct
24 Correct 14 ms 20428 KB Output is correct
25 Correct 11 ms 20408 KB Output is correct
26 Correct 11 ms 20300 KB Output is correct
27 Correct 13 ms 20428 KB Output is correct
28 Correct 13 ms 20432 KB Output is correct
29 Correct 15 ms 20500 KB Output is correct
30 Correct 13 ms 20524 KB Output is correct
31 Correct 13 ms 20440 KB Output is correct
32 Correct 13 ms 20436 KB Output is correct
33 Correct 11 ms 20368 KB Output is correct
34 Correct 12 ms 20428 KB Output is correct
35 Correct 12 ms 20428 KB Output is correct
36 Correct 14 ms 20476 KB Output is correct
37 Correct 11 ms 20416 KB Output is correct
38 Correct 11 ms 20432 KB Output is correct
39 Correct 82 ms 24936 KB Output is correct
40 Correct 96 ms 26180 KB Output is correct
41 Correct 98 ms 26280 KB Output is correct
42 Correct 85 ms 26132 KB Output is correct
43 Correct 89 ms 26272 KB Output is correct
44 Correct 87 ms 26176 KB Output is correct
45 Correct 874 ms 24040 KB Output is correct
46 Execution timed out 1085 ms 24112 KB Time limit exceeded
47 Halted 0 ms 0 KB -