#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
using ll = long long;
int n, m, q, t[N], x[N], y[N], dic[N], L;
int a[N], b[N];
ll d[4][N];
void add(int idx, int x, int v) {
    for(int i = x; i <= L; i += i & -i) d[idx][i] += v;
}
ll get(int idx, int x) {
    ll res = 0;
    for(int i = x; i; i -= i & -i) res += d[idx][i];
    return res;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> q;
    for(int i = 1; i <= q; i++) {
        cin >> t[i] >> x[i] >> y[i];
        dic[i] = y[i];
    }
    dic[q + 1] = 0;
    sort(dic + 1, dic + q + 2);
    L = unique(dic + 1, dic + q + 2) - dic - 1;
    add(0, 1, n);
    add(2, 1, m);
    // for(int j = 0; j < 4; j++) {
    //     for(int i = 1; i <= L; i++) cout << get(j, i) - get(j, i - 1) << " ";
    //     cout << endl;
    // }
    // cout << endl;
    ll ans = 0;
    for(int i = 1; i <= q; i++) {
        int np = lower_bound(dic + 1, dic + L + 1, y[i]) - dic;
        // cout << t[i] << " " << x[i] << " " << y[i] << " " << np << endl;
        if(t[i] == 1) {
            int p = lower_bound(dic + 1, dic + L + 1, a[x[i]]) - dic; 
            // for(int i = 1; i <= L; i++) cout << get(2, i) << endl;
            // cout << np << " " << p << endl;
            ans += get(2, np) * y[i] -  get(2, p) * a[x[i]];
            ans -= get(3, np) - get(3, p);
            add(0, p, -1);
            add(0, np, 1);
            add(1, p, -a[x[i]]);
            add(1, np, y[i]);
            a[x[i]] = y[i];
        } else {
            int p = lower_bound(dic + 1, dic + L + 1, b[x[i]]) - dic;
            ans += get(0, np - 1) * y[i] - get(0, p - 1) * b[x[i]];
            ans -= get(1, np - 1) - get(1, p - 1);
            // cout << get(0, np - 1) * y[i] - get(0, p - 1) * b[x[i]] << " " << get(1, np - 1) - get(1, p - 1) << endl;
            add(2, p, -1);
            add(2, np, 1);
            add(3, p, -b[x[i]]);
            add(3, np, y[i]);
            b[x[i]] = y[i];
        }
        cout << ans << endl;
        // for(int j = 0; j < 4; j++) {
        //     for(int i = 1; i <= L; i++) cout << get(j, i) - get(j, i - 1) << " ";
        //     cout << endl;
        // }
        // cout << endl;
    }
    return 0;
}
#include <bits/stdc++.h>
#include <algorithm>
#define max(p, q) ((p)>(q)?(p):(q))
#define min(p, q) ((p)<(q)?(p):(q))
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define INF LLONG_MAX;
#define MOD 1000000007
using ll = long long;
using ld = long double;
using namespace std;

int main()
{
    ll N, C;
    cin >> N >> C;
    vector<pair<ll, ll>> event;
    for (ll i = 0; i < N; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        event.emplace_back(a - 1, c);
        event.emplace_back(b, -c);
    }
    sort(event.begin(), event.end());
    ll ans = 0, fee = 0, t = 0;
    for (auto [x, y] : event)
    {
        if (x != t)
        {
            ans += min(C, fee) * (x - t);
            t = x;
        }
        fee += y;
    }
    cout << ans << endl;
    return 0;
}
