Submission #1003355

# Submission time Handle Problem Language Result Execution time Memory
1003355 2024-06-20T09:08:45 Z 79brue Food Court (JOI21_foodcourt) C++17
68 / 100
348 ms 29440 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;
    }
};

int records[250002]; int rcnt;
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){
            records[++rcnt] = 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){
            if(n<=65000) 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){
            if(n<=65000) 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;
            queries[++s] = dat(qx[i], i, a - b + qk[i]);
        }
    }

    if(s){
        sort(queries+1, queries+s+1);
        queries[s+1].x = INT_MAX;
        for(int i=1; i<=n+1; i++){
            qli[i] = qli[i-1];
            while(queries[qli[i]].x < i) qli[i]++;
        }
        tree3.init(1, 1, s, queries);

        for(int i=1; i<=q; i++){
            if(qt[i] != 1) continue;
            tree3.update(1, 1, s, qli[ql[i]], qli[qr[i]+1]-1, qk[i]);
            for(int p=1; p<=rcnt; p++){
                ans[queries[records[p]].idx] = qx[i];
            }
            rcnt = 0;
        }
    }

    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: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 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 780 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 780 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 804 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 784 KB Output is correct
28 Correct 2 ms 712 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 8100 KB Output is correct
2 Correct 44 ms 8020 KB Output is correct
3 Correct 48 ms 8020 KB Output is correct
4 Correct 44 ms 8016 KB Output is correct
5 Correct 45 ms 8272 KB Output is correct
6 Correct 43 ms 8016 KB Output is correct
7 Correct 14 ms 3188 KB Output is correct
8 Correct 16 ms 3168 KB Output is correct
9 Correct 48 ms 8272 KB Output is correct
10 Correct 47 ms 8028 KB Output is correct
11 Correct 50 ms 8152 KB Output is correct
12 Correct 42 ms 8020 KB Output is correct
13 Correct 42 ms 8084 KB Output is correct
14 Correct 45 ms 8448 KB Output is correct
15 Correct 44 ms 8020 KB Output is correct
16 Correct 43 ms 8484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 29440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 780 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 45 ms 8100 KB Output is correct
22 Correct 44 ms 8020 KB Output is correct
23 Correct 48 ms 8020 KB Output is correct
24 Correct 44 ms 8016 KB Output is correct
25 Correct 45 ms 8272 KB Output is correct
26 Correct 43 ms 8016 KB Output is correct
27 Correct 14 ms 3188 KB Output is correct
28 Correct 16 ms 3168 KB Output is correct
29 Correct 48 ms 8272 KB Output is correct
30 Correct 47 ms 8028 KB Output is correct
31 Correct 50 ms 8152 KB Output is correct
32 Correct 42 ms 8020 KB Output is correct
33 Correct 42 ms 8084 KB Output is correct
34 Correct 45 ms 8448 KB Output is correct
35 Correct 44 ms 8020 KB Output is correct
36 Correct 43 ms 8484 KB Output is correct
37 Correct 50 ms 8540 KB Output is correct
38 Correct 46 ms 8232 KB Output is correct
39 Correct 12 ms 3232 KB Output is correct
40 Correct 17 ms 3664 KB Output is correct
41 Correct 56 ms 8788 KB Output is correct
42 Correct 53 ms 8788 KB Output is correct
43 Correct 67 ms 9020 KB Output is correct
44 Correct 60 ms 8792 KB Output is correct
45 Correct 55 ms 8784 KB Output is correct
46 Correct 58 ms 8784 KB Output is correct
47 Correct 26 ms 8688 KB Output is correct
48 Correct 70 ms 8788 KB Output is correct
49 Correct 45 ms 7428 KB Output is correct
50 Correct 53 ms 8104 KB Output is correct
51 Correct 66 ms 8788 KB Output is correct
52 Correct 57 ms 8784 KB Output is correct
53 Correct 34 ms 7504 KB Output is correct
54 Correct 44 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 9808 KB Output is correct
2 Correct 63 ms 10072 KB Output is correct
3 Correct 57 ms 10324 KB Output is correct
4 Correct 42 ms 8556 KB Output is correct
5 Correct 55 ms 9552 KB Output is correct
6 Correct 74 ms 10320 KB Output is correct
7 Correct 19 ms 4696 KB Output is correct
8 Correct 20 ms 4500 KB Output is correct
9 Correct 31 ms 10088 KB Output is correct
10 Correct 39 ms 8460 KB Output is correct
11 Correct 65 ms 10064 KB Output is correct
12 Correct 67 ms 10108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 780 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 804 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 784 KB Output is correct
28 Correct 2 ms 712 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 45 ms 8100 KB Output is correct
40 Correct 44 ms 8020 KB Output is correct
41 Correct 48 ms 8020 KB Output is correct
42 Correct 44 ms 8016 KB Output is correct
43 Correct 45 ms 8272 KB Output is correct
44 Correct 43 ms 8016 KB Output is correct
45 Correct 14 ms 3188 KB Output is correct
46 Correct 16 ms 3168 KB Output is correct
47 Correct 48 ms 8272 KB Output is correct
48 Correct 47 ms 8028 KB Output is correct
49 Correct 50 ms 8152 KB Output is correct
50 Correct 42 ms 8020 KB Output is correct
51 Correct 42 ms 8084 KB Output is correct
52 Correct 45 ms 8448 KB Output is correct
53 Correct 44 ms 8020 KB Output is correct
54 Correct 43 ms 8484 KB Output is correct
55 Correct 50 ms 8540 KB Output is correct
56 Correct 46 ms 8232 KB Output is correct
57 Correct 12 ms 3232 KB Output is correct
58 Correct 17 ms 3664 KB Output is correct
59 Correct 56 ms 8788 KB Output is correct
60 Correct 53 ms 8788 KB Output is correct
61 Correct 67 ms 9020 KB Output is correct
62 Correct 60 ms 8792 KB Output is correct
63 Correct 55 ms 8784 KB Output is correct
64 Correct 58 ms 8784 KB Output is correct
65 Correct 26 ms 8688 KB Output is correct
66 Correct 70 ms 8788 KB Output is correct
67 Correct 45 ms 7428 KB Output is correct
68 Correct 53 ms 8104 KB Output is correct
69 Correct 66 ms 8788 KB Output is correct
70 Correct 57 ms 8784 KB Output is correct
71 Correct 34 ms 7504 KB Output is correct
72 Correct 44 ms 8272 KB Output is correct
73 Correct 52 ms 9808 KB Output is correct
74 Correct 63 ms 10072 KB Output is correct
75 Correct 57 ms 10324 KB Output is correct
76 Correct 42 ms 8556 KB Output is correct
77 Correct 55 ms 9552 KB Output is correct
78 Correct 74 ms 10320 KB Output is correct
79 Correct 19 ms 4696 KB Output is correct
80 Correct 20 ms 4500 KB Output is correct
81 Correct 31 ms 10088 KB Output is correct
82 Correct 39 ms 8460 KB Output is correct
83 Correct 65 ms 10064 KB Output is correct
84 Correct 67 ms 10108 KB Output is correct
85 Correct 61 ms 8940 KB Output is correct
86 Correct 61 ms 9548 KB Output is correct
87 Correct 59 ms 9044 KB Output is correct
88 Correct 66 ms 9588 KB Output is correct
89 Correct 46 ms 7924 KB Output is correct
90 Correct 63 ms 9296 KB Output is correct
91 Correct 54 ms 8528 KB Output is correct
92 Correct 54 ms 8272 KB Output is correct
93 Correct 65 ms 9304 KB Output is correct
94 Correct 61 ms 9296 KB Output is correct
95 Correct 61 ms 9300 KB Output is correct
96 Correct 67 ms 9300 KB Output is correct
97 Correct 72 ms 9296 KB Output is correct
98 Correct 58 ms 8692 KB Output is correct
99 Correct 28 ms 9552 KB Output is correct
100 Correct 50 ms 8788 KB Output is correct
101 Correct 63 ms 9296 KB Output is correct
102 Correct 348 ms 9040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 780 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 804 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 784 KB Output is correct
28 Correct 2 ms 712 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 45 ms 8100 KB Output is correct
40 Correct 44 ms 8020 KB Output is correct
41 Correct 48 ms 8020 KB Output is correct
42 Correct 44 ms 8016 KB Output is correct
43 Correct 45 ms 8272 KB Output is correct
44 Correct 43 ms 8016 KB Output is correct
45 Correct 14 ms 3188 KB Output is correct
46 Correct 16 ms 3168 KB Output is correct
47 Correct 48 ms 8272 KB Output is correct
48 Correct 47 ms 8028 KB Output is correct
49 Correct 50 ms 8152 KB Output is correct
50 Correct 42 ms 8020 KB Output is correct
51 Correct 42 ms 8084 KB Output is correct
52 Correct 45 ms 8448 KB Output is correct
53 Correct 44 ms 8020 KB Output is correct
54 Correct 43 ms 8484 KB Output is correct
55 Incorrect 84 ms 29440 KB Output isn't correct
56 Halted 0 ms 0 KB -