Submission #623578

# Submission time Handle Problem Language Result Execution time Memory
623578 2022-08-06T02:14:00 Z ACGN Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#include "candies.h"
struct st {
    int n;
    vi v;
    st(int x) {
        n=x;
        v.resize(4*n);
    }
    void _add(int i,int l,int r,int tg,int val) {
        v[i]+=val;
        if (r==l+1) return;
        int mid = (l+r)/2;
        if (tg<mid) _add(i*2,l,mid,tg,val);
    }
    void add(int p,int x) {
        _add(1,0,n,p,x);
    }
    int _sum(int i,int cl,int cr,int tl,int tr) {
        if (i==-1) return 0;
        if (cr<=tl) return 0;
        if (tr<=cl) return 0;
        if ((tl<=cl)&&(cr<=tr)) {
            return v[i];
        }
        int mid = (cl+cr)/2;
        return _sum(i*2,cl,mid,tl,tr)+_sum(i*2+1,mid,cr,tl,tr);
    }
    int sum(int k) {
        return _sum(1,0,n,0,k);
    }
};

vi distribute_candies(vi c,vi l,vi r,vi v) {
    int n = c.size();
    st s(n+3);
    for (int i=0;i<l.size();i++) {
        s.add(l[i],v[i]);
        s.add(r[i]+1,-v[i]);
    }
    vi ans;
    for (int i=0;i<n;i++) {
        ans.pb(min(c[i],s.sum(i+1)));
    }
    return ans;
}

Compilation message

candies.cpp: In function 'std::vector<long long int> distribute_candies(std::vector<long long int>, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
candies.cpp:43:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i=0;i<l.size();i++) {
      |                  ~^~~~~~~~~
/usr/bin/ld: /tmp/ccqzV1RW.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