답안 #836560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836560 2023-08-24T12:57:31 Z FulopMate 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include "candies.h"

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int n, q;
int m;
vector<ll> st;

void push(int ind){
    st[ind*2] += st[ind];
    st[ind*2+1] += st[ind];
    st[ind] = 0;
}

void update(int l, int r, int d, int cl = 0, int cr = m-1, int ind = 1){
    if(l <= cl && cr <= r){
        st[ind] += d;
        return;
    }
    if(r < cl || cr < l)return;
    push(ind);
    int md = (cl+cr)/2;
    update(l, r, d, cl, md, ind*2);
    update(l, r, d, md+1, cr, ind*2+1);
}

void pushall(int ind = 1){
    if(ind < m){
        push(ind);
        pushall(ind*2);
        pushall(ind*2+1);
    }
}

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {

    n = c.size(), q = l.size();
    m = (1<<int(ceil(log2(n))));
    st.assign(m*2, 0);

    for(int i = 0; i < q; i++){
        update(l[i], r[i], v[i]);
    }

    pushall();

    vector<int> s(n);
    for(int i = 0; i < n; i++){
        s[i] = min((ll)c[i], st[i+m]);
    }


    return s;
}


int main() {
    int n;
    assert(1 == scanf("%d", &n));
    std::vector<int> c(n);
    for(int i = 0; i < n; ++i) {
        assert(scanf("%d", &c[i]) == 1);
    }

    int q;
    assert(1 == scanf("%d", &q));
    std::vector<int> l(q), r(q), v(q);
    for(int i = 0; i < q; ++i) {
        assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
    }

    std::vector<int> ans = distribute_candies(c, l, r, v);

    for(int i = 0; i < n; ++i) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", ans[i]);
    }
    printf("\n");
    fclose(stdout);
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccGbgal4.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cch39Zb1.o:candies.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status