답안 #844796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844796 2023-09-06T00:51:08 Z Cookie 푸드 코트 (JOI21_foodcourt) C++14
2 / 100
88 ms 35160 KB
#include<bits/stdc++.h>
#define ll long long
#define vt vector
#define pb push_back
#define sz(v) (int)v.size()
#define pii pair<int, int>
using namespace std;
const ll base = 107, mod = 1e9 + 7;
const int mxn = 250000 + 5, inf = 1e9, sq = 400;
struct th{
    int type, val, colour, id;
};
struct Node{
    int sm, suf, idsuf;
};
int n, m, q;
vt<th>events[mxn + 1];
vt<pii>ask[mxn + 1];
int ans[mxn + 1];
Node st[4 * mxn + 1];
int mn[4 * mxn + 1], lz[4 * mxn + 1], co[mxn + 1];
void pull(int nd){
    st[nd].sm = st[nd << 1].sm + st[nd << 1 | 1].sm;
    ll cand1 = st[nd << 1 | 1].suf, cand2 = st[nd << 1 | 1].sm + st[nd << 1].suf;
    if(cand1 > cand2){
        st[nd].suf = cand1; st[nd].idsuf = st[nd << 1 | 1].idsuf;
    }else{
        st[nd].suf = cand2; st[nd].idsuf = st[nd << 1].idsuf;
    }
    mn[nd] = min(mn[nd << 1], mn[nd << 1 | 1]);
    return;
}
Node comb(Node a, Node b){
    Node res; res.sm = a.sm + b.sm;
    ll cand1 = b.suf, cand2 = b.sm + a.suf;
    if(cand1 > cand2){
        res.suf = cand1; res.idsuf = b.idsuf;
    }else{
        res.suf = cand2; res.idsuf = a.idsuf;
    }
    return(res);
}
void push(int nd){
    int &v = lz[nd];
    lz[nd << 1] += v; lz[nd << 1 | 1] += v; mn[nd << 1] += v; mn[nd << 1 | 1] += v;
    v = 0;
}
void upd(int nd, int l, int r, int id, int v){
    if(id < l || id > r)return;
    if(l == r){
        st[nd].sm += v;
        if(st[nd].sm >= 0){
            st[nd].suf =  st[nd].sm; st[nd].idsuf = l;
        }else{
            st[nd].suf = 0; st[nd].idsuf = l + 1;
        }
        return;
    }
    push(nd);
    int mid = (l + r) >> 1;
    upd(nd << 1, l, mid, id, v); upd(nd << 1 | 1, mid + 1, r, id, v);
    pull(nd);
}
void upd2(int nd, int l, int r, int ql, int qr, int v){
    if(ql > r || qr < l)return;
    if(ql <= l && qr >= r){
        mn[nd] += v; lz[nd] += v;
        return;
    }
    push(nd);
    int mid = (l + r) >> 1;
    upd2(nd << 1, l, mid, ql, qr, v); upd2(nd << 1 | 1, mid + 1, r, ql, qr, v);
    mn[nd] = min(mn[nd << 1], mn[nd << 1 | 1]);
}
Node get(int nd, int l, int r, int ql, int qr){
    if(ql <= l && qr >= r)return(st[nd]);
    int mid = (l + r) >> 1;
    push(nd);
    if(qr <= mid)return(get(nd << 1, l, mid, ql, qr));
    else if(ql > mid)return(get(nd << 1 | 1, mid + 1,r, ql, qr));
    else return(comb(get(nd << 1, l, mid, ql, qr), get(nd << 1 | 1, mid + 1, r, ql, qr)));
}
struct BIT{
    ll bit[mxn + 1];
    void upd(int p, ll v){
        while(p <= q){
            bit[p] += v; p += p & (-p);
        }
    }
    ll get(int p){
        ll ans = 0;
        while(p){
            ans += bit[p]; p -= p & (-p);
        }
        return(ans);
    }
    ll query(int l, int r){
        if(l > r)return(0);
        return(get(r) - get(l - 1));
    }
    int kth(ll x){
        ll sm = 0, id = 0;
        for(int i = 18; i >= 0; i--){
            if(id + (1 << i) <= q && sm + bit[id + (1 << i)] < x){
                id += (1 << i); sm += bit[id];
            }
        }
        return(id + 1);
    }
};
BIT one, two;
int getp(int nd, int l, int r, int id){
    if(id == 0)return(0);
    if(l == r)return(mn[nd]);
    int mid = (l + r) >> 1;
    push(nd);
    if(id <= mid)return(getp(nd << 1, l, mid, id));
    return(getp(nd << 1 | 1, mid + 1, r, id));
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> q;
    set<int>active;
    for(int i = 1; i <= q; i++){
        upd(1, 1, q, i, 0);
    }
    for(int i = 1; i <= q; i++){
        int idq; cin >> idq;
        if(idq == 1){
            int l, r, x, k; cin >> l >> r >> k >> x;
            events[l].pb({1, x, k, i}); events[r + 1].pb({1, -x, k, i});
            co[i] = k;
        }else if(idq == 2){
            int l, r, k; cin >> l >> r >> k;
            events[l].pb({2, k, -1, i}); events[r + 1].pb({2, -k, -1, i});
            
        }else{
            int id, x; cin >> id >> x;
            ask[id].pb({x, i});
        }
    }
    for(int i = 1; i <= n; i++){
        for(auto [type, val, colour, id]: events[i]){
            if(type == 1){
                upd(1, 1, q, id, val);
                one.upd(id, val);
            }else{
                upd(1, 1, q, id, -val);
                //upd2(1, 1, q, id, q, -val);
                two.upd(id, -val);
            }
            
        }
        for(auto [x, idq]: ask[i]){
            Node cool = get(1, 1, q, 1, idq);
           
            if(cool.suf < x){
                ans[idq] = -1;
            }else{
                int idd = cool.idsuf;
                
                ll needid = -two.query(idd, idq) + x + one.query(1, idd - 1);
                
                ll idres = one.kth(needid);
                ans[idq] = co[idres];
            }
        }
    }
    for(int i = 1; i <= q; i++){
        if(ans[i]){
            if(ans[i] == -1)cout << 0 << "\n";
            else cout << ans[i] << "\n";
        }
    }
}

