コード例 #1
0
ファイル: lul.cpp プロジェクト: diego9627/random-code
// Prereq : *t is initialized
void operar(tree **t,lli l,lli r,lli a,lli b){
  if((*t)->d <= l || r<=(*t)->i) return;
  if(l <= (*t)->i && (*t)->d <=r){
    addDiffs(t,a,b);
    return;
  }
  makeSons(t);
  push_down(t);
  operar(&((*t)->l),l,r,a,b);
  operar(&((*t)->r),l,r,a,b);
  (*t)->sa = (realA((*t)->l) + realA((*t)->r))%MOD;
  (*t)->sb = (realB((*t)->l) + realB((*t)->r))%MOD;
  (*t)->sc = (realC((*t)->l) + realC((*t)->r))%MOD;
}
コード例 #2
0
ファイル: nodo.cpp プロジェクト: margarcuae/arbolito
double Nodo::resolver(double x,double y){
    if (this->is_variableX){
        //cout << "variab"<<endl;
        return x;
    }
    if(this->is_variableY){
        return y;
    }
    if (this->is_valor){
        //cout << "valor"<<endl;
        return this->valor;
    }

    if(this->is_unario){
        return operar(hijo1->resolver(x,y),0);
    }
    else{
        return operar(hijo1->resolver(x,y),hijo2->resolver(x,y));
    }
}
コード例 #3
0
ファイル: lul.cpp プロジェクト: diego9627/random-code
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  lli N,Q,o,l,r,k;
  cin >> N >> Q;
  tree *root;
  root = NULL;
  initTree(&root,0,N);
  for(lli i = 0 ; i < Q ; i++) {
    cin >> o;
    if( o == 1 ){
      cin >> l >> r >> k;
      operar(&root,l-1,r,k,0);
    }
    else if( o == 2 ){
コード例 #4
0
void ejecutar(pila_tipo_dato *pilaPos, char *res ){
     pila_tipo_dato  auxresult;
     pila_init(&auxresult);
     int error=0;
     char elemento[TAM_RES],result1[TAM_RES],result2[TAM_RES],resultOp[TAM_RES];

     while(pilaPos->cant_element!=0)
     {
        //ceramos los vectores
        init_array(result1,TAM_RES);
        init_array(result2,TAM_RES);
        init_array(elemento,TAM_RES);
        init_array(resultOp,TAM_RES);

        pila_desapilar(pilaPos,elemento);

        //vemos si es operador
        if (esOperador(elemento)==1)
        {

            if ((auxresult.cant_element)<2){
               res[0]=elemento[0];
               strcat(res,"Error!!");
               pilaPos->cant_element=0;
               error=1;

               //ocurrio un error
               }
          pila_desapilar(&auxresult,result1);
          pila_desapilar(&auxresult,result2);
          operar(result1, result2,elemento[0],resultOp);
          pila_apilar(&auxresult,resultOp);
          if(error==0){pila_getfrente(&auxresult,res);}

        }
        else{
           pila_apilar(&auxresult,elemento);

        }
    }
}