Submission #588085

# Submission time Handle Problem Language Result Execution time Memory
588085 2022-07-02T17:15:24 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;
    int m=pow(2, 19);
    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 update(int, int, int, int*, int, int, int)':
candies.cpp:16:9: error: redeclaration of 'int m'
   16 |     int m=(l+r)/2;
      |         ^
candies.cpp:8:9: note: 'int m' previously declared here
    8 |     int m=pow(2, 19);
      |         ^
candies.cpp: In function 'void final(int, int, int, int*, std::vector<int>&, std::vector<int>)':
candies.cpp:25:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     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:74:1: warning: control reaches end of non-void function [-Wreturn-type]
   74 | }
      | ^