#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii; 
#define ll long long
#define ar array
const ll mxN=3e5;
const int mod=1e9+7;
const ll INF=1e18;
#define what_is(x) cerr << #x << " is " << x << endl;
ll a,b,c,n,k,m,x,y,h,l,r,t;


void solve(){
	cin>>n;
	
	cin>>c;
	vector<ar<ll,3>> a(n);
	set<ll> st;
	map<ll,ll> mp;
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
		a[i][1]++;
		st.insert(a[i][0]);
		st.insert(a[i][1]);
		
	}
	for(int i=0;i<n;i++){
				mp[a[i][0]]+=a[i][2];
		mp[a[i][1]]-=a[i][2];
	}

	vector<ll>events;
	for(auto itr=st.begin(); itr!=st.end();itr++){
		events.push_back(*itr);
	}
	ll cur_cost=0;	ll ans=0;
	for(int i=0;i<(int)events.size()-1;i++){
		cur_cost+=mp[events[i]];
		ans+=min(cur_cost,c)*(events[i+1]-events[i]);
	}

	cout<<ans<<endl;
}


signed main() {
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    cout<<setprecision(12)<<fixed;
    // cin>>t;
    // while(t--)
    	solve();
	return 0;
   
}
 
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n)-1;i >= 0;i--)
#define repr(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

struct SegmentTree {
private:
    int n;
    vector<ll> node;

public:
    SegmentTree(vector<int> v) {
    int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[2*i+1] ^ node[2*i+2];
    }

    void update(int x , int v) {
      x += (n - 1);
      node[x] = v;
      while(x > 0) {
          x = (x - 1) / 2;
          node[x] = node[2*x+1] ^ node[2*x+2];
      }
    }

    //includes a and b
    ll get(int a, int b, int k=0, int l=0, int r=-1) {
      if(r < 0) r = n;

      if(r-1 < a || b < l) return 0;

      if(a <= l && r-1 <= b) return node[k];

      ll vl = get(a, b, 2*k+1, l, (l+r)/2);
      ll vr = get(a, b, 2*k+2, (l+r)/2, r);
      return vl ^ vr;
    }
};

ll mod = 1e9 + 7;

ll gcd(ll a, ll b){
    if (a%b == 0)return(b);
    else return(gcd(b, a%b));
}

ll inv(ll x){
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while(k){
        if(k&1)res = (res*y)%mod;
        y = (y*y) % mod;
        k /= 2;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,q;
    cin >> n >> q;
    vi a(n);
    rep(i,n) cin >> a[i];
    SegmentTree st(a);

    rep(i,q) {
        int t,x,y;
        cin >> t >> x >> y;
        x--;
        if (t == 1) {
            a[x] = a[x] ^ y;
            st.update(x, a[x]);
        } else {
            y--;
            cout << st.get(x, y) << endl;
        }
    }
}
