Submission #1003134

# Submission time Handle Problem Language Result Execution time Memory
1003134 2024-06-20T06:33:20 Z 79brue Food Court (JOI21_foodcourt) C++17
0 / 100
1000 ms 31572 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll INF = 1e18;

struct segTree1{
    ll treeMax[1<<19], treeMin[1<<19], lazyA[1<<19], lazyB[1<<19];

    void init(int i, int l, int r){
        treeMax[i] = treeMin[i] = 0;
        lazyA[i] = 1, lazyB[i] = 0;
        if(l==r) return;
        int m = (l+r)>>1;
        init(i*2, l, m);
        init(i*2+1, m+1, r);
    }

    void propagate(int i, int l, int r){
        treeMax[i] = treeMax[i] * lazyA[i] + lazyB[i];
        treeMin[i] = treeMin[i] * lazyA[i] + lazyB[i];
        if(l!=r){
            lazyB[i*2] = lazyB[i*2] * lazyA[i] + lazyB[i], lazyA[i*2] *= lazyA[i];
            lazyB[i*2+1] = lazyB[i*2+1] * lazyA[i] + lazyB[i], lazyA[i*2+1] *= lazyA[i];
        }
        lazyA[i] = 1, lazyB[i] = 0;
    }

    void update(int i, int l, int r, int s, int e, ll v){
        propagate(i, l, r);
        if(r<s || e<l) return;
        if(s<=l && r<=e){
            if(v>=0 || treeMin[i]+v >= 0){
                lazyB[i] += v;
                propagate(i, l, r);
                return;
            }
            if(treeMax[i]+v <= 0){
                lazyA[i] = 0, lazyB[i] = 0;
                propagate(i, l, r);
                return;
            }
        }
        int m = (l+r)>>1;
        update(i*2, l, m, s, e, v);
        update(i*2+1, m+1, r, s, e, v);
        treeMax[i] = max(treeMax[i*2], treeMax[i*2+1]);
        treeMin[i] = min(treeMin[i*2], treeMin[i*2+1]);
    }

    ll query(int i, int l, int r, int x){
        propagate(i, l, r);
        if(l==r) return treeMax[i];
        int m = (l+r)>>1;
        if(x<=m) return query(i*2, l, m, x);
        else return query(i*2+1, m+1, r, x);
    }
} tree1;

struct segTree2{
    int n;
    ll tree[250002];

    void init(int _n){
        n = _n;
        for(int i=1; i<=n; i++) tree[i] = 0;
    }

    void add(int x, ll v){
        while(x<=n){
            tree[x] += v;
            x += x&-x;
        }
    }

    ll sum(int x){
        ll ret = 0;
        while(x){
            ret += tree[x];
            x -= x&-x;
        }
        return ret;
    }
} tree2;

struct dat{
    int x, idx; ll v;
    dat(){}
    dat(int x, int idx, ll v): x(x), idx(idx), v(v){}
    bool operator<(const dat &r)const{
        return x<r.x;
    }
};

vector<int> Record;
struct segTree3{
    ll tree[1<<19], lazy[1<<19];

    void init(int i, int l, int r, dat *arr){
        if(l==r){
            tree[i] = arr[l].v;
            return;
        }
        int m = (l+r)>>1;
        init(i*2, l, m, arr);
        init(i*2+1, m+1, r, arr);
        tree[i] = min(tree[i*2], tree[i*2+1]);
    }

    void propagate(int i, int l, int r){
        tree[i] += lazy[i];
        if(l!=r) lazy[i*2] += lazy[i], lazy[i*2+1] += lazy[i];
        lazy[i] = 0;
    }

    void search_range(int i, int l, int r){
        propagate(i, l, r);
        if(tree[i] > 0) return;
        if(l==r){
            Record.push_back(l);
            tree[i] = INF;
            return;
        }
        int m = (l+r)>>1;
        search_range(i*2, l, m);
        search_range(i*2+1, m+1, r);
        tree[i] = min(tree[i*2], tree[i*2+1]);
    }

    void update(int i, int l, int r, int s, int e, ll v){
        propagate(i, l, r);
        if(r<s || e<l) return;
        if(s<=l && r<=e){
            lazy[i] -= v;
            search_range(i, l, r);
            return;
        }
        int m = (l+r)>>1;
        update(i*2, l, m, s, e, v);
        update(i*2+1, m+1, r, s, e, v);
        tree[i] = min(tree[i*2], tree[i*2+1]);
    }
} tree3;

int n, m, q;
int qt[250002], ql[250002], qr[250002], qx[250002];
ll qk[250002], qb[250002];
int ans[250002];

int s;
dat queries[250002];
int qli[250002];

int main(){
    scanf("%d %d %d", &n, &m, &q);
    for(int i=1; i<=q; i++){
        scanf("%d", &qt[i]);
        if(qt[i] == 1) scanf("%d %d %d %lld", &ql[i], &qr[i], &qx[i], &qk[i]);
        else if(qt[i] == 2) scanf("%d %d %lld", &ql[i], &qr[i], &qk[i]);
        else scanf("%d %lld", &qx[i], &qk[i]);
    }

    tree1.init(1, 1, n);
    tree2.init(n);
    for(int i=1; i<=q; i++){
        if(qt[i] == 1){
            tree1.update(1, 1, n, ql[i], qr[i], qk[i]);
            tree2.add(ql[i], qk[i]);
            tree2.add(qr[i]+1, -qk[i]);
        }
        else if(qt[i] == 2){
            tree1.update(1, 1, n, ql[i], qr[i], -qk[i]);
        }
        else{
            ll a = tree2.sum(qx[i]), b = tree1.query(1, 1, n, qx[i]);
            if(b < qk[i]) continue;
            ans[i] = 1;
        }
    }

    for(int i=1; i<=q; i++) if(qt[i] == 3) printf("%d\n", ans[i]);
}

Compilation message

foodcourt.cpp: In function 'int main()':
foodcourt.cpp:176:16: warning: unused variable 'a' [-Wunused-variable]
  176 |             ll a = tree2.sum(qx[i]), b = tree1.query(1, 1, n, qx[i]);
      |                ^
foodcourt.cpp:156:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  156 |     scanf("%d %d %d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:158:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  158 |         scanf("%d", &qt[i]);
      |         ~~~~~^~~~~~~~~~~~~~
foodcourt.cpp:159:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  159 |         if(qt[i] == 1) scanf("%d %d %d %lld", &ql[i], &qr[i], &qx[i], &qk[i]);
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:160:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  160 |         else if(qt[i] == 2) scanf("%d %d %lld", &ql[i], &qr[i], &qk[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:161:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  161 |         else scanf("%d %lld", &qx[i], &qk[i]);
      |              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 220 ms 30376 KB Output is correct
2 Correct 201 ms 27472 KB Output is correct
3 Correct 222 ms 31312 KB Output is correct
4 Correct 156 ms 27992 KB Output is correct
5 Correct 166 ms 27776 KB Output is correct
6 Correct 211 ms 31572 KB Output is correct
7 Correct 61 ms 11368 KB Output is correct
8 Correct 62 ms 11092 KB Output is correct
9 Correct 217 ms 31432 KB Output is correct
10 Correct 180 ms 31388 KB Output is correct
11 Correct 222 ms 31332 KB Output is correct
12 Correct 229 ms 31332 KB Output is correct
13 Correct 219 ms 31316 KB Output is correct
14 Correct 222 ms 31320 KB Output is correct
15 Correct 246 ms 31400 KB Output is correct
16 Correct 254 ms 31312 KB Output is correct
17 Correct 241 ms 31312 KB Output is correct
18 Correct 262 ms 31316 KB Output is correct
19 Correct 247 ms 31164 KB Output is correct
20 Correct 229 ms 31356 KB Output is correct
21 Correct 257 ms 31312 KB Output is correct
22 Correct 260 ms 31216 KB Output is correct
23 Correct 246 ms 31404 KB Output is correct
24 Correct 247 ms 31376 KB Output is correct
25 Correct 199 ms 30592 KB Output is correct
26 Correct 226 ms 31060 KB Output is correct
27 Execution timed out 1037 ms 30032 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 8100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -