답안 #834648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834648 2023-08-22T16:28:19 Z Mohmad_Zaid 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include "candies.h"
#include <vector>
#define ll long long
using namespace std;
struct segtree{
    int size=1;
    vector<ll>arr;
    void init(int n){
        while(size<n)size*=2;
        arr.assign(2*size,0LL);
    }
    void update(int l,int r,int x,int lx,int rx,int v){
        if(lx>=r || rx<=l)return;
        if(lx>=l && rx<=r){
            arr[x]+=v;
            return;
        }
        int mid=(lx+rx)/2;
        update(l,r,2*x+1,lx,mid,v);
        update(l,r,2*x+2,mid,rx,v);
    }
    void update(int l,int r,int v){
        update(l,r,0,0,size,v);
    }
    void get_ans(int i,int x,int lx,int rx,ll& ans){
        if(lx>i || rx<=i)return;
        if(rx-lx==1){
            if(lx==i)ans+=arr[x];
            return;
        }
        if(lx<=i && rx>i){
            ans+=arr[x];
        }
        int mid=(lx+rx)/2;
        if(i<mid)get_ans(i,2*x+1,lx,mid,ans);
        else get_ans(i,2*x+2,mid,rx,ans);
    }
    void get_ans(int i,ll& ans){
        get_ans(i,0,0,size,ans);
    }
};
vector<ll> distribute_candies(vector<ll> c, vector<ll> l,vector<ll> r, vector<ll> v) {
    int n = c.size();
    int q=l.size();
    vector<ll> s(n);
    segtree st;
    st.init(n);
    for(int i=0;i<q;i++){
        st.update(l[i],r[i]+1,v[i]);
    }
    for(int i=0;i<n;i++){
        ll val=0;
        st.get_ans(i,val);
        s[i]=min(c[i],val);
    }
    return s;
}

Compilation message

/usr/bin/ld: /tmp/cc70vaSY.o: in function `main':
grader.cpp:(.text.startup+0x30e): undefined reference to `distribute_candies(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status