#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

const int N = 2e5 + 20;
typedef long long LL;
typedef pair<LL, LL> PLL;

int n, m, q;
struct Node
{
	int l, r;
	LL sum, cnt;
}tra[N << 2], trb[N << 2];
int a[N], b[N];
int t[N], x[N], y[N];
vector<int> nums;

void push_up(Node tr[], int u)
{
	tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
	tr[u].cnt = tr[u << 1].cnt + tr[u << 1 | 1].cnt;
}

void build(Node tr[], int u, int l, int r)
{
	tr[u] = {l, r, 0, 0};
	if(l == r) return;
	int mid = l + r >> 1;
	build(tr, u << 1, l, mid);
	build(tr, u << 1 | 1, mid + 1, r);
}

void modify(Node tr[], int u, int x, int d)
{
	if(tr[u].l == x && tr[u].r == x)
	{
		tr[u].cnt += d;
		tr[u].sum += nums[x] * d;
		return;
	}
	int mid = tr[u].l + tr[u].r >> 1;
	if(x <= mid) modify(tr, u << 1, x, d);
	else modify(tr, u << 1 | 1, x, d);
	push_up(tr, u);
}

PLL query(Node tr[], int u, int l, int r)
{
	if(tr[u].l >= l && tr[u].r <= r)
	{
		return {tr[u].cnt, tr[u].sum};
	}
	int mid = tr[u].l + tr[u].r >> 1;
	PLL res = {0, 0}, right = {0, 0}, left = {0, 0};
	if(l <= mid) left = query(tr, u << 1, l, r);
	if(r > mid) right = query(tr, u << 1 | 1, l, r);
	res.first = left.first + right.first;
	res.second = left.second + right.second;
	return res;
}

int find(int x)
{
	return lower_bound(nums.begin(), nums.end(), x) - nums.begin();
}

int main()
{
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= q; ++ i)
	{
		scanf("%d%d%d", &t[i], &x[i], &y[i]);
		nums.push_back(y[i]);
	}
	
	nums.push_back(0);
	sort(nums.begin(), nums.end());
	nums.erase(unique(nums.begin(), nums.end()), nums.end());
	
	LL res = 0;
	build(tra, 1, 0, nums.size() - 1);
	build(trb, 1, 0, nums.size() - 1);
	
	for(int i = 1; i <= q; ++ i)
	{
		if(t[i] == 1)
		{
			auto p = query(trb, 1, find(a[x[i]]) + 1, nums.size() - 1);
			modify(tra, 1, find(a[x[i]]), -1);
			res -= p.second + (m - p.first) * a[x[i]];
			a[x[i]] = y[i];
			modify(tra, 1, find(a[x[i]]), 1);
			p = query(trb, 1, find(a[x[i]]) + 1, nums.size() - 1);
			res += p.second + (m - p.first) * a[x[i]];	
		}
		else
		{
			auto p = query(tra, 1, find(b[x[i]]) + 1, nums.size() - 1);
			modify(trb, 1, find(b[x[i]]), -1);
			res -= p.second + (n - p.first) * b[x[i]];
			b[x[i]] = y[i];
			modify(trb, 1, find(b[x[i]]), 1);
			p = query(tra, 1, find(b[x[i]]) + 1, nums.size() - 1);
			res += p.second + (n - p.first) * b[x[i]];
		}
		printf("%lld\n", res);
	}
	return 0;	
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;
#define T pair<pair<ll, ll>, bool>


int main()
{
    ll n, c;
    scanf("%lld%lld", &n, &c);
    priority_queue<T, vector<T>, greater<T>> pq;
    for (ll i = 0; i < n; i++)
    {
        ll a, b, c;
        scanf("%lld%lld%lld", &a, &b, &c);
        pq.push({ {a, c}, 1 });
        pq.push({ {b + 1, c}, 0 });
    }
    ll sum = 0;
    ll cur = 0;
    while (!pq.empty())
    {
        ll day = pq.top().first.first;
        while (!pq.empty() && pq.top().first.first == day)
        {
            ll num = pq.top().first.second;
            bool type = pq.top().second;
            if (type) cur += num;
            else cur -= num;
            pq.pop();
        }
        if (pq.empty()) break;
        ll nxt = pq.top().first.first;
        sum += min(cur, c) * (nxt - day);
    }
    printf("%lld", sum);
    return 0;
}