Submission #831714

# Submission time Handle Problem Language Result Execution time Memory
831714 2023-08-20T12:36:42 Z Ronin13 Food Court (JOI21_foodcourt) C++17
24 / 100
195 ms 72664 KB
#include <bits/stdc++.h>
#define ll long long  
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

const int nmax = 250001;

struct node{
    ll sum, mn;
    ll sum1, sum2;
    int ind;
    node(){
        sum = mn = sum1 = 0;
        ind = 0;
        sum2 = 0;
    }
    node(int val){
        mn = min(0, val);
        sum = sum1 = val;
    }
}t[4 * nmax];

node merg(node a, node b){
    node c;
    c.sum = a.sum + b.sum;
    c.sum1 = a.sum1 + b.sum1;
    c.sum2 = a.sum2 + b.sum2;
    if(a.mn <= a.sum + b.mn){
        c.mn = a.mn;
        c.ind = a.ind;
    }
    else{
        c.mn = a.sum + b.mn;
        c.ind = b.ind;
    }
    return c;
}

void add(int v, int l, int r, int pos, ll val){
    if(l > pos || r < pos) return;
    if(l == r){
        t[v].sum = val;
        t[v].mn = val;
        t[v].sum1 = val;
        return;
    }
    int m = (l + r) / 2;
    add(2 * v, l,m, pos, val);
    add(2 *  v + 1, m + 1, r, pos, val);
    t[v] = merg(t[2 * v], t[2 * v + 1]);
}

void rem(int v, int l, int r, int pos, ll val){
    if(l > pos || r < pos) return;
    if(l == r){
        t[v].sum = -val;
        t[v].mn = -val;
        t[v].sum2 = val;
        return;
    }
    int m = (l + r) / 2;
    rem(2 * v,l, m, pos, val);
    rem(2 * v + 1, m + 1, r, pos, val);
    t[v] = merg(t[2 * v], t[2 * v +  1]);
}


node get_mn(int v, int l, int r, int st, int fin){
    if(l > fin || r < st) return {0};
    if(l >= st && r <= fin){
        return t[v];
    }
    int m = (l + r) / 2;
    return merg(get_mn(2 * v, l, m, st, fin),
                    get_mn(2 * v + 1, m + 1, r, st, fin));
}


ll get(int v, int l, int r, int st, int fin){
    if(l > fin || r < st){
        return 0;
    }
    if(l >= st && r <= fin){
        return t[v].sum1;
    }
    int m = (l + r) / 2;
    return get(2 * v, l, m, st, fin) + get(2 * v + 1,m + 1, r, st, fin);
}
ll get1(int v, int l, int r, int st, int fin){
    if(l > fin || r < st)
        return 0;
    if(l >= st && r <= fin){
        return t[v].sum2;
    }
    int m = (l + r) / 2;
    return get1(2 * v, l, m, st, fin) + 
            get1(2 * v + 1, m + 1, r, st, fin);
}

int getfirst(int v, int l, int r, int st, int fin, ll val){
    if(l > fin || r < st) return 0;
    if(l >= st && r <= fin){
        if(t[v].sum1 >= val) {
            while(l != r){
                int m = (l + r) / 2;
                if(t[v * 2].sum1 >= val) v *= 2, r = m;
                else val -= t[2 * v].sum1, v = v * 2 + 1, l = m + 1;
            }
            return l;
        }
        return 0;
    }
    int m = (l + r) / 2;
    int x = getfirst(2 * v, l, m, st, fin, val);
    if(x) return x;
    return getfirst(2 * v + 1, m + 1, r, st, fin, val - t[2 * v].sum1);
}

void build(int v, int l, int r){
    if(l == r){
        t[v].ind = l;
        return;
    }
    int m = (l + r)/ 2;
    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
}


