Submission #742635

# Submission time Handle Problem Language Result Execution time Memory
742635 2023-05-16T15:56:51 Z GrindMachine Food Court (JOI21_foodcourt) C++17
0 / 100
237 ms 17896 KB
// Om Namah Shivaya

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a, b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a, b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*



*/

const int MOD = 1e9 + 7;
const int N = 1 << 17;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#define data DATA

struct data {
    ll a;

    data() {
        a = 0;
    }
};

data d_neutral = data();

vector<int> roots(N);
vector<data> tr = {data()};
vector<pii> child = {{0, 0}};
int ptr = 1;

void merge(data &curr, data &left, data &right) {
    curr.a = left.a + right.a;
}

void modify(int x, int lx, int rx, ll v) {
    tr[x].a += v;
}

void pupd(int x, int px, int lx, int rx, int i, ll v) {
    if (rx - lx == 1) {
        modify(x, lx, rx, v);
        return;
    }

    int mid = (lx + rx) >> 1;

    if (i < mid) {
        child[x].ff = ptr++;
        tr.pb(data());
        child.pb(pii());

        child[x].ss = child[px].ss;
        pupd(child[x].ff, child[px].ff, lx, mid, i, v);
    }
    else {
        child[x].ss = ptr++;
        tr.pb(data());
        child.pb(pii());

        child[x].ff = child[px].ff;
        pupd(child[x].ss, child[px].ss, mid, rx, i, v);
    }

    merge(tr[x], tr[child[x].ff], tr[child[x].ss]);
}

void pupd(int curr, int prev, int i, ll v) {
    ll new_root = ptr++;
    tr.pb(data());
    child.pb(pii());

    pupd(new_root, roots[prev], 0, N, i, v);
    roots[curr] = new_root;
}

data query(int x, int lx, int rx, int l, int r) {
    if (lx >= r or rx <= l) return d_neutral;
    if (lx >= l and rx <= r) return tr[x];

    int mid = (lx + rx) >> 1;

    data left = query(child[x].ff, lx, mid, l, r);
    data right = query(child[x].ss, mid, rx, l, r);

    data curr;
    merge(curr, left, right);

    return curr;
}

data query(int curr, int l, int r) {
    r++;
    return query(roots[curr], 0, N, l, r);
}

void solve(int test_case)
{
    ll n, m, q; cin >> n >> m >> q;
    vector<ll> group(q + 5);

    rep1(i, q) {
        ll t; cin >> t;
        roots[i] = roots[i - 1];

        if (t == 1) {
            ll l, r, c, k; cin >> l >> r >> c >> k;
            pupd(i, i, l, k);
            pupd(i, i, r + 1, -k);
            group[i] = c;
        }
        else if (t == 2) {
            assert(0);
        }
        else {
            ll x, y; cin >> x >> y;
            ll lo = 1, hi = i - 1;
            ll first = -1;

            while (lo <= hi) {
                ll mid = (lo + hi) >> 1;
                if (query(mid, 1, x).a >= y) {
                    first = mid;
                    hi = mid - 1;
                }
                else {
                    lo = mid + 1;
                }
            }

            ll ans = 0;
            if (first != -1) {
                ans = group[first];
            }

            cout << ans << endl;
        }
    }
}

int main()
{
    fastio;

    int t = 1;
    // cin >> t;

    rep1(i, t) {
        solve(i);
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2516 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 237 ms 17896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -