답안 #831721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831721 2023-08-20T12:40:09 Z Ronin13 푸드 코트 (JOI21_foodcourt) C++17
24 / 100
530 ms 84120 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){
            ll a, b, c; cin >> a >> b >> c;
            ll d; cin >> d;
            Val[i] = c;
            in[a].pb({d, i});
            out[b].pb({d, i});
        }
        if(t == 2){
            ll a, b, c; cin >> a >> b >> c;
            uu[a].pb({c, i});
            vv[b].pb({0, i});
        }
        if(t == 3){
            int p; cin >> p;
            ll 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 39696 KB Output is correct
2 Correct 19 ms 39720 KB Output is correct
3 Correct 19 ms 39704 KB Output is correct
4 Correct 18 ms 39760 KB Output is correct
5 Correct 20 ms 39448 KB Output is correct
6 Correct 19 ms 39432 KB Output is correct
7 Correct 19 ms 39768 KB Output is correct
8 Correct 19 ms 39764 KB Output is correct
9 Correct 21 ms 39760 KB Output is correct
10 Correct 19 ms 39704 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 19 ms 39716 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 18 ms 39636 KB Output is correct
16 Correct 21 ms 39704 KB Output is correct
17 Correct 19 ms 39636 KB Output is correct
18 Correct 19 ms 39760 KB Output is correct
19 Correct 18 ms 39684 KB Output is correct
20 Correct 19 ms 39792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 39696 KB Output is correct
2 Correct 19 ms 39720 KB Output is correct
3 Correct 19 ms 39704 KB Output is correct
4 Correct 18 ms 39760 KB Output is correct
5 Correct 20 ms 39448 KB Output is correct
6 Correct 19 ms 39432 KB Output is correct
7 Correct 19 ms 39768 KB Output is correct
8 Correct 19 ms 39764 KB Output is correct
9 Correct 21 ms 39760 KB Output is correct
10 Correct 19 ms 39704 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 19 ms 39716 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 18 ms 39636 KB Output is correct
16 Correct 21 ms 39704 KB Output is correct
17 Correct 19 ms 39636 KB Output is correct
18 Correct 19 ms 39760 KB Output is correct
19 Correct 18 ms 39684 KB Output is correct
20 Correct 19 ms 39792 KB Output is correct
21 Incorrect 19 ms 39772 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 51948 KB Output is correct
2 Correct 121 ms 51900 KB Output is correct
3 Correct 118 ms 51964 KB Output is correct
4 Correct 128 ms 51952 KB Output is correct
5 Correct 125 ms 51892 KB Output is correct
6 Correct 124 ms 51896 KB Output is correct
7 Correct 77 ms 41848 KB Output is correct
8 Correct 75 ms 41976 KB Output is correct
9 Correct 122 ms 52008 KB Output is correct
10 Correct 120 ms 51788 KB Output is correct
11 Correct 115 ms 51832 KB Output is correct
12 Correct 129 ms 51916 KB Output is correct
13 Correct 104 ms 48716 KB Output is correct
14 Correct 113 ms 51732 KB Output is correct
15 Correct 116 ms 48844 KB Output is correct
16 Correct 113 ms 51664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 530 ms 84120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 39696 KB Output is correct
2 Correct 19 ms 39720 KB Output is correct
3 Correct 19 ms 39704 KB Output is correct
4 Correct 18 ms 39760 KB Output is correct
5 Correct 20 ms 39448 KB Output is correct
6 Correct 19 ms 39432 KB Output is correct
7 Correct 19 ms 39768 KB Output is correct
8 Correct 19 ms 39764 KB Output is correct
9 Correct 21 ms 39760 KB Output is correct
10 Correct 19 ms 39704 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 19 ms 39716 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 18 ms 39636 KB Output is correct
16 Correct 21 ms 39704 KB Output is correct
17 Correct 19 ms 39636 KB Output is correct
18 Correct 19 ms 39760 KB Output is correct
19 Correct 18 ms 39684 KB Output is correct
20 Correct 19 ms 39792 KB Output is correct
21 Correct 119 ms 51948 KB Output is correct
22 Correct 121 ms 51900 KB Output is correct
23 Correct 118 ms 51964 KB Output is correct
24 Correct 128 ms 51952 KB Output is correct
25 Correct 125 ms 51892 KB Output is correct
26 Correct 124 ms 51896 KB Output is correct
27 Correct 77 ms 41848 KB Output is correct
28 Correct 75 ms 41976 KB Output is correct
29 Correct 122 ms 52008 KB Output is correct
30 Correct 120 ms 51788 KB Output is correct
31 Correct 115 ms 51832 KB Output is correct
32 Correct 129 ms 51916 KB Output is correct
33 Correct 104 ms 48716 KB Output is correct
34 Correct 113 ms 51732 KB Output is correct
35 Correct 116 ms 48844 KB Output is correct
36 Correct 113 ms 51664 KB Output is correct
37 Correct 111 ms 50628 KB Output is correct
38 Correct 96 ms 50052 KB Output is correct
39 Correct 65 ms 41592 KB Output is correct
40 Correct 74 ms 41836 KB Output is correct
41 Correct 127 ms 51608 KB Output is correct
42 Correct 116 ms 51616 KB Output is correct
43 Correct 116 ms 51528 KB Output is correct
44 Correct 134 ms 51624 KB Output is correct
45 Correct 113 ms 51564 KB Output is correct
46 Correct 126 ms 51528 KB Output is correct
47 Correct 98 ms 50116 KB Output is correct
48 Correct 105 ms 50668 KB Output is correct
49 Correct 93 ms 48188 KB Output is correct
50 Correct 106 ms 50960 KB Output is correct
51 Correct 119 ms 51560 KB Output is correct
52 Correct 116 ms 51652 KB Output is correct
53 Correct 97 ms 49680 KB Output is correct
54 Correct 127 ms 51608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 116 ms 51216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 39696 KB Output is correct
2 Correct 19 ms 39720 KB Output is correct
3 Correct 19 ms 39704 KB Output is correct
4 Correct 18 ms 39760 KB Output is correct
5 Correct 20 ms 39448 KB Output is correct
6 Correct 19 ms 39432 KB Output is correct
7 Correct 19 ms 39768 KB Output is correct
8 Correct 19 ms 39764 KB Output is correct
9 Correct 21 ms 39760 KB Output is correct
10 Correct 19 ms 39704 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 19 ms 39716 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 18 ms 39636 KB Output is correct
16 Correct 21 ms 39704 KB Output is correct
17 Correct 19 ms 39636 KB Output is correct
18 Correct 19 ms 39760 KB Output is correct
19 Correct 18 ms 39684 KB Output is correct
20 Correct 19 ms 39792 KB Output is correct
21 Incorrect 19 ms 39772 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 39696 KB Output is correct
2 Correct 19 ms 39720 KB Output is correct
3 Correct 19 ms 39704 KB Output is correct
4 Correct 18 ms 39760 KB Output is correct
5 Correct 20 ms 39448 KB Output is correct
6 Correct 19 ms 39432 KB Output is correct
7 Correct 19 ms 39768 KB Output is correct
8 Correct 19 ms 39764 KB Output is correct
9 Correct 21 ms 39760 KB Output is correct
10 Correct 19 ms 39704 KB Output is correct
11 Correct 19 ms 39764 KB Output is correct
12 Correct 19 ms 39764 KB Output is correct
13 Correct 19 ms 39716 KB Output is correct
14 Correct 19 ms 39792 KB Output is correct
15 Correct 18 ms 39636 KB Output is correct
16 Correct 21 ms 39704 KB Output is correct
17 Correct 19 ms 39636 KB Output is correct
18 Correct 19 ms 39760 KB Output is correct
19 Correct 18 ms 39684 KB Output is correct
20 Correct 19 ms 39792 KB Output is correct
21 Incorrect 19 ms 39772 KB Output isn't correct
22 Halted 0 ms 0 KB -