int main(){
    int n, m, q; cin >> n >> m >> q;
    build(1, 1, q + 1);
    add(1, 1, q + 1, 1, 0);
    vector <vector <pair<int, int> > > in(n + 1);
    vector <vector <pair<int, int> > > out(n + 1);
    vector <vector <pii> > uu(n + 1);
    vector <vector <pii> > vv(n + 1);
    vector <vector <pii> > qv(n + 1);
    int Val[q + 1];
   vector <pll> ans;
    for(int i = 1; i <= q; i++){
        int t; cin >> t;
        if(t == 1){
            int a, b, c; cin >> a >> b >> c;
            int d; cin >> d;
            Val[i] = c;
            in[a].pb({d, i});
            out[b].pb({d, i});
        }
        if(t == 2){
            int a, b, c; cin >> a >> b >> c;
            uu[a].pb({c, i});
            vv[b].pb({0, i});
        }
        if(t == 3){
            int p; cin >> p;
            int b; cin >> b;
            qv[p].pb({i, b});
        }
    }
    q++;
    for(int i = 1; i <= n; ++i){
        for(auto to : in[i]){
            add(1, 1, q, to.s + 1, to.f);
        }
        for(auto to : uu[i]){
            rem(1, 1, q, to.s + 1, to.f);
        }
        for(auto to : qv[i]){
            node x = get_mn(1, 1, q, 1, to.f);
            //cout << x.ind << "\n";
            ll sum = get(1, 1, q, 1, x.ind);
            ll val = get1(1, 1, q, x.ind + 1, to.f);
            int pp = getfirst(1, 1, q, x.ind, to.f, val + sum + to.s);
            if(pp > 1){
                ans.pb({to.f, Val[pp - 1]});
            }
            else ans.pb({to.f, 0});
        }
        for(auto to : out[i]){
            add(1, 1, q, to.s + 1, 0);
        }
        for(auto to : vv[i]){
            rem(1, 1, q, to.s + 1, 0);
        }
    }
    sort(ans.begin(), ans.end());
    for(auto to : ans){
        cout << to.s << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 39636 KB Output is correct
2 Correct 18 ms 39764 KB Output is correct
3 Correct 18 ms 39688 KB Output is correct
4 Correct 19 ms 39764 KB Output is correct
5 Correct 17 ms 39428 KB Output is correct
6 Correct 18 ms 39456 KB Output is correct
7 Correct 19 ms 39716 KB Output is correct
8 Correct 18 ms 39764 KB Output is correct
9 Correct 19 ms 39800 KB Output is correct
10 Correct 19 ms 39708 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 22 ms 39736 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 19 ms 39716 KB Output is correct
16 Correct 19 ms 39764 KB Output is correct
17 Correct 18 ms 39636 KB Output is correct
18 Correct 19 ms 39756 KB Output is correct
19 Correct 19 ms 39628 KB Output is correct
20 Correct 20 ms 39740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 39636 KB Output is correct
2 Correct 18 ms 39764 KB Output is correct
3 Correct 18 ms 39688 KB Output is correct
4 Correct 19 ms 39764 KB Output is correct
5 Correct 17 ms 39428 KB Output is correct
6 Correct 18 ms 39456 KB Output is correct
7 Correct 19 ms 39716 KB Output is correct
8 Correct 18 ms 39764 KB Output is correct
9 Correct 19 ms 39800 KB Output is correct
10 Correct 19 ms 39708 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 22 ms 39736 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 19 ms 39716 KB Output is correct
16 Correct 19 ms 39764 KB Output is correct
17 Correct 18 ms 39636 KB Output is correct
18 Correct 19 ms 39756 KB Output is correct
19 Correct 19 ms 39628 KB Output is correct
20 Correct 20 ms 39740 KB Output is correct
21 Incorrect 17 ms 39772 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 129 ms 51980 KB Output is correct
2 Correct 115 ms 51852 KB Output is correct
3 Correct 125 ms 52008 KB Output is correct
4 Correct 116 ms 51932 KB Output is correct
5 Correct 126 ms 51912 KB Output is correct
6 Correct 115 ms 51912 KB Output is correct
7 Correct 75 ms 41732 KB Output is correct
8 Correct 77 ms 42012 KB Output is correct
9 Correct 150 ms 52056 KB Output is correct
10 Correct 115 ms 51756 KB Output is correct
11 Correct 114 ms 51788 KB Output is correct
12 Correct 127 ms 51876 KB Output is correct
13 Correct 106 ms 48748 KB Output is correct
14 Correct 132 ms 51788 KB Output is correct
15 Correct 119 ms 48880 KB Output is correct
16 Correct 130 ms 51736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 195 ms 72664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 39636 KB Output is correct
2 Correct 18 ms 39764 KB Output is correct
3 Correct 18 ms 39688 KB Output is correct
4 Correct 19 ms 39764 KB Output is correct
5 Correct 17 ms 39428 KB Output is correct
6 Correct 18 ms 39456 KB Output is correct
7 Correct 19 ms 39716 KB Output is correct
8 Correct 18 ms 39764 KB Output is correct
9 Correct 19 ms 39800 KB Output is correct
10 Correct 19 ms 39708 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 22 ms 39736 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 19 ms 39716 KB Output is correct
16 Correct 19 ms 39764 KB Output is correct
17 Correct 18 ms 39636 KB Output is correct
18 Correct 19 ms 39756 KB Output is correct
19 Correct 19 ms 39628 KB Output is correct
20 Correct 20 ms 39740 KB Output is correct
21 Correct 129 ms 51980 KB Output is correct
22 Correct 115 ms 51852 KB Output is correct
23 Correct 125 ms 52008 KB Output is correct
24 Correct 116 ms 51932 KB Output is correct
25 Correct 126 ms 51912 KB Output is correct
26 Correct 115 ms 51912 KB Output is correct
27 Correct 75 ms 41732 KB Output is correct
28 Correct 77 ms 42012 KB Output is correct
29 Correct 150 ms 52056 KB Output is correct
30 Correct 115 ms 51756 KB Output is correct
31 Correct 114 ms 51788 KB Output is correct
32 Correct 127 ms 51876 KB Output is correct
33 Correct 106 ms 48748 KB Output is correct
34 Correct 132 ms 51788 KB Output is correct
35 Correct 119 ms 48880 KB Output is correct
36 Correct 130 ms 51736 KB Output is correct
37 Correct 119 ms 50600 KB Output is correct
38 Correct 103 ms 50052 KB Output is correct
39 Correct 64 ms 41584 KB Output is correct
40 Correct 81 ms 41828 KB Output is correct
41 Correct 112 ms 51620 KB Output is correct
42 Correct 149 ms 51560 KB Output is correct
43 Correct 124 ms 51516 KB Output is correct
44 Correct 132 ms 51676 KB Output is correct
45 Correct 115 ms 51592 KB Output is correct
46 Correct 120 ms 51596 KB Output is correct
47 Correct 100 ms 50060 KB Output is correct
48 Correct 115 ms 50700 KB Output is correct
49 Correct 104 ms 48020 KB Output is correct
50 Correct 128 ms 50928 KB Output is correct
51 Correct 146 ms 51676 KB Output is correct
52 Correct 150 ms 51596 KB Output is correct
53 Correct 104 ms 49648 KB Output is correct
54 Correct 136 ms 51564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 48816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 39636 KB Output is correct
2 Correct 18 ms 39764 KB Output is correct
3 Correct 18 ms 39688 KB Output is correct
4 Correct 19 ms 39764 KB Output is correct
5 Correct 17 ms 39428 KB Output is correct
6 Correct 18 ms 39456 KB Output is correct
7 Correct 19 ms 39716 KB Output is correct
8 Correct 18 ms 39764 KB Output is correct
9 Correct 19 ms 39800 KB Output is correct
10 Correct 19 ms 39708 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 22 ms 39736 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 19 ms 39716 KB Output is correct
16 Correct 19 ms 39764 KB Output is correct
17 Correct 18 ms 39636 KB Output is correct
18 Correct 19 ms 39756 KB Output is correct
19 Correct 19 ms 39628 KB Output is correct
20 Correct 20 ms 39740 KB Output is correct
21 Incorrect 17 ms 39772 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 39636 KB Output is correct
2 Correct 18 ms 39764 KB Output is correct
3 Correct 18 ms 39688 KB Output is correct
4 Correct 19 ms 39764 KB Output is correct
5 Correct 17 ms 39428 KB Output is correct
6 Correct 18 ms 39456 KB Output is correct
7 Correct 19 ms 39716 KB Output is correct
8 Correct 18 ms 39764 KB Output is correct
9 Correct 19 ms 39800 KB Output is correct
10 Correct 19 ms 39708 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 22 ms 39736 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 19 ms 39716 KB Output is correct
16 Correct 19 ms 39764 KB Output is correct
17 Correct 18 ms 39636 KB Output is correct
18 Correct 19 ms 39756 KB Output is correct
19 Correct 19 ms 39628 KB Output is correct
20 Correct 20 ms 39740 KB Output is correct
21 Incorrect 17 ms 39772 KB Output isn't correct
22 Halted 0 ms 0 KB -