Submission #807734

# Submission time Handle Problem Language Result Execution time Memory
807734 2023-08-05T00:02:58 Z Mouad_ouj Distributing Candies (IOI21_candies) C++17
0 / 100
190 ms 11376 KB
#include "candies.h"
#include<bits/stdc++.h>
using namespace std;
int tree[40000000]={0},lazy[40000000]={0};
void upd(int p,int l,int r,int a,int b,int n)
{
    if(lazy[p]!=0)
    {
        tree[p]+=(r-l+1)*lazy[p];
        if(l!=r)
        {
            lazy[2*p+1]+=lazy[p];
            lazy[2*p+2]+=lazy[p];
        }
        lazy[p]=0;
    }
    if(l>b || r<a)
    return;
    if(l>=a && r<=b)
    {
        tree[p]+=n*(r-l+1);
        if(l!=r)
        {
            lazy[2*p+1]+=n;
            lazy[2*p+2]+=n;
        }
        return;
    }
    int mid=(l+r)/2;
    upd(2*p+1,l,mid,a,b,n);
    upd(2*p+2,mid+1,r,a,b,n);
    tree[p]=tree[2*p+1]+tree[2*p+2];
}
int get(int p,int l,int r,int cur)
{
    if(cur>r || cur<l)
    return 0;
    if(lazy[p]!=0)
    {
        tree[p]+=(r-l+1)*lazy[p];
        if(l!=r)
        {
            lazy[2*p+1]+=lazy[p];
            lazy[2*p+2]+=lazy[p];
        }
        lazy[p]=0;
    }
    if(cur==l && cur==r)
    return tree[p];
    int mid=(l+r)/2;
    return get(2*p+1,l,mid,cur)+get(2*p+2,mid+1,r,cur);
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v)
{
    vector<int> a;
    a.assign(c.size(),0);
    for(int y=0;y<l.size();y++)
        upd(0,0,c.size(),l[y],r[y],v[y]);
    for(int x=0;x<c.size();x++)
    a[x]=min(get(0,0,c.size(),x),c[x]);
    return a;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int y=0;y<l.size();y++)
      |                 ~^~~~~~~~~
candies.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int x=0;x<c.size();x++)
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 190 ms 11376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -