Submission #1329607

#TimeUsernameProblemLanguageResultExecution timeMemory
1329607SinaPourkashaniFood Court (JOI21_foodcourt)C++20
9 / 100
1102 ms206428 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector <pair<ll, ll>> vp;
typedef pair<ll, ll> pll;
typedef map <ll, ll> mll;
typedef set <ll> sll;
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define print(x) for (auto i : x) cout << i << ' '; cout << '\n';
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);

const ll maxn = 250000+5;
const ll mod = 1e9+7;
const ll inf = 2e18;

ll pw(ll a, ll b, ll M = mod) {ll ans = 1; for (; b; a = ((a * a) % M), b >>= 1) if (b & 1) ans = (ans * a) % M; return ans;}

ll n, m, q, d[maxn], seg[4*maxn];
vll vct[maxn];

void upd(ll id, ll l, ll r, ll s, ll e, ll x) {
    if (s >= r || e <= l) return;
    if (s <= l && e >= r) {
        seg[id] += x;
        return;
    }

    ll mid = (l+r)/2;
    upd(2*id, l, mid, s, e, x);
    upd(2*id+1, mid, r, s, e, x);
}

ll get(ll id, ll l, ll r, ll p) {
    if (r - l == 1) {
        return seg[id];
    }

    ll mid = (l+r)/2;
    if (p < mid) return seg[id] + get(2*id, l, mid, p);
    return seg[id] + get(2*id+1, mid, r, p);
}

int main() {
    FastIO

    cin >> n >> m >> q;

    while (q--) {
        ll t, l, r, c, k, a, b;

        cin >> t;
        if (t == 1) {
            cin >> l >> r >> c >> k;

            for (ll i = l; i <= r; i++) {
                ll g = get(1, 1, n+1, i);
                if (vct[i].empty()) upd(1, 1, n+1, i, i+1, -g);
                else {
                    if ((ll)vct[i].size() < g) {
                        upd(1, 1, n+1, i, i+1, -(g-vct[i].size()));
                    } 
                };

                vct[i].pb(c);
            }
        } else if (t == 2) {
            cin >> l >> r >> k;
            
            upd(1, 1, n+1, l, r+1, k);
        } else {
            cin >> a >> b;

            b += get(1, 1, n+1, a);
            
            if (b > (ll)vct[a].size()) cout << 0 << '\n';
            else cout << vct[a][b-1] << '\n';
        }
    }

    return 0;
}
#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...