Submission #421895

# Submission time Handle Problem Language Result Execution time Memory
421895 2021-06-09T13:26:07 Z lyc Food Court (JOI21_foodcourt) C++14
0 / 100
1000 ms 23380 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;

const int mxN = 250005;
const int mxM = 250005;
const int mxQ = 250005;

int N, M, Q;
int group[mxM];

struct node {
    int s, e, m;
    ll v;
    node *l, *r;
    node(int s, int e): s(s), e(e), m((s+e)/2), v(0) {
        if (s != e) {
            l = new node(s,m);
            r = new node(m+1,e);
        }
    }

    node(node* n): s(n->s), e(n->e), m(n->m), v(n->v), l(n->l), r(n->r) {}

    node* uadd(int a, int b, ll c) {
        node *n(this);
        if (a <= s && e <= b) {
            n->v += c;
        } else {
            if (a <= m) n->l = l->uadd(a,b,c);
            if (b > m) n->r = r->uadd(a,b,c);
        }
        return n;
    }

    ll qsum(int a) {
        ll ret = v;
        if (s != e) {
            if (a <= m) ret += l->qsum(a);
            else ret += r->qsum(a);
        }
        return ret;
    }

    void debug() {
        TRACE(s _ e _ v);
        if (s != e) {
            l->debug();
            r->debug();
        }
    }

} *enter[mxN];

ll leave[mxN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    cin >> N >> M >> Q;
    enter[0] = new node(1,N);
    memset(leave,0,sizeof leave);
    FOR(i,1,Q){
        int T, L, R, C, K, A;
        long long B;
        cin >> T;
        enter[i] = new node(enter[i-1]);
        if (T == 1) {
            cin >> L >> R >> C >> K;
            enter[i] = enter[i]->uadd(L,R,K);
            group[i] = C;
        } else if (T == 2) {
            cin >> L >> R >> K;
            FOR(a,L,R){
                ll cur = enter[i]->qsum(a);
                leave[a] += min(cur,(ll)K);
            }
        } else {
            cin >> A >> B;
            B += leave[A];

            int lo = 1, hi = i;
            while (hi-lo > 1) {
                int mid = (lo+hi)/2;
                if (enter[mid]->qsum(A) < B) lo = mid;
                else hi = mid;
            }

            if (hi == i) cout << 0 << '\n';
            else cout << group[hi] << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 8488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 23380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 11664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2508 KB Output isn't correct
2 Halted 0 ms 0 KB -