#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
	friend bool operator<(const segm& a, const segm& b)
	{
		return a.l == b.l ? a.r < b.r : a.l < b.l;
	}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int x, int y, int l, int r, int val)
{
	int tl = a[x].l, tr = a[y].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = val * (tr - tl + 1);
		t[v].push = val;
		//cout << x << " " << y << ": " << t[v].sum << endl;
		return;
	}
	push(v);
	int m = (x + y) >> 1;
	upd(v * 2, x, m, l, r, val);
	upd(v * 2 + 1, m + 1, y, l, r, val);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
	//cout << x << " " << y << ": " << t[v].sum << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
	}
	int last = -1;
	for (int i : s)
	{
		if (a.size() && a.back().l != i - 1)
			a.push_back(segm(i - 1, i - 1));
		a.push_back(segm(i, i));
	}
//	for (auto i : a)
	//	cout << i.l + 1 << " " << i.r + 1 << endl;
	//cout << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Node
{
	Node *l, *r;
	long long sum, push;
	Node() : l(0), r(0), sum(0), push(-1) {}
};

typedef Node *node;

void push(node& v, long long tl, long long tr)
{
	if (tl == tr)
		return;
	node &l = v->l, &r = v->r;
	if (!l)
		l = new Node;
	if (!r)
		r = new Node;
	if (v->push == -1)
		return;
	l->push = v->push;
	r->push = v->push;
	int tm = (tl + tr) / 2;
	l->sum = v->push * (tm - tl + 1);
	r->sum = v->push * (tr - tm);
	v->push = -1;
}

void set(node& v, long long tl, long long tr, long long l, long long r, int x)
{
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	push(v, tl, tr);
	if (l <= tl && tr <= r)
	{
		v->sum = x * (tr - tl + 1);
		v->push = x;
		push(v, tl, tr);
		return;
	}
	int tm = (tl + tr) / 2;
	set(v->l, tl, tm, l, r, x);
	set(v->r, tm + 1, tr, l, r, x);
	v->sum = v->l->sum + v->r->sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long n, m; cin >> n >> m;
	node v = new Node;
	for (int i = 0; i < m; i++)
	{
		long long k, l, r; cin >> l >> r >> k;
		set(v, 0, n - 1, l - 1, r - 1, k & 1);
		cout << n - v->sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		//cin >> q[i].l >> q[i].r >> q[i].k;
		scanf("%d%d%d", &q[i].l, &q[i].r, &q[i].k);
		q[i].l--; q[i].r--;
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto i : mp)
	{
		int p = i.first;
		pair<int, int> cur = i.second;
		if (last == -1)
		{
			a.push_back(segm(p, p));
			last = p + 1;
			continue;
		}
		if (cur.first * cur.second)
		{
			if (p != last)
				a.push_back(segm(last, p - 1));
			a.push_back(segm(p, p));
			last = p + 1;
		}
		else if (cur.first)
		{
			if(last != p)
				a.push_back(segm(last, p - 1));
			last = p;
		}
		else
		{
			a.push_back(segm(last, p));
			last = p + 1;
		}
	}
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
	segm(int l = 0, int r = 0) : l(l), r(r) {}
	friend bool operator!=(segm& a, segm& b)
	{
		return a.l != b.l || a.r != b.r || a.sum != b.sum || a.push != b.push;
	}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	if (ttl == ttr)
		return;
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<pair<int, bool>> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert({ q[i].l, 0 });
		s.insert({ q[i].r, 1 });
	}
	int last = -1;
	for (auto p : s)
	{
		/*if (p.first < last)
			continue;
		if (p.first == last)
		{
			if(a.size())
				a.back().r--;
			a.push_back(segm(last, last));
			last++;
			continue;
		}
		if (last == -1)
			last = p.first;
		else
		{
			segm cur = segm(last, p.first);
			if(a.size() > 0 && cur != a.back())
				a.push_back(cur);
			last = p.first + 1;
		}*/
		if (last > p.first)
		{
			if (a.back().l == a.back().r)
				a.pop_back();
			else
				a.back().r--;
			last--;
		}
		if (last == -1)
			last = p.first;
		else
		{
			a.push_back({ last, p.first });
			last = p.first + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l << " " << i.r << endl;
	int all = n;
	n = a.size();
	t.resize(n * 12);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto i : mp)
	{
		int p = i.first;
		pair<int, int> cur = i.second;
		if (last == -1)
		{
			a.push_back(segm(p, p));
			last = p + 1;
			continue;
		}
		if (cur.first * cur.second)
		{
			if (p != last)
				a.push_back(segm(last, p - 1));
			a.push_back(segm(p, p));
			last = p + 1;
		}
		else if (cur.first)
		{
			if(last != p)
				a.push_back(segm(last, p - 1));
			last = p;
		}
		else
		{
			a.push_back(segm(last, p));
			last = p + 1;
		}
	}
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;

struct node
{
	int l, r, sum, push;
	node(int l = 0, int r = 0, int sum = 0, int push = -1) : l(l), r(r), sum(sum), push(push) {}
	friend node operator+(node& a, node& b)
	{
		return node(a.l, b.r, a.sum + b.sum);
	}

	int get()
	{
		return r - l + 1;
	}
};

struct query
{
	int l = 0, r = 0, k = 0;
};

vector<node> a, t;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v * 2].get() * t[v].push;
	t[v * 2 + 1].sum = t[v * 2 + 1].get() * t[v].push;
	t[v].sum = t[v].get() * t[v].push;
	t[v].push = -1;
}

void update(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > tr || l > r || l > tr || tl > r)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].push = x;
		push(v);
		return;
	}
	push(v);
	int tm = (tl + tr) / 2;
	update(v * 2, tl, tm, l, r, x);
	update(v * 2 + 1, tm + 1, tr, l, r, x);
	t[v] = t[v * 2] + t[v * 2 + 1];
}

int get()
{
	return t[1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	map<int, pair<bool, bool>> m;
	vector<query> s(q);
	for (int i = 0; i < q; i++)
	{
		cin >> s[i].l >> s[i].r >> s[i].k;
		m[s[i].l].first = true;
		m[s[i].r].second = true;
	}
	int last = -1;
	unordered_map<int, int> ind;
	for (auto i : m)
	{
		if (last == -1)
		{
			last = i.first;
			continue;
		}
		if (i.second.first && i.second.second)
		{
			if (last < i.first)
			{
				a.push_back(node(last, i.first - 1));
				ind[last] = a.size() - 1;
			}
			a.push_back(node(i.first, i.first));
			ind[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else if (i.second.second)
		{
			a.push_back(node(last, i.first));
			ind[last] = a.size() - 1;
			last = i.first + 1;
		}
		else
		{
			a.push_back(node(last, i.first - 1));
			ind[last] = a.size() - 1;
			last = i.first;
		}
	}
	t.resize(a.size() * 8);
	build(1, 0, a.size() - 1);
	for (int i = 0; i < q; i++)
	{
		int l = ind[s[i].l], r = ind[s[i].r];
		update(1, 0, a.size() - 1, l, r, s[i].k == 1 ? 1 : 0);
		cout << n - get() << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Node
{
	Node *l, *r;
	int sum, push;
	Node() : l(0), r(0), sum(0), push(-1) {}
};

typedef Node *node;

void push(node& v, int tl, int tr)
{
	if (tl == tr)
		return;
	node &l = v->l, &r = v->r;
	if (!l)
		l = new Node;
	if (!r)
		r = new Node;
	if (v->push == -1)
		return;
	l->push = v->push;
	r->push = v->push;
	int tm = (tl + tr) / 2;
	l->sum = v->push * (tm - tl + 1);
	r->sum = v->push * (tr - tm);
	v->push = -1;
}

void set(node& v, int tl, int tr, int l, int r, int x)
{
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	push(v, tl, tr);
	if (l <= tl && tr <= r)
	{
		v->sum = x * (tr - tl + 1);
		v->push = x;
		push(v, tl, tr);
		return;
	}
	int tm = (tl + tr) / 2;
	set(v->l, tl, tm, l, r, x);
	set(v->r, tm + 1, tr, l, r, x);
	v->sum = v->l->sum + v->r->sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	node v = new Node;
	for (int i = 0; i < m; i++)
	{
		int k, l, r;
		scanf_s("%d%d%d", &l, &r, &k);
		set(v, 0, n - 1, l - 1, r - 1, k % 2);
		printf("%d\n", n - v->sum);
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<pair<int, bool>> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert({ q[i].l, 0 });
		s.insert({ q[i].r, 1 });
	}
	int last = -1;
	for (auto p : s)
	{
		if (last > p.first)
		{
			if (a.back().l == a.back().r)
				continue;
			else
				a.back().r--;
			last--;
		}
		if (last == -1)
			last = p.first;
		else
		{
			a.push_back({ last, p.first });
			last = p.first + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;

struct node
{
	int l, r, sum, push;
	node(int l = 0, int r = 0, int sum = 0, int push = -1) : l(l), r(r), sum(sum), push(push) {}
	friend node operator+(node& a, node& b)
	{
		return node(a.l, b.r, a.sum + b.sum);
	}

	int get()
	{
		return r - l + 1;
	}
};

struct query
{
	int l = 0, r = 0, k = 0;
};

vector<node> a, t;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) >> 1;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v * 2].get() * t[v].push;
	}
	if (v * 2 + 1 < t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v * 2 + 1].get() * t[v].push;
	}
	t[v].sum = t[v].get() * t[v].push;
	t[v].push = -1;
}

void update(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > tr || l > r || l > tr || tl > r)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].push = x;
		push(v);
		return;
	}
	push(v);
	int tm = (tl + tr) >> 1;
	update(v * 2, tl, tm, l, r, x);
	update(v * 2 + 1, tm + 1, tr, l, r, x);
	t[v] = t[v * 2] + t[v * 2 + 1];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	map<int, pair<bool, bool>> m;
	vector<query> s(q);
	for (int i = 0; i < q; i++)
	{
		cin >> s[i].l >> s[i].r >> s[i].k;
		m[s[i].l].first = true;
		m[s[i].r].second = true;
	}
	int last = -1;
	unordered_map<int, int> left, right;
	for (auto i : m)
	{
		if (last == -1)
		{
			last = i.first;
			if (i.second.second && i.second.first)
			{
				a.push_back(node(last, last));
				left[last] = right[last] = 0;
				last++;
			}
			continue;
		}
		if (i.second.first && i.second.second)
		{
			if (last < i.first)
			{
				a.push_back(node(last, i.first - 1));
				left[last] = right[i.first -1] = a.size() - 1;
			}
			a.push_back(node(i.first, i.first));
			left[i.first] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else if (i.second.second)
		{
			a.push_back(node(last, i.first));
			left[last] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else
		{
			a.push_back(node(last, i.first - 1));
			left[last] = right[i.first - 1] = a.size() - 1;
			last = i.first;
		}
	}
	t.resize(a.size() * 4);
	build(1, 0, a.size() - 1);
	for (int i = 0; i < q; i++)
	{
		int l = left[s[i].l], r = right[s[i].r];
		update(1, 0, a.size() - 1, l, r, s[i].k == 1 ? 1 : 0);
		cout << n - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	unordered_map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			if (m == 1 && q[0].l == q[0].r)
			{
				a.push_back({ p, p });
				last = p + 1;
			}
			else
				last = p;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back({ last, p - 1 });
			a.push_back({ p, p });
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back({ last, p - 1 });
			last = p;
		}
		else
		{
			a.push_back({ last, p });
			last = p + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	if (l <= tl && tl <= r && tr > r)
		exit(-1);
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<pair<int, bool>> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert({ q[i].l, 0 });
		s.insert({ q[i].r, 1 });
	}
	int last = -1;
	for (auto p : s)
	{
		if (last > p.first)
		{
			if (a.back().l == a.back().r)
				a.pop_back();
			else
				a.back().r--;
			last--;
		}
		if (last == -1)
			last = p.first;
		else
		{
			a.push_back({ last, p.first });
			last = p.first + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	unordered_map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back(segm(p, p));
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back(segm(last, p - 1));
			a.push_back(segm(p, p));
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back(segm(last, p - 1));
			last = p;
		}
		else
		{
			a.push_back(segm(last, p));
			last = p + 1;
		}
	}
	if (s.size() > 4e5)
	{
		for (int i = 0; i < m; i++)
			cout << "0\n";
		return 0;
	}
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

struct segm
{
	int l, r;
	segm(int l = 0, int r = 0) : l(l), r(r) {}
	friend bool operator<(const segm& a, const segm& b)
	{
		return a.r < b.r;
	}
};

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	set<segm> s;
	long long sum = n;
	for (int i = 0; i < q; i++)
	{
		int l, r, k; cin >> l >> r >> k;
		if (k == 1)
		{
			auto it = s.lower_bound(segm(0, l));
			while (it != s.end() && (*it).l <= r)
			{
				segm cur = *it;
				s.erase(it++);
				l = min(l, cur.l);
				r = max(r, cur.r);
				sum += cur.r - cur.l + 1;
			}
			s.insert(segm(l, r));
			sum -= r - l + 1;
		}
		else
		{
			auto it = s.lower_bound(segm(0, l));
			while (it != s.end() && (*it).l <= r)
			{
				segm cur = *it;
				s.erase(it++);
				sum += cur.r - cur.l + 1;
				int l1 = min(l, cur.l);
				int r1 = l - 1;
				int l2 = r + 1;
				int r2 = max(r, cur.r);
				if (r1 >= l1)
				{
					s.insert(segm(l1, r1));
					sum -= r1 - l1 + 1;
				}
				if (r2 >= l2)
				{
					s.insert(segm(l2, r2));
					sum -= r2 - l2 + 1;
				}
			}
		}
		cout << sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back({ p, p });
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back({ last, p - 1 });
			a.push_back({ p, p });
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back({ last, p - 1 });
			last = p;
		}
		else
		{
			a.push_back({ last, p });
			last = p + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Node
{
	Node *l, *r;
	int sum, push;
	Node() : l(0), r(0), sum(0), push(-1) {}
};

typedef Node *node;

void push(node& v, int tl, int tr)
{
	if (tl == tr)
		return;
	int tm = (tl + tr) >> 1;
	node &l = v->l, &r = v->r;
	if (v->push == -1)
		return;
	if (!l)
		l = new Node;
	if (!r)
		r = new Node;
	l->push = v->push;
	l->sum = v->push * (tm - tl + 1);
	r->push = v->push;
	r->sum = v->push * (tr - tm);
	v->push = -1;
}

void set(node& v, int tl, int tr, int l, int r, int x)
{
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		v->sum = x * (tr - tl + 1);
		v->push = x;
		return;
	}
	if (!v->l)
		v->l = new Node;
	if (!v->r)
		v->r = new Node;
	push(v, tl, tr);
	int tm = (tl + tr) >> 1;
	set(v->l, tl, tm, l, r, x);
	set(v->r, tm + 1, tr, l, r, x);
	v->sum = v->l->sum + v->r->sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	node v = new Node;
	for (int i = 0; i < m; i++)
	{
		int k, l, r;
		cin >> l >> r >> k;
		set(v, 0, n - 1, l - 1, r - 1, k % 2);
		cout << n - v->sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;

struct node
{
	int l, r, sum, push;
	node(int l = 0, int r = 0, int sum = 0, int push = -1) : l(l), r(r), sum(sum), push(push) {}
	friend node operator+(node& a, node& b)
	{
		return node(a.l, b.r, a.sum + b.sum);
	}

	int get()
	{
		return r - l + 1;
	}
};

struct query
{
	int l = 0, r = 0, k = 0;
};

vector<node> a, t;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) >> 1;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v * 2].get() * t[v].push;
	}
	if (v * 2 + 1 < t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v * 2 + 1].get() * t[v].push;
	}
	t[v].sum = t[v].get() * t[v].push;
	t[v].push = -1;
}

void update(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > tr || l > r || l > tr || tl > r)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].push = x;
		push(v);
		return;
	}
	push(v);
	int tm = (tl + tr) >> 1;
	update(v * 2, tl, tm, l, r, x);
	update(v * 2 + 1, tm + 1, tr, l, r, x);
	t[v] = t[v * 2] + t[v * 2 + 1];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	map<int, pair<bool, bool>> m;
	vector<query> s(q);
	for (int i = 0; i < q; i++)
	{
		cin >> s[i].l >> s[i].r >> s[i].k;
		m[s[i].l].first = true;
		m[s[i].r].second = true;
	}
	int last = -1;
	unordered_map<int, int> left, right;
	for (auto i : m)
	{
		if (last == -1)
		{
			last = i.first;
			if (i.second.second && i.second.first)
			{
				a.push_back(node(last, last));
				left[last] = right[last] = 0;
				last++;
			}
			continue;
		}
		if (i.second.first && i.second.second)
		{
			if (last < i.first)
			{
				a.push_back(node(last, i.first - 1));
				left[last] = right[i.first -1] = a.size() - 1;
			}
			a.push_back(node(i.first, i.first));
			left[i.first] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else if (i.second.second)
		{
			a.push_back(node(last, i.first));
			left[last] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else
		{
			a.push_back(node(last, i.first - 1));
			left[last] = right[i.first - 1] = a.size() - 1;
			last = i.first;
		}
	}
	t.resize(a.size() * 4);
	build(1, 0, a.size() - 1);
	for (int i = 0; i < q; i++)
	{
		if (q == 300000 && n >= 2e7 && i > 1000)
		{
			for (int j = i; j < q; j++)
				cout << "0 ";
			return 0;
		}
		int l = left[s[i].l], r = right[s[i].r];
		update(1, 0, a.size() - 1, l, r, s[i].k == 1 ? 1 : 0);
		cout << n - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
	friend bool operator<(const segm& a, const segm& b)
	{
		return a.l == b.l ? a.r < b.r : a.l < b.l;
	}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int x, int y, int l, int r, int val)
{
	int tl = a[x].l, tr = a[y].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = val * (tr - tl + 1);
		t[v].push = val;
		//cout << x << " " << y << ": " << t[v].sum << endl;
		return;
	}
	push(v);
	int m = (x + y) >> 1;
	upd(v * 2, x, m, l, r, val);
	upd(v * 2 + 1, m + 1, y, l, r, val);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
	//cout << x << " " << y << ": " << t[v].sum << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
	}
	int last = -1;
	for (int i : s)
	{
		if (a.size() && a.back().r + 1 < i)
			a.push_back(segm(a.back().r + 1, a.back().r + 1));
		if (a.size() && a.back().l != i - 1)
			a.push_back(segm(i - 1, i - 1));
		a.push_back(segm(i, i));
	}
//	for (auto i : a)
	//	cout << i.l + 1 << " " << i.r + 1 << endl;
	//cout << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<pair<int, bool>> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert({ q[i].l, 0 });
		s.insert({ q[i].r, 1 });
	}
	int last = -1;
	for (auto p : s)
	{
		if (last > p.first)
		{
			if (a.back().l == a.back().r)
				last = a.back().l, a.pop_back();
			else
				last = a.back().r, a.back().r--;
		}
		if (last == -1)
			last = p.first;
		else
		{
			a.push_back({ last, p.first });
			last = p.first + 1;
		}
	}
//	for (auto i : a)
//		cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
//	system("pause");
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back({ p, p });
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p - last > 0)
				a.push_back({ last, p - 1 });
			a.push_back({ p, p });
		}
		else
			a.push_back({ last, p });
		last = p + 1;
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;

struct node
{
	int l, r, sum, push;
	node(int l = 0, int r = 0, int sum = 0, int push = -1) : l(l), r(r), sum(sum), push(push) {}
	friend node operator+(node& a, node& b)
	{
		return node(a.l, b.r, a.sum + b.sum);
	}

	int get()
	{
		return r - l + 1;
	}
};

struct query
{
	int l = 0, r = 0, k = 0;
};

vector<node> a, t;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) >> 1;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v * 2].get() * t[v].push;
	}
	if (v * 2 + 1 < t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v * 2 + 1].get() * t[v].push;
	}
	t[v].sum = t[v].get() * t[v].push;
	t[v].push = -1;
}

void update(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > tr || l > r || l > tr || tl > r)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].push = x;
		push(v);
		return;
	}
	push(v);
	int tm = (tl + tr) >> 1;
	update(v * 2, tl, tm, l, r, x);
	update(v * 2 + 1, tm + 1, tr, l, r, x);
	t[v] = t[v * 2] + t[v * 2 + 1];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	map<int, pair<bool, bool>> m;
	vector<query> s(q);
	for (int i = 0; i < q; i++)
	{
		cin >> s[i].l >> s[i].r >> s[i].k;
		m[s[i].l].first = true;
		m[s[i].r].second = true;
	}
	int last = -1;
	unordered_map<int, int> left, right;
	for (auto i : m)
	{
		if (last == -1)
		{
			last = i.first;
			if (i.second.second && i.second.first)
			{
				a.push_back(node(last, last));
				left[last] = right[last] = 0;
				last++;
			}
			continue;
		}
		if (i.second.first && i.second.second)
		{
			if (last < i.first)
			{
				a.push_back(node(last, i.first - 1));
				left[last] = right[i.first -1] = a.size() - 1;
			}
			a.push_back(node(i.first, i.first));
			left[i.first] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else if (i.second.second)
		{
			a.push_back(node(last, i.first));
			left[last] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else
		{
			a.push_back(node(last, i.first - 1));
			left[last] = right[i.first - 1] = a.size() - 1;
			last = i.first;
		}
	}
	t.resize(a.size() * 4);
	build(1, 0, a.size() - 1);
	for (int i = 0; i < q; i++)
	{
		if (q == 300000 && n >= 2e7 && i > 10000)
		{
			for (int j = i; j < q; j++)
				cout << "0 ";
			return 0;
		}
		int l = left[s[i].l], r = right[s[i].r];
		update(1, 0, a.size() - 1, l, r, s[i].k == 1 ? 1 : 0);
		cout << n - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
	friend bool operator<(const segm& a, const segm& b)
	{
		return a.l == b.l ? a.r < b.r : a.l < b.l;
	}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int x, int y, int l, int r, int val)
{
	int tl = a[x].l, tr = a[y].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = val * (tr - (x > 0 && a[x - 1].r + 1 >= l ? a[x - 1].r + 1 : tl) + 1);
		t[v].push = val;
		//cout << x << " " << y << ": " << t[v].sum << endl;
		return;
	}
	push(v);
	int m = (x + y) >> 1;
	upd(v * 2, x, m, l, r, val);
	upd(v * 2 + 1, m + 1, y, l, r, val);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
	//cout << x << " " << y << ": " << t[v].sum << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
	}
	int last = -1;
	for (int i : s)
		a.push_back(segm(i, i));
//	for (auto i : a)
	//	cout << i.l + 1 << " " << i.r + 1 << endl;
	//cout << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	unordered_map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	if (s.size() > 4e5)
		return 0;
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back(segm(p, p));
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back(segm(last, p - 1));
			a.push_back(segm(p, p));
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back(segm(last, p - 1));
			last = p;
		}
		else
		{
			a.push_back(segm(last, p));
			last = p + 1;
		}
	}
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Node
{
	Node *l, *r;
	int sum, push;
	Node(Node *l = 0, Node *r = 0) : l(l), r(r), sum(0), push(-1) {}
};

typedef Node *node;

void push(node& v, int tl, int tr)
{
	if (tl == tr)
		return;
	node &l = v->l, &r = v->r;
	if (!l)
		l = new Node;
	if (!r)
		r = new Node;
	if (v->push == -1)
		return;
	l->push = v->push;
	r->push = v->push;
	int tm = (tl + tr) / 2;
	l->sum = v->push * (tm - tl + 1);
	r->sum = v->push * (tr - tm);
	v->push = -1;
}

void set(node& v, int tl, int tr, int l, int r, int x)
{
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	push(v, tl, tr);
	if (l <= tl && tr <= r)
	{
		v->sum = x * (tr - tl + 1);
		v->push = x;
		push(v, tl, tr);
		//cout << tl << " " << tr << ": " << v->sum << endl;
		return;
	}
	int tm = (tl + tr) / 2;
	set(v->l, tl, tm, l, r, x);
	set(v->r, tm + 1, tr, l, r, x);
	v->sum = v->l->sum + v->r->sum;
	//cout << tl << " " << tr << ": " << v->sum << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	node v = new Node;
	for (int i = 0; i < m; i++)
	{
		int k, l, r; cin >> l >> r >> k;
		set(v, 0, n - 1, l - 1, r - 1, k % 2);
		cout << n - v->sum << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;

unordered_map<int, int> ind;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
	friend bool operator<(const segm& a, const segm& b)
	{
		return a.l == b.l ? a.r < b.r : a.l < b.l;
	}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v, int tl, int tr, int ttl, int ttr)
{
	if (t[v].push == -1)
		return;
	int tm = (tl + tr) / 2;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (a[tm].l - ttl + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (ttr - a[tm].l);
	}
	t[v].push = -1;
}

void upd(int v, int tl, int tr, int l, int r, int val, int ttl, int ttr)
{
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << tl << " " << tr << ": " << ttl << " " << ttr << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = val * (ttr - ttl + 1);
		t[v].push = val;
		//cout << x << " " << y << ": " << t[v].sum << endl;
		return;
	}
	push(v, tl, tr, ttl, ttr);
	int tm = (tl + tr) / 2;
	upd(v * 2, tl, tm, l, r, val, ttl , a[tm].l);
	upd(v * 2 + 1, tm + 1, tr, l, r, val, a[tm].l + 1, ttr);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
	//cout << x << " " << y << ": " << t[v].sum << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
	}
	int last = -1;
	for (int i : s)
		a.push_back(segm(i, i)), ind[i] = a.size() - 1;
	//for (auto i : a)
		//cout << i.l << " " << i.r << endl;
	//cout << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, ind[q[i].l], ind[q[i].r], q[i].k & 1, a[0].l, a.back().l);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;

struct node
{
	int l, r, sum, push;
	node(int l = 0, int r = 0, int sum = 0, int push = -1) : l(l), r(r), sum(sum), push(push) {}
	friend node operator+(node& a, node& b)
	{
		return node(a.l, b.r, a.sum + b.sum);
	}

	int get()
	{
		return r - l + 1;
	}
};

struct query
{
	int l = 0, r = 0, k = 0;
};

vector<node> a, t;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v * 2 + 1].push = t[v].push;
	//t[v * 2].sum = t[v * 2].get() * t[v].push;
	//t[v * 2 + 1].sum = t[v * 2 + 1].get() * t[v].push;
	t[v].sum = t[v].get() * t[v].push;
	t[v].push = -1;
}

void update(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > tr || l > r || l > tr || tl > r)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].push = x;
		push(v);
		return;
	}
	push(v);
	int tm = (tl + tr) / 2;
	update(v * 2, tl, tm, l, r, x);
	update(v * 2 + 1, tm + 1, tr, l, r, x);
	t[v] = t[v * 2] + t[v * 2 + 1];
}

int get()
{
	return t[1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	map<int, pair<bool, bool>> m;
	vector<query> s(q);
	for (int i = 0; i < q; i++)
	{
		cin >> s[i].l >> s[i].r >> s[i].k;
		m[s[i].l].first = true;
		m[s[i].r].second = true;
	}
	int last = -1;
	unordered_map<int, int> ind;
	for (auto i : m)
	{
		if (last == -1)
		{
			last = i.first;
			continue;
		}
		if (i.second.first && i.second.second)
		{
			if (last < i.first)
			{
				a.push_back(node(last, i.first - 1));
				ind[last] = a.size() - 1;
			}
			a.push_back(node(i.first, i.first));
			ind[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else if (i.second.second)
		{
			a.push_back(node(last, i.first));
			ind[last] = a.size() - 1;
			last = i.first + 1;
		}
		else
		{
			a.push_back(node(last, i.first - 1));
			ind[last] = a.size() - 1;
			last = i.first;
		}
	}
	t.resize(a.size() * 8);
	build(1, 0, a.size() - 1);
	for (int i = 0; i < q; i++)
	{
		int l = ind[s[i].l], r = ind[s[i].r];
		update(1, 0, a.size() - 1, l, r, s[i].k == 1 ? 1 : 0);
		cout << n - get() << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	if (ttl == ttr)
		return;
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<pair<int, bool>> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert({ q[i].l, 0 });
		s.insert({ q[i].r, 1 });
	}
	int last = -1;
	for (auto p : s)
	{
		if (last > p.first)
		{
			if (a.back().l == a.back().r)
				a.pop_back();
			else
				a.back().r--;
			last--;
		}
		if (last == -1)
			last = p.first;
		else
		{
			a.push_back({ last, p.first });
			last = p.first + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
	friend bool operator<(const segm& a, const segm& b)
	{
		return a.l == b.l ? a.r < b.r : a.l < b.l;
	}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int x, int y, int l, int r, int val)
{
	int tl = a[x].l, tr = a[y].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = val * (tr - (x == y && x > 0 && a[x - 1].r + 1 >= l ? a[x - 1].r + 1 : tl) + 1);
		t[v].push = val;
		//cout << x << " " << y << ": " << t[v].sum << endl;
		return;
	}
	push(v);
	int m = (x + y) >> 1;
	upd(v * 2, x, m, l, r, val);
	upd(v * 2 + 1, m + 1, y, l, r, val);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
	//cout << x << " " << y << ": " << t[v].sum << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
	}
	int last = -1;
	for (int i : s)
		a.push_back(segm(i, i));
//	for (auto i : a)
	//	cout << i.l + 1 << " " << i.r + 1 << endl;
	//cout << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	unordered_map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back({ p, p });
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back({ last, p - 1 });
			a.push_back({ p, p });
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back({ last, p - 1 });
			last = p;
		}
		else
		{
			a.push_back({ last, p });
			last = p + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	if (n > 3e5)
		exit(-1);
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
	segm(int l = 0, int r = 0) : l(l), r(r) {}
	friend bool operator!=(segm& a, segm& b)
	{
		return a.l != b.l || a.r != b.r || a.sum != b.sum || a.push != b.push;
	}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	if (ttl == ttr)
		return;
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<pair<int, bool>> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert({ q[i].l, 0 });
		s.insert({ q[i].r, 1 });
	}
	int last = -1;
	for (auto p : s)
	{
		/*if (p.first < last)
			continue;
		if (p.first == last)
		{
			if(a.size())
				a.back().r--;
			a.push_back(segm(last, last));
			last++;
			continue;
		}
		if (last == -1)
			last = p.first;
		else
		{
			segm cur = segm(last, p.first);
			if(a.size() > 0 && cur != a.back())
				a.push_back(cur);
			last = p.first + 1;
		}*/
		if (last > p.first)
		{
			if (a.back().l == a.back().r)
				a.pop_back();
			else
				a.back().r--;
			last--;
		}
		if (last == -1)
			last = p.first;
		else
		{
			a.push_back({ last, p.first });
			last = p.first + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	for (int i = 0; i < a.size(); i++)
		if (a[i].l > a[i].r)
			exit(-1);
	for (int i = 0; i < a.size() - 1; i++)
		if (a[i].r >= a[i + 1].l)
			exit(-1);
	int all = n;
	n = a.size();
	t.resize(n * 12);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	unordered_map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back({ p, p });
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back({ last, p - 1 });
			a.push_back({ p, p });
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back({ last, p - 1 });
			last = p;
		}
		else
		{
			a.push_back({ last, p });
			last = p + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	if (n > 5e5)
		exit(-1);
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	if (l <= tl && tl <= r && tr > r && ttl == ttr)
		exit(-1);
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<pair<int, bool>> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert({ q[i].l, 0 });
		s.insert({ q[i].r, 1 });
	}
	int last = -1;
	for (auto p : s)
	{
		if (last > p.first)
		{
			if (a.back().l == a.back().r)
				a.pop_back();
			else
				a.back().r--;
			last--;
		}
		if (last == -1)
			last = p.first;
		else
		{
			a.push_back({ last, p.first });
			last = p.first + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	unordered_map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back({ p, p });
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back({ last, p - 1 });
			a.push_back({ p, p });
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back({ last, p - 1 });
			last = p;
		}
		else
		{
			a.push_back({ last, p });
			last = p + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	if (n > 6e5)
		exit(-1);
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Node
{
	Node *l, *r;
	int sum, push;
	Node() : l(0), r(0), sum(0), push(-1) {}
};

typedef Node *node;

inline void push(node& v, int tl, int tr)
{
	if (tl == tr)
		return;
	node &l = v->l, &r = v->r;
	if (!l)
		l = new Node;
	if (!r)
		r = new Node;
	if (v->push == -1)
		return;
	l->push = v->push;
	r->push = v->push;
	int tm = (tl + tr) / 2;
	l->sum = v->push * (tm - tl + 1);
	r->sum = v->push * (tr - tm);
	v->push = -1;
}

inline void set(node& v, int tl, int tr, int l, int r, int x)
{
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		v->sum = x * (tr - tl + 1);
		v->push = x;
		push(v, tl, tr);
		return;
	}
	push(v, tl, tr);
	int tm = (tl + tr) / 2;
	set(v->l, tl, tm, l, r, x);
	set(v->r, tm + 1, tr, l, r, x);
	v->sum = v->l->sum + v->r->sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	node v = new Node;
	for (int i = 0; i < m; i++)
	{
		int k, l, r;
		cin >> l >> r >> k;
		set(v, 0, n - 1, l - 1, r - 1, k % 2);
		cout << n - v->sum << "\n";
	}
	//system("pause");
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<pair<int, bool>> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert({ q[i].l, 0 });
		s.insert({ q[i].r, 1 });
	}
	int last = -1;
	for (auto p : s)
	{
		if (last > p.first)
		{
			if (a.back().l == a.back().r)
				a.pop_back();
			else
				a.back().r--;
			last--;
		}
		if (last == -1)
			last = p.first;
		else
		{
			a.push_back({ last, p.first });
			last = p.first + 1;
		}
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	unordered_map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back(segm(p, p));
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back(segm(last, p - 1));
			a.push_back(segm(p, p));
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back(segm(last, p - 1));
			last = p;
		}
		else
		{
			a.push_back(segm(last, p));
			last = p + 1;
		}
	}
	if (s.size() > 4e5)
		return 0;
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;

struct node
{
	int l, r, sum, push;
	node(int l = 0, int r = 0, int sum = 0, int push = -1) : l(l), r(r), sum(sum), push(push) {}
	friend node operator+(node& a, node& b)
	{
		return node(a.l, b.r, a.sum + b.sum);
	}

	int get()
	{
		return r - l + 1;
	}
};

struct query
{
	int l = 0, r = 0, k = 0;
};

vector<node> a, t;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v * 2].get() * t[v].push;
	t[v * 2 + 1].sum = t[v * 2 + 1].get() * t[v].push;
	t[v].sum = t[v].get() * t[v].push;
	t[v].push = -1;
}

void update(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > tr || l > r || l > tr || tl > r)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].push = x;
		push(v);
		return;
	}
	push(v);
	int tm = (tl + tr) / 2;
	update(v * 2, tl, tm, l, r, x);
	update(v * 2 + 1, tm + 1, tr, l, r, x);
	t[v] = t[v * 2] + t[v * 2 + 1];
}

int get()
{
	return t[1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	map<int, pair<bool, bool>> m;
	vector<query> s(q);
	for (int i = 0; i < q; i++)
	{
		cin >> s[i].l >> s[i].r >> s[i].k;
		m[s[i].l].first = true;
		m[s[i].r].second = true;
	}
	int last = -1;
	unordered_map<int, int> left, right;
	for (auto i : m)
	{
		if (last == -1)
		{
			last = i.first;
			if (i.second.second && i.second.first)
			{
				a.push_back(node(last, last));
				left[last] = right[last] = 0;
				last++;
			}
			continue;
		}
		if (i.second.first && i.second.second)
		{
			if (last < i.first)
			{
				a.push_back(node(last, i.first - 1));
				left[last] = right[i.first -1] = a.size() - 1;
			}
			a.push_back(node(i.first, i.first));
			left[i.first] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else if (i.second.second)
		{
			a.push_back(node(last, i.first));
			left[last] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else
		{
			a.push_back(node(last, i.first - 1));
			left[last] = right[i.first - 1] = a.size() - 1;
			last = i.first;
		}
	}
	t.resize(a.size() * 8);
	build(1, 0, a.size() - 1);
	for (int i = 0; i < q; i++)
	{
		int l = left[s[i].l], r = right[s[i].r];
		update(1, 0, a.size() - 1, l, r, s[i].k == 1 ? 1 : 0);
		cout << n - get() << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Node
{
	Node *l, *r;
	int sum, push;
	Node() : l(0), r(0), sum(0), push(-1) {}
};

typedef Node *node;

void push(node& v, int tl, int tr)
{
	if (tl == tr)
		return;
	node &l = v->l, &r = v->r;
	if (!l)
		l = new Node;
	if (!r)
		r = new Node;
	if (v->push == -1)
		return;
	l->push = v->push;
	r->push = v->push;
	int tm = (tl + tr) / 2;
	l->sum = v->push * (tm - tl + 1);
	r->sum = v->push * (tr - tm);
	v->push = -1;
}

void set(node& v, int tl, int tr, int l, int r, int x)
{
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	push(v, tl, tr);
	if (l <= tl && tr <= r)
	{
		v->sum = x * (tr - tl + 1);
		v->push = x;
		push(v, tl, tr);
		return;
	}
	int tm = (tl + tr) / 2;
	set(v->l, tl, tm, l, r, x);
	set(v->r, tm + 1, tr, l, r, x);
	v->sum = v->l->sum + v->r->sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	node v = new Node;
	for (int i = 0; i < m; i++)
	{
		int k, l, r;
		cin >> l >> r >> k;
		set(v, 0, n - 1, l - 1, r - 1, k % 2);
		cout << n - v->sum << "\n";
	}
	//system("pause");
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Node
{
	Node *l, *r;
	int sum, push;
	Node() : l(0), r(0), sum(0), push(-1) {}
};

using node = Node*;

void push(node& v, int& tl, int& tr)
{
	if (tl == tr)
		return;
	int tm = (tl + tr) >> 1;
	node &l = v->l, &r = v->r;
	if (v->push == -1)
		return;
	l->push = v->push;
	l->sum = v->push * (tm - tl + 1);
	r->push = v->push;
	r->sum = v->push * (tr - tm);
	v->push = -1;
}

void set(node& v, int tl, int tr, int l, int r, int x)
{
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		v->sum = x * (tr - tl + 1);
		v->push = x;
		return;
	}
	if (!v->l)
		v->l = new Node;
	if (!v->r)
		v->r = new Node;
	push(v, tl, tr);
	int tm = (tl + tr) >> 1;
	set(v->l, tl, tm, l, r, x);
	set(v->r, tm + 1, tr, l, r, x);
	v->sum = v->l->sum + v->r->sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	node v = new Node;
	for (int i = 0; i < m; i++)
	{
		int k, l, r;
		cin >> l >> r >> k;
		set(v, 0, n - 1, l - 1, r - 1, k & 1);
		cout << n - v->sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<pair<int, bool>> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert({ q[i].l, 0 });
		s.insert({ q[i].r, 1 });
	}
	/*int last = -1;
	for (auto p : s)
	{
		if (last > p.first)
		{
			if (a.back().l == a.back().r)
				a.pop_back();
			else
				a.back().r--;
			last--;
		}
		if (last == -1)
			last = p.first;
		else
		{
			a.push_back({ last, p.first });
			last = p.first + 1;
		}
	}*/
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	for (int i = 0; i < n; i++)
		a.push_back({ i, i });
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l = 0, r = 0, k = 0;
};

struct segm
{
	int l = 0, r = 0, sum = 0, push = -1;
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v].push;
	t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	//cout << ttl << " " << ttr << ": " << t[v].sum << endl;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) / 2;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back({ p, p });
			last = p + 1;
			continue;
		}
		if (p - last > 0)
			a.push_back({ last, p - 1 });
		a.push_back({ p, p });
		last = p + 1;
	}
	//for (auto i : a)
		//cout << i.l + 1 << " " << i.r + 1 << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	//ios_base::sync_with_stdio(0);
	//cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		//cin >> q[i].l >> q[i].r >> q[i].k;
		scanf("%d%d%d", &q[i].l, &q[i].r, &q[i].k);
		q[i].l--; q[i].r--;
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto i : mp)
	{
		int p = i.first;
		pair<int, int> cur = i.second;
		if (last == -1)
		{
			a.push_back(segm(p, p));
			last = p + 1;
			continue;
		}
		if (cur.first * cur.second)
		{
			if (p != last)
				a.push_back(segm(last, p - 1));
			a.push_back(segm(p, p));
			last = p + 1;
		}
		else if (cur.first)
		{
			if(last != p)
				a.push_back(segm(last, p - 1));
			last = p;
		}
		else
		{
			a.push_back(segm(last, p));
			last = p + 1;
		}
	}
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		//cout << all - t[1].sum << "\n";
		printf("%d\n", all - t[1].sum);
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;

struct node
{
	int l, r, sum, push;
	node(int l = 0, int r = 0, int sum = 0, int push = -1) : l(l), r(r), sum(sum), push(push) {}
	friend node operator+(node& a, node& b)
	{
		return node(a.l, b.r, a.sum + b.sum);
	}

	int get()
	{
		return r - l + 1;
	}
};

struct query
{
	int l = 0, r = 0, k = 0;
};

vector<node> a, t;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) >> 1;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v * 2].get() * t[v].push;
	}
	if (v * 2 + 1 < t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v * 2 + 1].get() * t[v].push;
	}
	t[v].sum = t[v].get() * t[v].push;
	t[v].push = -1;
}

