답안 #446439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446439 2021-07-21T23:23:33 Z luciocf 사탕 분배 (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;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Incorrect 141 ms 9180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -