Submission #588086

# Submission time Handle Problem Language Result Execution time Memory
588086 2022-07-02T17:16:15 Z sofijavelkovska Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

void update(int x, int l, int r, int segmenttree[], int ls, int rs, int vs)
{
    if (l>rs || r<ls)
        return;
    if (l>=ls && r<=rs)
    {
        segmenttree[x]=segmenttree[x]+vs;
        return;
    }
    if (r-l==1)
        return;
    int m=(l+r)/2;
    update(2*x+1, l, m, segmenttree, ls, rs, vs);
    update(2*x+2, m, r, segmenttree, ls, rs, vs);

    return;
}

void final(int x, int l, int r, int segmenttree[], vector<int> &s, vector<int> c)
{
    if (r>s.size())
        return;
    for (int i=l; i<r; i++)
        s[i]=min(s[i]+segmenttree[x], c[i]);
    if (r-l==1)
        return;
    int m=(l+r)/2;
    final(2*x+1, l, m, segmenttree, s, c);
    final(2*x+2, m, r, segmenttree, s, c);

    return;
}

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v)
{
    int n=c.size();
    int q=l.size();
    if (n<=2000 && q<=2000)
    {
        vector<int> s(n);
        for (int i=0; i<n; i++)
            s[i]=0;
        for (int i=0; i<q; i++)
        {
            if (v[i]>0)
                for (int j=l[i]; j<=r[i]; j++)
                    s[j]=min(s[j]+v[i], c[j]);
            else
                for (int j=l[i]; j<=r[i]; j++)
                    s[j]=max(s[j]+v[i], 0);
        }
        return s;
    }
    int t=0;
    for (auto x : v)
        if (x>0)
            t=t+1;
    if (t==q)
    {
        int m=pow(2, 19);
        int segmenttree[m]={0};
        for (int i=0; i<q; i++)
            update(0, 0, n, segmenttree, l[i], r[i]+1, v[i]);
        vector<int> s(n);
        for (int i=0; i<n; i++)
            s[i]=0;
        //final(0, 0, n, segmenttree, s, c);
        return s;
    }
}

int main()
{
    int n=3000, q=3000;
    vector<int> c(n);
    for (int i=0; i<n; i++)
        c[i]=100;
    vector<int> l(q), r(q), v(q);
    for (int i=0; i<q; i++)
    {
        l[i]=0;
        r[i]=n-1;
        v[i]=1;
    }
    vector<int> s=distribute_candies(c, l, r, v);

    return 0;
}

Compilation message

candies.cpp: In function 'void final(int, int, int, int*, std::vector<int>&, std::vector<int>)':
candies.cpp:24:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     if (r>s.size())
      |         ~^~~~~~~~~
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:73:1: warning: control reaches end of non-void function [-Wreturn-type]
   73 | }
      | ^
/usr/bin/ld: /tmp/cckbVC70.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccHAeEhY.o:candies.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status