Submission #436751

# Submission time Handle Problem Language Result Execution time Memory
436751 2021-06-24T20:33:27 Z 5745 Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define vll vector<long long>
#define vi vector<int>
#define ll long long

using namespace std;

vll a, lazy;
ll val;
int lo, hi, poz;
void update(int c, int l, int r) {
    if(l > r) return;
    if(lazy[c] != 0) {
        a[c] += lazy[c];
        if(l != r) {
            lazy[2 * c] += lazy[c];
            lazy[2 * c + 1] += lazy[c];
        }
        lazy[c] = 0;
    }
    if(l > hi or r < lo) return;
    if(lo <= l and r <= hi) {
        a[c] += val;
        if(l != r) {
            lazy[2 * c] += val;
            lazy[2 * c + 1] += val;
        }
        return;
    }
    int m = (l + r) / 2;
    update(2 * c, l, m); update(2 * c + 1, m + 1, r);
    a[c] = a[2 * c] + a[2 * c + 1];
}
int query(int c, int l, int r) {
    if(lazy[c] != 0) {
        a[c] += lazy[c];
        if(l != r) {
            lazy[2 * c] += lazy[c];
            lazy[2 * c + 1] += lazy[c];
        }
        lazy[c] = 0;
    }
    if(l == r)
        return a[c];
    int m = (l + r) / 2;
    if(poz <= m)
        return query(2 * c, l, m);
    else
        return query(2 * c + 1, m + 1, r);
    return 0;
}
vll distribute_candies(vll c, vll l, vll r, vll v) {
    int n = c.size(), m = l.size();
    a = vll(4 * n + 77, 0);
    lazy = vll(4 * n + 77, 0);
    for(int i = 0; i < m; ++i) {
        lo = l[i] + 1, hi = r[i] + 1, val = v[i];
        update(1, 1, n);
    }
    vll ans(n);
    for(int i = 0; i < n; ++i) {
        poz = i + 1;
        val = query(1, 1, n);
        ans[i] = min(c[i], val);
    }
    return ans;
}

Compilation message

/usr/bin/ld: /tmp/cciRMn1U.o: in function `main':
grader.cpp:(.text.startup+0x30e): undefined reference to `distribute_candies(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status