#include<cstdio>
typedef long long ll;
struct SegmentTree {
    int num,rt;
    ll size[2000005],sum[2000005];
    int lson[2000005],rson[2000005];
    SegmentTree() {num=0; rt=0;}
    inline void _change(int &p,int l,int r,int x,int d) {
        if(!p) p=++num;
        size[p]+=d; sum[p]+=x*1ll*d;
        if(l==r) return;
        int mid=l+r>>1;
        if(x<=mid) _change(lson[p],l,mid,x,d);
        else _change(rson[p],mid+1,r,x,d);
    }
    inline void change(int x,int d) {_change(rt,1,100000000,x,d);}
    inline ll _ask(int p,int l,int r,int L,int R,ll *arr) {
        if(L<=l&&r<=R) return arr[p];
        int mid=l+r>>1; ll res=0;
        if(L<=mid&&lson[p]) res+=_ask(lson[p],l,mid,L,R,arr);
        if(R>mid&&rson[p]) res+=_ask(rson[p],mid+1,r,L,R,arr);
        return res;
    }
    inline ll ask(int L,int R,int op) {return op==1? _ask(rt,1,100000000,L,R,size):_ask(rt,1,100000000,L,R,sum);}
}t[2];
int a[200005][2];
inline int read() {
    register int x=0,f=1;register char s=getchar();
    while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();}
    while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
    return x*f;
}
int main() {
    int n=read(),m=read(),Q=read(); ll ans=0;
    t[0].change(0,n); t[1].change(0,m);
    while(Q--) {
        int op=read()-1,x=read(),val=read();
        t[op].change(a[x][op],-1);
        ans-=t[op^1].ask(1,a[x][op],1)*a[x][op]+t[op^1].ask(a[x][op]+1,1e8,2);
        t[op].change(val,1);
        ans+=t[op^1].ask(1,val,1)*val+t[op^1].ask(val+1,1e8,2);
        a[x][op]=val;
        printf("%lld\n",ans);
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

long N, C, x, y, c, cur, pr1, pr2, total;
vector<pair<long, long>> a;

bool sortbc(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
	if (a.first == b.first)
    	return (a.second > b.second); 
    return a.first < b.first;
} 

int main() {
	cin>>N>>C;
	for(int i=0; i<N; i++) {
		cin>>x>>y>>c;
		a.push_back(make_pair(x, c));
		a.push_back(make_pair(y, -1*c));
	}
	sort(a.begin(), a.end(), sortbc);
	
	int i = 0;
	while( i < 2*N ) {
		int day = a[i].first;
		int both = 0;
		while(a[i].first == day && a[i].second > 0) {
			cur += a[i].second;
			i++;
		}
		if( a[i].first == day ) {
			total += min(C, cur);
			both = 1;
		}
		while( a[i].first == day && a[i].second < 0 ) {
			cur += a[i].second;		
			i++;
		}
		total += (a[i].first - day - both) * min(C, cur);
	}
	cout<<total;
}