Submission #1053230

# Submission time Handle Problem Language Result Execution time Memory
1053230 2024-08-11T09:53:32 Z dozer Distributing Candies (IOI21_candies) C++17
3 / 100
5000 ms 25940 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define pb push_back
#define pii pair<int, int>
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define st first
#define nd second
#define ll long long
#define LL node * 2
#define RR node * 2 + 1
#define N 300005
#define LOGN 20

const int modulo = 1e9 + 7;
const ll INF = 2e18 + 7;


ll tree[4 * N], lazy[4 * N], lazy_set[4 * N];
int arr[N];


void push(int node, int l, int r){
    tree[node] += lazy[node];
    if (lazy_set[node] != -1){
        if (l == r){
            if (lazy_set[node] == 1) tree[node] = arr[l];
            else if (lazy_set[node] == 0) tree[node] = 0;
        }
        else{
            lazy_set[LL] = lazy_set[node];
            lazy_set[RR] = lazy_set[node];
        }
    }

    if (l != r){
        lazy[LL] += lazy[node];
        lazy[RR] += lazy[node];
    }
    lazy[node] = 0;
    lazy_set[node] = -1;
}

void build(int node, int l, int r){
    tree[node] = 0;
    lazy[node] = 0;
    lazy_set[node] = -1;
    if (l == r) return;
    int mid = (l + r) / 2;
    build(LL,l, mid);
    build(RR, mid + 1, r);
}

void update1(int node, int l, int r, int sl, int sr, int val){
    push(node, l, r);
    if (l > sr || r < sl) return;
    if (l >= sl && r <= sr){
        lazy[node] += val;
        push(node, l , r);
        return;
    }

    int mid = (l + r) / 2;
    update1(LL, l, mid, sl, sr, val);
    update1(RR, mid + 1, r, sl, sr, val);
}

void update2(int node, int l, int r, int sl, int sr, int val){
    push(node, l, r);
    if (l > sr || r < sl) return;
    if (l >= sl && r <= sr){
        lazy_set[node] = val;
        push(node, l, r);
        return;
    }
    int mid = (l + r) / 2;
    update2(LL, l, mid, sl, sr, val);
    update2(RR, mid + 1, r, sl, sr, val);   
}



ll query(int node, int l, int r, int sl){
    push(node, l, r);
    if (l > r || l > sl || r < sl) return 0;
    if (l == r) {
        return tree[node];
    }
    int mid = (l + r) / 2;
    if (sl <= mid) return query(LL, l, mid, sl);
    return query(RR, mid + 1, r, sl);
}


vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = c.size();
    vector<int> s(n, 0);
    int m = l.size();
    build(1, 0, n - 1);
    for (int i = 0; i < m; i++){
        for (int j = l[i]; j <= r[i]; j++){
            int curr = max(0, min(s[j] + v[i], c[j]));
            s[j] = curr;
        }
    }

    return s;
}
/*

int main() {
    fileio();
    int n;
    assert(1 == scanf("%d", &n));
    std::vector<int> c(n);
    for(int i = 0; i < n; ++i) {
        assert(scanf("%d", &c[i]) == 1);
    }

    int q;
    assert(1 == scanf("%d", &q));
    std::vector<int> l(q), r(q), v(q);
    for(int i = 0; i < q; ++i) {
        assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
    }

    std::vector<int> ans = distribute_candies(c, l, r, v);

    for(int i = 0; i < n; ++i) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", ans[i]);
    }
    printf("\n");
    fclose(stdout);
    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6596 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 4 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5052 ms 25840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 114 ms 11160 KB Output is correct
3 Correct 116 ms 22336 KB Output is correct
4 Execution timed out 5069 ms 25940 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 293 ms 11324 KB Output is correct
4 Correct 327 ms 21312 KB Output is correct
5 Execution timed out 5023 ms 25936 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6596 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 4 ms 6492 KB Output is correct
6 Execution timed out 5052 ms 25840 KB Time limit exceeded
7 Halted 0 ms 0 KB -