For this Question: You are given a binary array A of size N. Now, an array P is calculated from A such that:
P[i] = A[i] + P[i-1]
(for 1 <= i <= N and P[0] = 0)
Now, you have to handle two types of queries:
1 L R - invert every element of A from L to R (If A[i] = 0, change it to 1 and vice versa)
2 L R - print the sum of array P from L to R
The array P is updated after every query of type 1.The first line contains two integers N and Q denoting the number of elements of the array and the number of queries respectively. The next line contains N boolean values representing the element of array A. The next Q lines contain three integers T L R denoting the queries.

1 <= N, Q <= 200000
0 <= A[i] <= 1
1 <= T <= 2
1 <= L <= R <= NFor every query of type 2, print a single integer denoting the sum of range from L to R in a separate line. Since the sum can be quite large, print sum modulo (10^9 + 7)Sample Input:
9 6
1 0 0 1 1 0 0 0 1
1 2 6
1 4 8
2 1 9
2 3 5
1 2 7
2 5 8

Sample Output:
41
12
8

Explanation:
Array P initially: [1, 1, 1, 2, 3, 3, 3, 3, 4]
After 1st query:
A: [1, 1, 1, 0, 0, 1, 0, 0, 1]
P: [1, 2, 3, 3, 3, 4, 4, 4, 5]
After 2nd query:
A: [1, 1, 1, 1, 1, 0, 1, 1, 1]
P: [1, 2, 3, 4, 5, 5, 6, 7, 8], I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int n, q;
bool a[N], lz[4*N];
int sum[4*N][2], sumi[4*N][2];

void merge(int nd){
    for(int i = 0; i < 2; i++){
        sum[nd][i] = sum[nd << 1][i] + sum[nd << 1 | 1][i];
        sumi[nd][i] = sumi[nd << 1][i] + sumi[nd << 1 | 1][i];
    }
}

void modify(int nd){
    swap(sum[nd][0], sum[nd][1]);
    swap(sumi[nd][0], sumi[nd][1]);
}

void pushdown(int nd, int s, int e){
    if(lz[nd] == 0) return;
    modify(nd);
    if(s != e){
        lz[nd << 1] ^= lz[nd];
        lz[nd << 1 | 1] ^= lz[nd];
    }
    lz[nd] = 0;
}

void build(int nd, int s, int e){
    if(s == e){
        sum[nd][a[s]] = n-s+1;
        sumi[nd][a[s]]++;
        return;
    }
    int md = (s + e) >> 1;
    build(nd << 1, s, md);
    build(nd << 1 | 1, md+1, e);
    merge(nd);
}

void upd(int nd, int s, int e, int l, int r){
    pushdown(nd, s, e);
    if(s > e || s > r || e < l)
        return;
    if(s >= l && e <= r){
        modify(nd);
        if(s != e){
            lz[nd << 1] ^= 1;
            lz[nd << 1 | 1] ^= 1;
        }
        return;
    }
    int md = (s + e) >> 1;
    upd(nd << 1, s, md, l, r);
    upd(nd << 1 | 1, md+1, e, l, r);
    merge(nd);
}

pi query(int nd, int s, int e, int l, int r){
    pushdown(nd, s, e);
    if(s > e || s > r || e < l)
        return {0, 0};
    if(s >= l && e <= r)
        return {sum[nd][0], sumi[nd][0]};
    int md = (s + e) >> 1;
    pi p = query(nd << 1, s, md, l, r);
    pi q = query(nd << 1 | 1, md+1, e, l, r);
    return {p.fi+q.fi, p.se+q.se};
}

void solve(){
    cin >> n >> q;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    build(1, 1, n);
    while(q--){
        int t, l, r;
        cin >> t >> l >> r;
        if(t == 1)
            upd(1, 1, n, l, r);
        else{
            pi x = query(1, 1, n, l, r);
            pi y = query(1, 1, n, 1, l-1);
            int ans = r*(r+1)/2 - (l-1)*l/2;
            ans = ans - (x.fi - x.se*(n-r)) - y.se*(r-l+1);
            cout << ans % mod << endl;
        }
    }
}

void testcases(){
    int tt = 1; 
    //cin >> tt;
    while(tt--){
        solve();
    }
}

signed main() {
    IOS;
        clock_t start = clock();

    testcases();

    cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}   , In this Programming Language: C++, Now tell me if this Code is compilable or not?