답안 #475303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475303 2021-09-21T19:20:55 Z nafis_shifat 푸드 코트 (JOI21_foodcourt) C++14
21 / 100
350 ms 25456 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];
    
    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;

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

        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) {
            tree[node] = merge(v, tree[node]);
            // cout<<"After update"<<b<<" "<<e<<" "<<v.f<<" - "<<v.s<<" "<<tree[node].f<<" "<<tree[node].s<<endl;
            return;
        }
        if(tree[node].f != 0 || tree[node].s != 0) 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);
    }

    ll query(int node,int b,int e,int p) {
        if(b == e) return tree[node].s;

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

        if(tree[node].f != 0 || tree[node].s != 0) propogate(node);

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

int main() {
    cin >> n >> m >> q;
    st.init(n);


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

        if(tp == 1) {
            int l,r,c;
            ll k;
            scanf("%d%d%d %lld",&l,&r,&c,&k);

            st.update(1,1,n,l,r,{0,k});
        } else if(tp == 2) {
            int l,r;
            ll k;
            scanf("%d%d %lld",&l,&r,&k);
            st.update(1,1,n,l,r,{k,0});
        } else {
            ll a,b;
            scanf("%lld %lld",&a,&b);

            if(st.query(1,1,n,a) >= b) printf("1\n");
            else printf("0\n");
        }

    }


}

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:47:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |         int mid = b + e >>1;
      |                   ~~^~~
foodcourt.cpp: In member function 'long long int segtree::query(int, int, int, int)':
foodcourt.cpp:58:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |         int mid = b + e >> 1;
      |                   ~~^~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         scanf("%d",&tp);
      |         ~~~~~^~~~~~~~~~
foodcourt.cpp:81:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |             scanf("%d%d%d %lld",&l,&r,&c,&k);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:87:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |             scanf("%d%d %lld",&l,&r,&k);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:91:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |             scanf("%lld %lld",&a,&b);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 19020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 19020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 19080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 278 ms 19100 KB Output is correct
2 Correct 217 ms 23388 KB Output is correct
3 Correct 286 ms 25108 KB Output is correct
4 Correct 217 ms 23612 KB Output is correct
5 Correct 215 ms 23680 KB Output is correct
6 Correct 299 ms 25284 KB Output is correct
7 Correct 123 ms 23316 KB Output is correct
8 Correct 138 ms 23236 KB Output is correct
9 Correct 266 ms 25340 KB Output is correct
10 Correct 276 ms 25360 KB Output is correct
11 Correct 317 ms 25336 KB Output is correct
12 Correct 350 ms 25220 KB Output is correct
13 Correct 335 ms 25284 KB Output is correct
14 Correct 293 ms 25284 KB Output is correct
15 Correct 310 ms 25280 KB Output is correct
16 Correct 317 ms 25184 KB Output is correct
17 Correct 336 ms 25412 KB Output is correct
18 Correct 314 ms 25220 KB Output is correct
19 Correct 336 ms 25156 KB Output is correct
20 Correct 286 ms 25220 KB Output is correct
21 Correct 289 ms 25456 KB Output is correct
22 Correct 326 ms 25208 KB Output is correct
23 Correct 309 ms 25212 KB Output is correct
24 Correct 314 ms 25304 KB Output is correct
25 Correct 229 ms 24728 KB Output is correct
26 Correct 240 ms 24900 KB Output is correct
27 Correct 231 ms 24960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 19020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 61 ms 19092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 19020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 19020 KB Output isn't correct
2 Halted 0 ms 0 KB -