Submission #1329613

#TimeUsernameProblemLanguageResultExecution timeMemory
1329613benyFood Court (JOI21_foodcourt)C++20
0 / 100
166 ms151116 KiB
#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<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define int ll
#define smid (nl+nr)/2

const int N = 65e3, SQ = 300;
int n, m, q;

ll l[SQ], r[SQ], s[SQ][N];

ll tmp[N];


int32_t main(){

    vector<array<int, 5>> Q;
    vector<pair<int, int>> QQ;

    cin >> n >> m >> q;
    for (int i = 1; i <= q; i++) {
        int t; cin >> t;
        if (t == 1) {
            int l, r, c, k; cin >> l >> r >> c >> k;
            l--;
            r--;
            Q.push_back({ l, r, c, k, i });
        }
        if (t == 3) {
            ll A, B; cin >> A >> B;
            A--;
            QQ.push_back({ A, B });
        }
    }

    for (int i = 0; i < SQ; i++) {
        l[i] = SQ * i;
        r[i] = SQ * (i + 1);
    }

    for (int i = 0; i < SQ; i++) {
        for (int j = 0; j < n; j++) tmp[j] = 0;
        int mn = r[i];
        mn = min(mn, (int)Q.size());
        for (int j = l[i]; j < mn; j++) {
            tmp[Q[j][0]] += Q[j][3];
            tmp[Q[j][1]] -= Q[j][3];
        }
        for (int j = 1; j < n; j++) tmp[j] += tmp[j - 1];

        for (int j = 0; j < n; j++) s[i][j] = tmp[j];
    }

    for (int x = 0; x < QQ.size(); x++) {
        ll y = 0;
        int i = 0;
        for (; i < SQ; i++) {
            y += s[i][QQ[x].first];
            if (y >= QQ[x].second) break;
        }

        if (i == SQ) {
            cout << "0\n";
            continue;
        }

        y -= s[i][QQ[x].first];
        int mn = r[i];
        mn = min(mn, (int)(Q.size()));
        int res = 0;
        for (int j = l[i]; j < mn; j++) {
            if (Q[j][0] <= QQ[x].first && QQ[x].first < Q[j][1]) {
                y += Q[j][3];
                if (y >= QQ[x].second) {
                    res = Q[j][2];
                    break;
                }
            }
        }

        cout << res << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...