답안 #436753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436753 2021-06-24T20:34:52 Z 5745 사탕 분배 (IOI21_candies) C++17
0 / 100
384 ms 19804 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;
}
vi distribute_candies(vi c, vi l, vi r, vi 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);
    }
    vi ans(n);
    for(int i = 0; i < n; ++i) {
        poz = i + 1;
        val = query(1, 1, n);
        ans[i] = min(1LL*c[i], val);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 384 ms 19804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -