TEMA

Wrong answer (100%) !!!

Wellington Ribeiro preguntado 2 years ago


int N;
int *vet;

void atualiza(int, int);
int soma(int x);
void casoespecial(int , int , int , int, int );

int main()
{
    int n, m, x,y,a,b,c,d,local,tam=4,aux;
    int acum=0;
    int v[tam];

    cin>>n>>m;
    n++;
    vet = new int[n];

    N=n;

    for(int i=1;i<n;i++)
    {
            vet[i]=0;
    }

    for(int i=0;i<m;i++)
    {

        cin>>n;

        if(n==1)
        {
            cin>>x>>y;

            local=x;

            atualiza(local,y);

        }
        else if(n==2)
        {
            cin>>a>>b>>c>>d;

            if(a==b and c==d)
            {

                if(c==b)
                {   
                    cout<<soma(b)-soma(a-1)<<endl;
                }
                else
                {
                    cout<<(soma(b)-soma(a-1))+(soma(d)-soma(c-1))<<endl;

                }
            }
            else
            {   

                if(c<a and b>=d)
                {

                    if(d>=a)
                    cout<<soma(b)-soma(c-1)<<endl;
                    else
                    casoespecial(a,  b,  c, d, tam);

                }
                else if(c<a and d>b)
                {
                    cout<<soma(d)-soma(c-1)<<endl;
                }
                else if(a<c and b>d)
                {
                    cout<<soma(b)-soma(a-1)<<endl;

                }
                else if(a<=c and d>=b)
                {

                    if(b>=c)
                    cout<<soma(d)-soma(a-1)<<endl;
                    else
                    casoespecial(a,  b,  c, d, tam);

                }

            }           

        }

    }

    return 0;
}
void atualiza(int local, int v){

    while(local <= N){ 

        vet[local] += v;
        local += (local & -local);  

    }

}
int soma(int local){

    int s = 0;

    while(local > 0){ 

        s += vet[local];

        local -= (local & -local); 

    }

    return s;
}
void casoespecial(int a, int b, int c, int d,int tam)
{
    int v[4];

    v[0]=a;
    v[1]=b;
    v[2]=c;
    v[3]=d;

    sort(v,v+tam+1);

    a=v[0];
    b=v[1];
    c=v[2];
    d=v[3];

    cout<<(soma(b)-soma(a-1))+(soma(d)-soma(c-1))<<endl;
}

Recuerda no enviar soluciones. Tu mensaje puede ser revisado por nuestros moderadores.

  • Wellington Ribeiro respondido 2 years ago

    Por conto do tamanho retirei os includes das bibliotcas