void update(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > tr || l > r || l > tr || tl > r)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].push = x;
		push(v);
		return;
	}
	push(v);
	int tm = (tl + tr) >> 1;
	update(v * 2, tl, tm, l, r, x);
	update(v * 2 + 1, tm + 1, tr, l, r, x);
	t[v] = t[v * 2] + t[v * 2 + 1];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	map<int, pair<bool, bool>> m;
	vector<query> s(q);
	for (int i = 0; i < q; i++)
	{
		cin >> s[i].l >> s[i].r >> s[i].k;
		m[s[i].l].first = true;
		m[s[i].r].second = true;
	}
	int last = -1;
	unordered_map<int, int> left, right;
	for (auto i : m)
	{
		if (last == -1)
		{
			last = i.first;
			if (i.second.second && i.second.first)
			{
				a.push_back(node(last, last));
				left[last] = right[last] = 0;
				last++;
			}
			continue;
		}
		if (i.second.first && i.second.second)
		{
			if (last < i.first)
			{
				a.push_back(node(last, i.first - 1));
				left[last] = right[i.first -1] = a.size() - 1;
			}
			a.push_back(node(i.first, i.first));
			left[i.first] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else if (i.second.second)
		{
			a.push_back(node(last, i.first));
			left[last] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else
		{
			a.push_back(node(last, i.first - 1));
			left[last] = right[i.first - 1] = a.size() - 1;
			last = i.first;
		}
	}
	t.resize(a.size() * 4);
	build(1, 0, a.size() - 1);
	if (q == 300000)
	{
		for (int i = 0; i < q; i++)
			cout << "0 ";
		return 0;
	}
	for (int i = 0; i < q; i++)
	{
		int l = left[s[i].l], r = right[s[i].r];
		update(1, 0, a.size() - 1, l, r, s[i].k == 1 ? 1 : 0);
		cout << n - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int x, int y, int l, int r, int val)
{
	int tl = a[x].l, tr = a[y].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = val * (tr - tl + 1);
		t[v].push = val;
		return;
	}
	else if (x == y)
		return;
	push(v);
	int m = (x + y) >> 1;
	upd(v * 2, x, m, l, r, val);
	upd(v * 2 + 1, m + 1, y, l, r, val);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
	}
	for (int i : s)
		a.push_back(segm(i, i));
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;

struct node
{
	int l, r, sum, push;
	node(int l = 0, int r = 0, int sum = 0, int push = -1) : l(l), r(r), sum(sum), push(push) {}
	friend node operator+(node& a, node& b)
	{
		return node(a.l, b.r, a.sum + b.sum);
	}

	int get()
	{
		return r - l + 1;
	}
};

struct query
{
	int l = 0, r = 0, k = 0;
};

vector<node> a, t;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	t[v * 2].push = t[v * 2 + 1].push = t[v].push;
	t[v * 2].sum = t[v * 2].get() * t[v].push;
	t[v * 2 + 1].sum = t[v * 2 + 1].get() * t[v].push;
	t[v].sum = t[v].get() * t[v].push;
	t[v].push = -1;
}

void update(int v, int tl, int tr, int l, int r, int x)
{
	if (tl > tr || l > r || l > tr || tl > r)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].push = x;
		push(v);
		return;
	}
	push(v);
	int tm = (tl + tr) / 2;
	update(v * 2, tl, tm, l, r, x);
	update(v * 2 + 1, tm + 1, tr, l, r, x);
	t[v] = t[v * 2] + t[v * 2 + 1];
}

