Submission #446439

# Submission time Handle Problem Language Result Execution time Memory
446439 2021-07-21T23:23:33 Z luciocf Distributing Candies (IOI21_candies) C++17
3 / 100
141 ms 9180 KB
#include <bits/stdc++.h>
#include "candies.h"

using namespace std;

typedef long long ll;

const int maxn = 2e5+10;

struct FenwickTree
{
    ll bit[maxn];

    void upd(int x, ll v)
    {
        for (; x < maxn; x += (x&-x))
            bit[x] += v;
    }

    ll soma(int x)
    {
        ll ans = 0;
        for (; x > 0; x -= (x&-x))
            ans += bit[x];
        return ans;
    }

    ll get(int l, int r)
    {
        return soma(r)-soma(l-1);
    }
} BIT;

ll value(ll v, ll add, int C)
{
    if (add + v > 1ll*C) return C;
    if (add + v < 0) return 0;
    return add+v;
}

int a[maxn];

vector<int> distribute_candies(vector<int> c, vector<int> L, vector<int> R, vector<int> V)
{
    int n = c.size(), q = L.size();

    if (max(n, q) <= 2000)
    {
        for (int i = 0; i < q; i++)
        {
            for (int j = L[i]; j <= R[i]; j++)
                a[j] = value(a[j], V[i], c[j]);
        }

        vector<int> ans;

        for (int i = 0; i < n; i++)
            ans.push_back(a[i]);
        return ans;
    }

    for (int i = 0; i < q; i++)
    {
        BIT.upd(L[i]+1, V[i]);
        BIT.upd(R[i]+2, -V[i]);
    }

    vector<int> ans;

    for (int i = 1; i <= n; i++)
    {
        if (BIT.soma(i) >= c[i]) ans.push_back(c[i]);
        else ans.push_back(BIT.soma(i));
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 5 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 141 ms 9180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 74 ms 4964 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 71 ms 4956 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 5 ms 368 KB Output is correct
6 Incorrect 141 ms 9180 KB Output isn't correct
7 Halted 0 ms 0 KB -