#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vui = vector<ui>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
template <typename T>
using vv = vector<vector<T>>;
template <typename T>
using vvv = vector<vector<vector<T>>>;

struct BIT
{
	vector<ll> Data;
	int N;
	ll Init;

	BIT(int n, ll init = 0)
	{
		N = n;
		Data.resize(N + 1, init);
		Init = init;
	}

	void add(int i, ll v)
	{
		while (i <= N)
		{
			Data[i] += v;
			i += i & -i;
		}
	}

	ll getSum(int i)
	{
		auto sum = 0ll;
		while (i > 0)
		{
			sum += Data[i];
			i -= i & -i;
		}
		return sum;
	}
};

ll calc(int X, int Y, vi& a, vi& b, vi& listA, vi& listB, BIT& cntA, BIT& cntB, BIT& sumA, BIT& sumB)
{
	auto ret = 0ll;
	auto oldB = lower_bound(listB.begin(), listB.end(), a[X]) - listB.begin();
	auto newB = lower_bound(listB.begin(), listB.end(), Y) - listB.begin();
	ret -= cntB.getSum(oldB) * a[X];
	ret += cntB.getSum(newB) * Y;
	ret -= sumB.getSum(newB);
	ret += sumB.getSum(oldB);

	auto oldA = lower_bound(listA.begin(), listA.end(), a[X]) - listA.begin();
	auto newA = lower_bound(listA.begin(), listA.end(), Y) - listA.begin();
	cntA.add(oldA + 1 , -1);
	cntA.add(newA + 1, 1);
	sumA.add(oldA + 1, -a[X]);
	sumA.add(newA + 1, Y);
	a[X] = Y;
	return ret;
}

int main()
{
	int N, M, Q;
	cin >> N >> M >> Q;

	set<int> sA;
	set<int> sB;
	struct query
	{
		int T;
		int X;
		int Y;
	};
	vector<query> q(Q);
	for (auto i = 0; i < Q; ++i)
	{
		cin >> q[i].T >> q[i].X >> q[i].Y;
		--q[i].X;
		if (q[i].T == 1)
		{
			sA.insert(q[i].Y);
		}
		else
		{
			sB.insert(q[i].Y);
		}
	}
	sA.insert(0);
	sB.insert(0);
	vi listA(sA.begin(), sA.end());
	vi listB(sB.begin(), sB.end());

	auto numA = (int)listA.size();
	auto numB = (int)listB.size();
	BIT cntA(numA);
	BIT cntB(numB);
	BIT sumA(numA);
	BIT sumB(numB);
	cntA.add(1, N);
	cntB.add(1, M);

	vi a(N);
	vi b(M);
	auto ans = 0ll;

	for (auto i = 0; i < Q; ++i)
	{
		if (q[i].T == 1)
		{
			ans += calc(q[i].X, q[i].Y, a, b, listA, listB, cntA, cntB, sumA, sumB);
		}
		else
		{
			ans += calc(q[i].X, q[i].Y, b, a, listB, listA, cntB, cntA, sumB, sumA);
		}
		cout << ans << endl;
	}

	return 0;
}
#include <bits/stdc++.h>

using namespace std;

#define ull unsigned long long
#define ll long long
#define ui unsigned int
#define us unsigned short
#define inf_int 1e9
#define inf_ll 1e18
#define mod 1000000007
#define smod 998244353

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	
	int n;
	cin >> n;
	
	vector<pair<double, int>> v;
	for(int x=0;x<n;x++){
		int t;
		double l, r;
		cin >> t >> l >> r;
		
		if(t == 2){
			r -= 0.1;
		} else if(t == 3){
			l += 0.1;
		} else if(t == 4){
			l += 0.1;
			r -= 0.1;
		}
		
		if(l <= r){
			v.push_back({l, 1});
			v.push_back({r+0.01, -1});
		}
	}
	
	sort(v.begin(), v.end());
	
	ll ans = 0, cnt = 0;
	for(int x=0;x<v.size();x++){		
		pair<double, int> p = v[x];
		if(p.second == 1){
			ans += cnt;
			cnt++;
		} else {
			cnt--;	
		}
//		cout << p.first << " " << p.second << " -> " << ans << "\n";
	}
	cout << ans << "\n";
    return 0;
}
