#include "happy.h"
std::vector <long long int> happy (int N, int Q, std::vector <int> u, std::vector <int> v, std::vector <int> h, std::vector <int> t, std::vector <int> l, std::vector <int> r) {
   std::vector <long long >ans;
   ans.resize(Q);
   std::vector<bool> restor;
   for(long long a=0;a<N;a++){
    restor[a] = false;
   }
   for(long long a=0;a<Q;a++){
        ans[a] = 0;
        if(t[a]==1){
            for(long long x=l[a];x<=r[a];x++){
                restor[x] = true;
            }
        }
        if(t[a]==2){
            for(long long x=l[a];x<=r[a];x++){
                restor[x] = false;
            }
        }
        for(long long b=0;b<N;b++){
            for(long long c=b+1;c++){
                if(!restor[b]){
                        break;
                }
                if(restor[b]&&restor[c]){
                        for(long long inx = 0;inx<N-1;inx++){
                            if(restor[b]==u[inx]&&restor[c]==v[inx]){
                                ans[a]+=h[inx];
                            }
                            else{
                                
                            }
                        }
                    //ako ima put mejdu tqh
                    //ako nqma - xor ot putishtata
                }
            }
        }
   }
    return ans;
}