Compilation message

foodcourt.cpp: In function 'int main()':
foodcourt.cpp:143:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  143 |         for(auto [type, val, colour, id]: events[i]){
      |                  ^
foodcourt.cpp:154:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  154 |         for(auto [x, idq]: ask[i]){
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Correct 5 ms 21080 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 6 ms 21080 KB Output is correct
5 Correct 5 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 6 ms 21080 KB Output is correct
8 Correct 6 ms 21080 KB Output is correct
9 Correct 5 ms 21080 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21084 KB Output is correct
12 Correct 5 ms 21080 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
14 Correct 5 ms 21080 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 5 ms 21084 KB Output is correct
17 Correct 5 ms 21080 KB Output is correct
18 Correct 7 ms 21080 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 5 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Correct 5 ms 21080 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 6 ms 21080 KB Output is correct
5 Correct 5 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 6 ms 21080 KB Output is correct
8 Correct 6 ms 21080 KB Output is correct
9 Correct 5 ms 21080 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21084 KB Output is correct
12 Correct 5 ms 21080 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
14 Correct 5 ms 21080 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 5 ms 21084 KB Output is correct
17 Correct 5 ms 21080 KB Output is correct
18 Correct 7 ms 21080 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 5 ms 21084 KB Output is correct
21 Incorrect 4 ms 21080 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 64 ms 25936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 35160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Correct 5 ms 21080 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 6 ms 21080 KB Output is correct
5 Correct 5 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 6 ms 21080 KB Output is correct
8 Correct 6 ms 21080 KB Output is correct
9 Correct 5 ms 21080 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21084 KB Output is correct
12 Correct 5 ms 21080 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
14 Correct 5 ms 21080 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 5 ms 21084 KB Output is correct
17 Correct 5 ms 21080 KB Output is correct
18 Correct 7 ms 21080 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 5 ms 21084 KB Output is correct
21 Incorrect 64 ms 25936 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 23772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Correct 5 ms 21080 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 6 ms 21080 KB Output is correct
5 Correct 5 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 6 ms 21080 KB Output is correct
8 Correct 6 ms 21080 KB Output is correct
9 Correct 5 ms 21080 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21084 KB Output is correct
12 Correct 5 ms 21080 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
14 Correct 5 ms 21080 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 5 ms 21084 KB Output is correct
17 Correct 5 ms 21080 KB Output is correct
18 Correct 7 ms 21080 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 5 ms 21084 KB Output is correct
21 Incorrect 4 ms 21080 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Correct 5 ms 21080 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 6 ms 21080 KB Output is correct
5 Correct 5 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 6 ms 21080 KB Output is correct
8 Correct 6 ms 21080 KB Output is correct
9 Correct 5 ms 21080 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21084 KB Output is correct
12 Correct 5 ms 21080 KB Output is correct
13 Correct 5 ms 21080 KB Output is correct
14 Correct 5 ms 21080 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 5 ms 21084 KB Output is correct
17 Correct 5 ms 21080 KB Output is correct
18 Correct 7 ms 21080 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 5 ms 21084 KB Output is correct
21 Incorrect 4 ms 21080 KB Output isn't correct
22 Halted 0 ms 0 KB -