Help me debug my code

I have written the following code for the question above…

I couldn’t understand where my code goes wrong kindly please help me in debugging this code

Thanks

#include<bits/stdc++.h>

using namespace std;

#define ll long long int

void lazyupdates(ll a[],ll lazy1[],ll lazy2[],ll l, ll r,ll i)

{

``````if(lazy1[i])

{

a[i] += (lazy1[i]*(r-l+1));

if(l!=r)

{

lazy1[2*i+1] += lazy1[i];

lazy1[2*i+2] += lazy1[i];

}

lazy1[i] = 0;

}

if(lazy2[i])

{

a[i] = (lazy2[i]*(r-l+1));

if(l!=r)

{

lazy2[2*i+1] = lazy2[i];lazy1[2*i+1] = 0;

lazy2[2*i+2] = lazy2[i];lazy1[2*i+2] = 0;

}

lazy2[i] = 0;

}
``````

}

void BuildTree(ll a[],ll l,ll r,ll i=0)

{

``````if(l==r)cin>>a[i];

else

{

ll mid = l+(r-l)/2;

BuildTree(a,l,mid,2*i+1);

BuildTree(a,mid+1,r,2*i+2);

a[i] = a[2*i+1] + a[2*i+2];

}
``````

}

ll getsum(ll a[],ll lazy1[],ll lazy2[],ll ql,ll qr,ll l,ll r,ll i=0)

{

``````lazyupdates(a,lazy1,lazy2,l,r,i);

if(l>qr || r<ql || l>r)return 0;

if(l>=ql && r<=qr)return a[i];

else

{

ll mid=l+(r-l)/2;

return getsum(a,lazy1,lazy2,ql,qr,l,mid,2*i+1)+getsum(a,lazy1,lazy2,ql,qr,mid+1,r,2*i+2);

}
``````

}

void update1(ll a[],ll lazy1[],ll lazy2[],ll ql,ll qr,ll l,ll r,ll x,ll i=0)

{

``````lazyupdates(a,lazy1,lazy2,l,r,i);

if(l>qr || r<ql || l>r)return;

else if(l>=ql && r<=qr)

{

a[i] += ((r-l+1)*x);

if(l!=r)

{

ll mid = l+(r-l)/2;

}

}

else

{

ll mid = l+(r-l)/2;

update1(a,lazy1,lazy2,ql,qr,l,mid,x,2*i+1);

update1(a,lazy1,lazy2,ql,qr,mid+1,r,x,2*i+2);

a[i] = a[2*i+1] + a[2*i+2];

}
``````

}

void update2(ll a[],ll lazy1[],ll lazy2[],ll ql,ll qr,ll l,ll r,ll x,ll i=0)

{

``````lazyupdates(a,lazy1,lazy2,l,r,i);

if(l>qr || r<ql || l>r)return;

else if(l>=ql && r<=qr)

{

a[i] = (r-l+1)*x;

if(l!=r)

{

ll mid = l+(r-l)/2;

lazy2[2*i+1] = lazy2[2*i+2] = x;

lazy1[2*i+1] = lazy1[2*i+2] = 0;

}

}

else

{

ll mid=l+(r-l)/2;

update2(a,lazy1,lazy2,ql,qr,l,mid,x,2*i+1);

update2(a,lazy1,lazy2,ql,qr,mid+1,r,x,2*i+2);

a[i] = a[2*i+1] + a[2*i+2];

}
``````

}

int main()

{

``````ll n,q,k,ql,qr,x;cin>>n>>q;

ll a[4*n]={0},lazy1[4*n]={0},lazy2[4*n]={0};

BuildTree(a,0,n-1);

while(q--)

{

cin>>k>>ql>>qr;ql--;qr--;

if(k==1)

{

cin>>x;

update1(a,lazy1,lazy2,ql,qr,0,n-1,x);

}

else if(k==2)

{

cin>>x;

update2(a,lazy1,lazy2,ql,qr,0,n-1,x);

}

else cout<<getsum(a,lazy1,lazy2,ql,qr,0,n-1)<<"\n";

}
``````

}