Submission #537205

# Submission time Handle Problem Language Result Execution time Memory
537205 2022-03-14T18:06:45 Z Jarif_Rahman Food Court (JOI21_foodcourt) C++17
0 / 100
58 ms 43300 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
struct BIT{
    int n;
    vector<ll> sm;
    BIT(int _n){
        n = _n;
        sm.resize(n);
    }
    void add(int in, ll x){
        in++;
        while(in <= n) sm[in-1]+=x, in+=in&-in;
    }
    ll sum(int in){
        in++;
        ll s = 0;
        while(in >= 1) s+=sm[in-1], in-=in&-in;
        return s;
    }
    ll sum(int l, int r){
        return sum(r)-(l == 0? 0:sum(l-1));
    }
};
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, q; cin >> n >> m >> q;

    vector<vector<int>> ql(n), qr(n);
    vector<int> ans;
    vector<pair<int, ll>> queries(q, {-1, -1});
    vector<vector<pair<int, int>>> qq(n);

    BIT sum(n+1);

    for(int i = 0; i < q; i++){
        int tt; cin >> tt;
        if(tt == 1){
            int l, r, c; ll k; cin >> l >> r >> c >> k; l--, r--;
            queries[i] = {c, k};
            ql[l].pb(i);
            qr[r].pb(i);
            sum.add(l, k);
            sum.add(r+1, -k);
        }
        else{
            int a; ll b; cin >> a >> b; a--;
            if(sum.sum(0, a) < b) ans.pb(0);
            else{
                qq[a].pb({b, ans.size()});
                ans.pb(-1);
            }
        }
    }

    BIT Q(q+1);
    for(int i = n-1; i >= 0; i--){
        for(int x: qr[i]) Q.add(x, queries[x].sc);

        for(auto [b, in]: qq[i]){
            int l = 0, r = q-1;
            while(l < r){
                int md = (l+r)/2;
                if(Q.sum(0, md) >= b) r = md;
                else l = md+1;
            }
            ans[in] = queries[l].f;
        }

        for(int x: ql[i]) Q.add(x, queries[x].sc);
    }

    for(int x: ans) cout << x << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 12784 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 43300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 10184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -