제출 #446439

#제출 시각아이디문제언어결과실행 시간메모리
446439luciocf사탕 분배 (IOI21_candies)C++17
3 / 100
141 ms9180 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...