can anyone help me figure out the problem in this code??
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define f(i, j, k) for(ll i = j; i < k; i++)
const int sz = 1e5 + 5;
const int mod = 1e9 + 7;
ll stree[800002];
ll lazy[800002];
ll pw(ll a, ll x)
{
ll ans = 1;
while(x) {
if(x & 1) {
ans = (ans * a) % mod;
}
a = (a * a) % mod;
x = x >> 1;
}
return ans;
}
int n;
ll query(int s, int e, int qs, int qe, int idx)
{
if(lazy[idx] != -1) {
stree[idx] = (pw(2 * lazy[idx], e - s + 1) - (1LL * lazy[idx]) + mod) % mod;
if(s != e) {
lazy[2 * idx] = lazy[idx];
lazy[2 * idx + 1] = lazy[idx];
}
lazy[idx] = -1;
}
if(qs > e || qe < s)
return 0;
if(qs <= s && qe >= e)
return (stree[idx] * pw(2, qe - e)) % mod;
int m = (s + e) / 2;
ll lq = query(s, m, qs, qe, 2 * idx);
ll rq = query(m + 1, e, qs, qe, 2 * idx + 1);
return (lq + rq) % mod;
}
void update(int s, int e, int us, int ue, int val, int idx)
{
if(lazy[idx] != -1) {
stree[idx] = (pw(2 * lazy[idx], e - s + 1) - (1LL * lazy[idx]) + mod) % mod;
if(s != e) {
lazy[2 * idx] = lazy[idx];
lazy[2 * idx + 1] = lazy[idx];
}
lazy[idx] = -1;
}
if(us > e || ue < s)
return;
if(s >= us && e <= ue) {
stree[idx] = (pw(2 * val, e - s + 1) - (1 * val) + mod) % mod;
lazy[2 * idx] = val;
lazy[2 * idx + 1] = val;
return;
}
int m = (s + e) / 2;
update(s, m, us, ue, val, 2 * idx);
update(m + 1, e, us, ue, val, 2 * idx + 1);
stree[idx] = (stree[2 * idx] * pw(2, e - (m + 1) + 1)) % mod;
stree[idx] = (stree[idx] + stree[2 * idx + 1]) % mod;
}
int main()
{
memset(stree, 0, sizeof(stree));
memset(lazy, -1, sizeof(lazy));
cin >> n;
int q;
cin >> q;
f(i, 0, q)
{
int val, l, r;
cin >> val >> l >> r;
if(val == 2) {
cout << query(0, n - 1, l, r, 1) << ā\nā;
} else {
update(0, n - 1, l, r, val, 1);
}
}
}