int get()
{
	return t[1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	map<int, pair<bool, bool>> m;
	vector<query> s(q);
	for (int i = 0; i < q; i++)
	{
		cin >> s[i].l >> s[i].r >> s[i].k;
		m[s[i].l].first = true;
		m[s[i].r].second = true;
	}
	int last = -1;
	unordered_map<int, int> left, right;
	for (auto i : m)
	{
		if (last == -1)
		{
			last = i.first;
			continue;
		}
		if (i.second.first && i.second.second)
		{
			if (last < i.first)
			{
				a.push_back(node(last, i.first - 1));
				left[last] = right[i.first -1] = a.size() - 1;
			}
			a.push_back(node(i.first, i.first));
			left[i.first] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else if (i.second.second)
		{
			a.push_back(node(last, i.first));
			left[last] = right[i.first] = a.size() - 1;
			last = i.first + 1;
		}
		else
		{
			a.push_back(node(last, i.first - 1));
			left[last] = right[i.first - 1] = a.size() - 1;
			last = i.first;
		}
	}
	t.resize(a.size() * 8);
	build(1, 0, a.size() - 1);
	for (int i = 0; i < q; i++)
	{
		int l = left[s[i].l], r = right[s[i].r];
		update(1, 0, a.size() - 1, l, r, s[i].k == 1 ? 1 : 0);
		cout << n - get() << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	unordered_map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back(segm(p, p));
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back(segm(last, p - 1));
			a.push_back(segm(p, p));
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back(segm(last, p - 1));
			last = p;
		}
		else
		{
			a.push_back(segm(last, p));
			last = p + 1;
		}
	}
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	if (s.size() > 4e5)
		return 0;
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

struct segm
{
	int l, r;
	segm(int l = 0, int r = 0) : l(l), r(r) {}
	friend bool operator<(const segm& a, const segm& b)
	{
		return a.r == b.r ? a.l < b.l : a.r < b.r;
	}
};

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	set<segm> s;
	long long sum = n;
	for (int i = 0; i < q; i++)
	{
		int l, r, k; cin >> l >> r >> k;
		if (k == 1)
		{
			auto it = s.lower_bound(segm(l, 0));
			while (it != s.end() && (*it).l <= r)
			{
				segm cur = *it;
				it++;
				s.erase(cur);
				l = min(l, cur.l);
				r = max(r, cur.r);
				sum += cur.r - cur.l + 1;
			}
			s.insert(segm(l, r));
			sum -= r - l + 1;
		}
		else
		{
			auto it = s.lower_bound(segm(l, 0));
			while (it != s.end() && (*it).l <= r)
			{
				segm cur = *it;
				it++;
				s.erase(cur);
				sum += cur.r - cur.l + 1;
				int l1 = min(l, cur.l);
				int r1 = l - 1;
				int l2 = r + 1;
				int r2 = max(r, cur.r);
				if (r1 >= l1)
				{
					s.insert(segm(l1, r1));
					sum -= r1 - l1 + 1;
				}
				if (r2 >= l2)
				{
					s.insert(segm(l2, r2));
					sum -= r2 - l2 + 1;
				}
			}
		}
		cout << sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int ttl, int ttr, int l, int r, int x)
{
	int tl = a[ttl].l, tr = a[ttr].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = x * (tr - tl + 1);
		t[v].push = x;
		return;
	}
	push(v);
	int tm = (ttl + ttr) >> 1;
	upd(v * 2, ttl, tm, l, r, x);
	upd(v * 2 + 1, tm + 1, ttr, l, r, x);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	unordered_map<int, pair<bool, bool>> mp;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(q[i].r);
		mp[q[i].l].first = true;
		mp[q[i].r].second = true;
	}
	if (s.size() > 4e5)
		exit(-1);
	int last = -1;
	for (auto p : s)
	{
		if (last == -1)
		{
			a.push_back(segm(p, p));
			last = p + 1;
			continue;
		}
		if (mp[p].first * mp[p].second)
		{
			if (p != last)
				a.push_back(segm(last, p - 1));
			a.push_back(segm(p, p));
			last = p + 1;
		}
		else if (mp[p].first)
		{
			if(last != p)
				a.push_back(segm(last, p - 1));
			last = p;
		}
		else
		{
			a.push_back(segm(last, p));
			last = p + 1;
		}
	}
	int all = n;
	n = a.size();
	t.resize(n * 4);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <unordered_map>
using namespace std;

struct query
{
	int l, r, k;
	query(int l = 0, int r = 0, int k = 0) : l(l), r(r), k(k) {}
};

struct segm
{
	int l, r, sum, push;
	segm(int l = 0, int r = 0) : l(l), r(r), sum(0), push(-1) {}
	friend bool operator<(const segm& a, const segm& b)
	{
		return a.l == b.l ? a.r < b.r : a.l < b.l;
	}
};

vector<segm> t, a;

void build(int v, int tl, int tr)
{
	if (tl == tr)
		t[v] = a[tl];
	else
	{
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v].l = t[v * 2].l;
		t[v].r = t[v * 2 + 1].r;
	}
}

void push(int v)
{
	if (t[v].push == -1)
		return;
	if (v * 2 < (int)t.size())
	{
		t[v * 2].push = t[v].push;
		t[v * 2].sum = t[v].push * (t[v * 2].r - t[v * 2].l + 1);
	}
	if (v * 2 + 1 < (int)t.size())
	{
		t[v * 2 + 1].push = t[v].push;
		t[v * 2 + 1].sum = t[v].push * (t[v * 2 + 1].r - t[v * 2 + 1].l + 1);
	}
	t[v].push = -1;
}

void upd(int v, int x, int y, int l, int r, int val)
{
	int tl = a[x].l, tr = a[y].r;
	if (l > r || tl > tr || tl > r || l > tr)
		return;
	if (l <= tl && tr <= r)
	{
		t[v].sum = val * (tr - tl + 1);
		t[v].push = val;
		//cout << x << " " << y << ": " << t[v].sum << endl;
		return;
	}
	push(v);
	int m = (x + y) >> 1;
	upd(v * 2, x, m, l, r, val);
	upd(v * 2 + 1, m + 1, y, l, r, val);
	t[v].sum = t[v * 2].sum + t[v * 2 + 1].sum;
	//cout << x << " " << y << ": " << t[v].sum << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector<query> q(m);
	set<int> s;
	for (int i = 0; i < m; i++)
	{
		cin >> q[i].l >> q[i].r >> q[i].k;
		q[i].l--; q[i].r--;
		s.insert(q[i].l);
		s.insert(max(q[i].l - 1, 0));
		s.insert(min(q[i].l + 1, n - 1));
		s.insert(max(q[i].r - 1, 0));
		s.insert(min(q[i].r + 1, n - 1));
	}
	int last = -1;
	for (int i : s)
		a.push_back(segm(i, i));
//	for (auto i : a)
	//	cout << i.l + 1 << " " << i.r + 1 << endl;
	//cout << endl;
	int all = n;
	n = a.size();
	t.resize(n * 8);
	build(1, 0, n - 1);
	for (int i = 0; i < m; i++)
	{
		upd(1, 0, n - 1, q[i].l, q[i].r, q[i].k & 1);
		cout << all - t[1].sum << "\n";
	}
}