Submission #1069371

# Submission time Handle Problem Language Result Execution time Memory
1069371 2024-08-21T20:36:22 Z ArthuroWich Distributing Candies (IOI21_candies) C++17
11 / 100
189 ms 21616 KB
#include "candies.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int seg[4*200005], lazy[4*200005];
void lazypropagate(int n, int l, int r) {
    if (lazy[n]) {
        seg[n] += (r-l+1)*lazy[n];
        if (l != r) {
            lazy[2*n] += lazy[n];
            lazy[2*n+1] += lazy[n];
        }
        lazy[n] = 0;
    }
}
void update(int n, int l, int r, int a, int b, int v) {
    lazypropagate(n, l, r);
    if (b < l || r < a) {
        return;
    } else if (a <= l && r <= b) {
        lazy[n] += v;
        lazypropagate(n, l, r);
    } else {
        int m = (l+r)/2;
        update(2*n, l, m, a, b, v);
        update(2*n+1, m+1, r, a, b, v);
        seg[n] = seg[2*n] + seg[2*n+1];
    }
}
int query(int n, int l, int r, int i) {
    lazypropagate(n, l, r);
    if (l == r) {
        return seg[n];
    } else {
        int m = (l+r)/2;
        if (l <= i && i <= m) {
            return query(2*n, l, m, i);
        } else {
            return query(2*n+1, m+1, r, i);
        }
    }
}
vector<int32_t> distribute_candies(vector<int32_t> c, vector<int32_t> l, vector<int32_t> r, vector<int32_t> v) {
    int n = c.size(), q = l.size();
    vector<int32_t> s(n, 0);
    if (n <= 2000 && q <= 2000) {
        for (int i = 0; i < q; i++) {
            for (int j = l[i]; j <= r[i]; j++) {
                s[j] += v[i];
                s[j] = min(s[j], c[j]);
                s[j] = max(s[j], 0);
            }
        }
    } else {
        for (int i = 0; i < q; i++) {
            update(1, 0, n-1, l[i], r[i], v[i]);
        }
        for (int i = 0; i < n; i++) {
            s[i] = min((int)c[i], query(1, 0, n-1, i));
        }
    }
    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 17748 KB Output is correct
2 Correct 179 ms 21616 KB Output is correct
3 Correct 189 ms 21600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 88 ms 10064 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 31 ms 6996 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 180 ms 17748 KB Output is correct
7 Correct 179 ms 21616 KB Output is correct
8 Correct 189 ms 21600 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 88 ms 10064 KB Output isn't correct
11 Halted 0 ms 0 KB -