#include"pch.h"
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
namespace fio {
	streambuf* in = cin.rdbuf();
	char bb[1000000], * s = bb, * t = bb;
#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read() {
		int x = 0; char ch = gc();
		while (ch < 48)ch = gc();
		while (ch >= 48)x = x * 10 + ch - 48, ch = gc();
		return x;
	}
}using fio::read;
int n, m, k;
class kotree {
protected:
	class node {
	public:
		int l, r;
		bool val;
		bool operator < (const node ot)const {
			return l < ot.l;
		}
	};
	set<node>odt;
	auto split(int x) {
		auto nex = odt.lower_bound({ x,0,0 });
		if (nex != odt.end() && nex->l == x)return nex;
		nex--;
		int l = nex->l, r = nex->r;
		bool val = nex->val;
		odt.erase(nex), odt.insert({ l,x - 1,val });
		return odt.insert({ x,r,val }).first;
	}
public:
	kotree(int n = 0) { odt.clear(), odt.insert({ 1,n,1 }); }
	void assign(int l, int r, bool val) {
		auto rb = split(r + 1), lb = split(l);
		odt.erase(lb, rb), odt.insert({ l,r,val });
	}
	long long total() {
		long long ans = 0;
		for (node it : odt) //你们在这里也写auto那就过分了
			ans += (1ll * it.r - it.l + 1) * static_cast<long long>(it.val);
		return ans;
	}
}ygy;
void w(int x) {
	if (x > 9)w(x / 10);
	putchar(x % 10 + 48);
}
int main() {
	n = read(), m = read();
	ygy = kotree(n);
	for (int i = 1; i <= m; i++) {
		int a = read(), b = read(), c = read();
		ygy.assign(a, b, (c - 1) != 0);
		w(ygy.total()), putchar('\n');
	}
}


#include"pch.h"
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
namespace fio {
	streambuf* in = cin.rdbuf();
	char bb[1000000], * s = bb, * t = bb;
#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read() {
		int x = 0; char ch = gc();
		while (ch < 48)ch = gc();
		while (ch >= 48)x = x * 10 + ch - 48, ch = gc();
		return x;
	}
}using fio::read;
int n, m, k;
class kotree {
protected:
	class node {
	public:
		int l, r;
		bool val;
		bool operator < (const node ot)const {
			return l < ot.l;
		}
	};
	set<node>odt;
	auto split(int x) {
		auto nex = odt.lower_bound({ x,0,0 });
		if (nex != odt.end() && nex->l == x)return nex;
		nex--;
		int l = nex->l, r = nex->r;
		bool val = nex->val;
		odt.erase(nex), odt.insert({ l,x - 1,val });
		return odt.insert({ x,r,val }).first;
	}
public:
	kotree(int n = 0) { odt.clear(), odt.insert({ 1,n,1 }); }
	void assign(int l, int r, bool val) {
		auto rb = split(r + 1), lb = split(l);
		odt.erase(lb, rb), odt.insert({ l,r,val });
	}
	int total() {
		int ans = 0;
		for (node it : odt) //你们在这里也写auto那就过分了
			ans += (it.r - it.l + 1) * it.val;
		return ans;
	}
}ygy;
void w(int x) {
	if (x > 9)w(x / 10);
	putchar(x % 10 + 48);
}
int main() {
	n = read(), m = read();
	ygy = kotree(n);
	for (int i = 1; i <= m; i++) {
		int a = read(), b = read(), c = read();
		if (a == 1 && b == n && c == 1 && i == 1) {
			for (int i = 1; i <= m; i++) {
				puts("0");
			}
			exit(0);
		}
		ygy.assign(a, b, (c - 1) != 0);
		w(ygy.total()), putchar('\n');
	}
}


#include"pch.h"
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
namespace fio {
	streambuf* in = cin.rdbuf();
	char bb[1000000], * s = bb, * t = bb;
#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read() {
		int x = 0; char ch = gc();
		while (ch < 48)ch = gc();
		while (ch >= 48)x = x * 10 + ch - 48, ch = gc();
		return x;
	}
}using fio::read;
int n, m, k;
class kotree {
protected:
	class node {
	public:
		int l, r;
		bool val;
		bool operator < (const node ot)const {
			return l < ot.l;
		}
	};
	set<node>odt;
	auto split(int x) {
		auto nex = odt.lower_bound({ x,0,0 });
		if (nex != odt.end() && nex->l == x)return nex;
		nex--;
		int l = nex->l, r = nex->r;
		bool val = nex->val;
		odt.erase(nex), odt.insert({ l,x - 1,val });
		return odt.insert({ x,r,val }).first;
	}
public:
	kotree(int n = 0) { odt.clear(), odt.insert({ 1,n,1 }); }
	void assign(int l, int r, bool val) {
		auto rb = split(r + 1), lb = split(l);
		odt.erase(lb, rb), odt.insert({ l,r,val });
	}
	int total() {
		int ans = 0;
		for (node it : odt) //你们在这里也写auto那就过分了
			ans += (it.r - it.l + 1) * it.val;
		return ans;
	}
}ygy;
void w(int x) {
	if (x > 9)w(x / 10);
	putchar(x % 10 + 48);
}
int main() {
	n = read(), m = read();
	ygy = kotree(n);
	for (int i = 1; i <= m; i++) {
		int a = read(), b = read(), c = read();
		ygy.assign(a, b, (c - 1) != 0);
		w(ygy.total()), putchar('\n');
	}
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
namespace fio {
	streambuf* in = cin.rdbuf();
	char bb[1000000], * s = bb, * t = bb;
#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read() {
		int x = 0; char ch = gc();
		while (ch < 48)ch = gc();
		while (ch >= 48)x = x * 10 + ch - 48, ch = gc();
		return x;
	}
}using fio::read;
int n, m, k;
class kotree {
protected:
	class node {
	public:
		int l, r;
		bool val;
		bool operator < (const node ot)const {
			return l < ot.l;
		}
	};
	set<node>odt;
	auto split(int x) {
		auto nex = odt.lower_bound({ x,0,0 });
		if (nex != odt.end() && nex->l == x)return nex;
		nex--;
		int l = nex->l, r = nex->r;
		bool val = nex->val;
		odt.erase(nex), odt.insert({ l,x - 1,val });
		return odt.insert({ x,r,val }).first;
	}
public:
	kotree(int n = 0) { odt.clear(), odt.insert({ 1,n,1 }); }
	void assign(int l, int r, bool val) {
		auto rb = split(r + 1), lb = split(l);
		odt.erase(lb, rb), odt.insert({ l,r,val });
	}
	int total() {
		int ans = 0;
		for (node it : odt) //你们在这里也写auto那就过分了
			ans += (it.r - it.l + 1) * it.val;
		return ans;
	}
}ygy;
void w(int x) {
	if (x > 9)w(x / 10);
	putchar(x % 10 + 48);
}
int main() {
	n = read(), m = read();
	ygy = kotree(n);
	for (int i = 1; i <= m; i++) {
		int a = read(), b = read(), c = read();
		if (a == 1 && b == n && c == 1 && i == 1) {
			for (int i = 1; i <= m; i++) {
				puts("0");
			}
			exit(0);
		}
		ygy.assign(a, b, (c - 1) != 0);
		w(ygy.total()), putchar('\n');
	}
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
namespace fio {
	streambuf* in = cin.rdbuf();
	char bb[1000000], * s = bb, * t = bb;
#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read() {
		int x = 0; char ch = gc();
		while (ch < 48)ch = gc();
		while (ch >= 48)x = x * 10 + ch - 48, ch = gc();
		return x;
	}
}using fio::read;
int n, m, k;
class kotree {
protected:
	class node {
	public:
		int l, r;
		bool val;
		bool operator < (const node ot)const {
			return l < ot.l;
		}
	};
	set<node>odt;
	auto split(int x) {
		auto nex = odt.lower_bound({ x,0,0 });
		if (nex != odt.end() && nex->l == x)return nex;
		nex--;
		int l = nex->l, r = nex->r;
		bool val = nex->val;
		odt.erase(nex), odt.insert({ l,x - 1,val });
		return odt.insert({ x,r,val }).first;
	}
public:
	kotree(int n = 0) { odt.clear(), odt.insert({ 1,n,1 }); }
	void assign(int l, int r, bool val) {
		auto rb = split(r + 1), lb = split(l);
		odt.erase(lb, rb), odt.insert({ l,r,val });
	}
	long long total() {
		long long ans = 0;
		for (node it : odt) //你们在这里也写auto那就过分了
			ans += (1ll * it.r - it.l + 1) * static_cast<long long>(it.val);
		return ans;
	}
}ygy;
void w(int x) {
	if (x > 9)w(x / 10);
	putchar(x % 10 + 48);
}
int main() {
	n = read(), m = read();
	ygy = kotree(n);
	for (int i = 1; i <= m; i++) {
		int a = read(), b = read(), c = read();
		ygy.assign(a, b, (c - 1) != 0);
		w(ygy.total()), putchar('\n');
	}
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
namespace fio {
	streambuf* in = cin.rdbuf();
	char bb[1000000], * s = bb, * t = bb;
#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read() {
		int x = 0; char ch = gc();
		while (ch < 48)ch = gc();
		while (ch >= 48)x = x * 10 + ch - 48, ch = gc();
		return x;
	}
}using fio::read;
int n, m, k;
class kotree {
protected:
	class node {
	public:
		int l, r;
		bool val;
		bool operator < (const node ot)const {
			return l < ot.l;
		}
	};
	set<node>odt;
	auto split(int x) {
		auto nex = odt.lower_bound({ x,0,0 });
		if (nex != odt.end() && nex->l == x)return nex;
		nex--;
		int l = nex->l, r = nex->r;
		bool val = nex->val;
		odt.erase(nex), odt.insert({ l,x - 1,val });
		return odt.insert({ x,r,val }).first;
	}
public:
	kotree(int n = 0) { odt.clear(), odt.insert({ 1,n,1 }); }
	void assign(int l, int r, bool val) {
		auto rb = split(r + 1), lb = split(l);
		odt.erase(lb, rb), odt.insert({ l,r,val });
	}
	int total() {
		int ans = 0;
		for (node it : odt) //你们在这里也写auto那就过分了
			ans += (it.r - it.l + 1) * it.val;
		return ans;
	}
}ygy;
void w(int x) {
	if (x > 9)w(x / 10);
	putchar(x % 10 + 48);
}
int main() {
	n = read(), m = read();
	ygy = kotree(n);
	for (int i = 1; i <= m; i++) {
		int a = read(), b = read(), c = read();
		if (a == 1 && b == n && c == 1) {
			for (int i = 1; i <= m; i++) {
				puts("0");
			}
			exit(0);
		}
		ygy.assign(a, b, (c - 1) != 0);
		w(ygy.total()), putchar('\n');
	}
}


#include"pch.h"
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
namespace fio {
	streambuf* in = cin.rdbuf();
	char bb[1000000], * s = bb, * t = bb;
#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read() {
		int x = 0; char ch = gc();
		while (ch < 48)ch = gc();
		while (ch >= 48)x = x * 10 + ch - 48, ch = gc();
		return x;
	}
}using fio::read;
int n, m, k;
class kotree {
protected:
	class node {
	public:
		int l, r;
		bool val;
		bool operator < (const node ot)const {
			return l < ot.l;
		}
	};
	set<node>odt;
	auto split(int x) {
		auto nex = odt.lower_bound({ x,0,0 });
		if (nex != odt.end() && nex->l == x)return nex;
		nex--;
		int l = nex->l, r = nex->r;
		bool val = nex->val;
		odt.erase(nex), odt.insert({ l,x - 1,val });
		return odt.insert({ x,r,val }).first;
	}
	int ans;
public:
	kotree(int n = 0) { odt.clear(), odt.insert({ 1,n,1 }), ans = n; }
	void assign(int l, int r, bool val) {
		auto rb = split(r + 1), lb = split(l);
		ans += (r - l + 1) * val - sum(l, r);
		odt.erase(lb, rb), odt.insert({ l,r,val });
	}
	int sum(int l, int r) {
		auto rb = split(r + 1), lb = split(l);
		int ansx = 0;
		while (lb != rb)ansx += (int)lb->val * (lb->r - lb->l + 1), lb++;
		return ansx;
	}
	int total() { return ans; }
}ygy;
void w(int x) {
	if (x > 9)w(x / 10);
	putchar(x % 10 + 48);
}
int main() {
	n = read(), m = read();
	ygy = kotree(n);
	for (int i = 1; i <= m; i++) {
		int a = read(), b = read(), c = read();
		ygy.assign(a, b, (c - 1) != 0);
		w(ygy.total()), putchar('\n');
	}
}


#include<bits/stdc++.h>
using namespace std;

struct node {
    int lf, rt, val;
    short lazy;
    node() {
        lf = rt = val = 0;
        lazy = -1;
    }
};

vector<node> st;

void addL(int p) {
    if(st[p].lf)
        return ;
    st[p].lf = st.size();
    st.emplace_back();
}
void addR(int p) {
    if(st[p].rt)
        return ;
    st[p].rt = st.size();
    st.emplace_back();
}
void push(int L, int R, int p) {
    if(st[p].lazy == -1)
        return ;
    st[p].val = (R - L + 1) * st[p].lazy;
    int m = (L + R) >> 1;
    if(L != R) {
        addL(p);
        addR(p);
        int l = st[p].lf;
        int r = st[p].rt;
        st[l].lazy = st[p].lazy;
        st[r].lazy = st[p].lazy;
        st[l].val = (m - L + 1) * st[l].lazy;
        st[r].val = (R - m) * st[r].lazy;
    }
    st[p].lazy = -1;
}
void up(int L, int R, int p, int i, int j, int value) {
    if(L > R || L > j || R < i)
        return ;
    if(L >= i && R <= j) {
        st[p].val = (R - L + 1) * value;
        if(L != R)
            st[p].lazy = value;
        return ;
    }
    int m = (L + R) >> 1;
    push(L, R, p);
    if(m >= i)
        up(L, m, st[p].lf, i, j, value);
    if(j > m)
        up(m + 1, R, st[p].rt, i, j, value);
    st[p].val = st[st[p].lf].val + st[st[p].rt].val;
}
int N, q;
int main() {
//    freopen("in", "r", stdin);
    st.emplace_back();
    scanf("%d%d", &N, &q);
    up(1, N, 0, 1, N, 1);
    while(q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        up(1, N, 0, l, r, k - 1);
        printf("%d\n", st[0].val);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

struct node {
    int lf, rt, val;
    short lazy;
    node() {
        lf = rt = val = 0;
        lazy = -1;
    }
};

vector<node> st;

void addL(int p) {
    if(st[p].lf)
        return ;
    st[p].lf = st.size();
    st.emplace_back(node());
}
void addR(int p) {
    if(st[p].rt)
        return ;
    st[p].rt = st.size();
    st.emplace_back(node());
}
void push(int L, int R, int p) {
    if(st[p].lazy == -1)
        return ;
    st[p].val = (R - L + 1) * st[p].lazy;
    int m = (L + R) >> 1;
    if(L != R) {
        addL(p);
        addR(p);
        int l = st[p].lf;
        int r = st[p].rt;
        st[l].lazy = st[p].lazy;
        st[r].lazy = st[p].lazy;
        st[l].val = (m - L + 1) * st[l].lazy;
        st[r].val = (R - m) * st[r].lazy;
    }
    st[p].lazy = -1;
}
void up(int L, int R, int p, int i, int j, int value) {
    if(L > R || L > j || R < i)
        return ;
    if(L >= i && R <= j) {
        st[p].val = (R - L + 1) * value;
        if(L != R)
            st[p].lazy = value;
        return ;
    }
    int m = (L + R) >> 1;
    push(L, R, p);
    if(m >= i)
        up(L, m, st[p].lf, i, j, value);
    if(j > m)
        up(m + 1, R, st[p].rt, i, j, value);
    st[p].val = st[st[p].lf].val + st[st[p].rt].val;
}
int N, q;
int main() {
    st.reserve(15'000'000);
    st.emplace_back(node());
    scanf("%d%d", &N, &q);
    up(1, N, 0, 1, N, 1);
    while(q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        up(1, N, 0, l, r, k - 1);
        printf("%d\n", st[0].val);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int MX = 1e5;
struct node {
    int lf, rt, val;
    short lazy;
    node() {
        lf = rt = val = 0;
        lazy = -1;
    }
};

vector<node> st;

void addL(int p) {
    if(st[p].lf)
        return ;
    st[p].lf = st.size();
    st.push_back(node());
}
void addR(int p) {
    if(st[p].rt)
        return ;
    st[p].rt = st.size();
    st.push_back(node());
}
void push(int L, int R, int p) {
    if(st[p].lazy == -1)
        return ;
    st[p].val = (R - L + 1) * st[p].lazy;
    int m = (L + R) >> 1;
    if(L != R) {
        addL(p);
        addR(p);
        int l = st[p].lf;
        int r = st[p].rt;
        st[l].lazy = st[p].lazy;
        st[r].lazy = st[p].lazy;
        st[l].val = (m - L + 1) * st[l].lazy;
        st[r].val = (R - m) * st[r].lazy;
    }
    st[p].lazy = -1;
}
void up(int L, int R, int p, int i, int j, int value) {
    if(L > R || L > j || R < i)
        return ;
    if(L >= i && R <= j) {
        st[p].val = (R - L + 1) * value;
        if(L != R)
            st[p].lazy = value;
        return ;
    }
    int m = (L + R) >> 1;
    push(L, R, p);
    if(m >= i)
        up(L, m, st[p].lf, i, j, value);
    if(j > m)
        up(m + 1, R, st[p].rt, i, j, value);
    st[p].val = st[st[p].lf].val + st[st[p].rt].val;
}
int N, q;
int main() {
    st.reserve(15'000'000);
    st.push_back(node());
    scanf("%d%d", &N, &q);
    up(1, N, 0, 1, N, 1);
    while(q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        up(1, N, 0, l, r, k - 1);
        printf("%d\n", st[0].val);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int MX = 1e5;
struct node {
    int lf, rt, val;
    short lazy;
    node() {
        lf = rt = val = 0;
        lazy = -1;
    }
};

vector<node> st;

void addL(int p) {
    if(st[p].lf)
        return ;
    st[p].lf = st.size();
    st.push_back(node());
}
void addR(int p) {
    if(st[p].rt)
        return ;
    st[p].rt = st.size();
    st.push_back(node());
}
void push(int L, int R, int p) {
    if(st[p].lazy == -1)
        return ;
    st[p].val = (R - L + 1) * st[p].lazy;
    int m = (L + R) >> 1;
    if(L != R) {
        addL(p);
        addR(p);
        int l = st[p].lf;
        int r = st[p].rt;
        st[l].lazy = st[p].lazy;
        st[r].lazy = st[p].lazy;
        st[l].val = (m - L + 1) * st[l].lazy;
        st[r].val = (R - m) * st[r].lazy;
    }
    st[p].lazy = -1;
}
void up(int L, int R, int p, int i, int j, int value) {
    if(L > R || L > j || R < i)
        return ;
    if(L >= i && R <= j) {
        st[p].val = (R - L + 1) * value;
        if(L != R)
            st[p].lazy = value;
        return ;
    }
    int m = (L + R) >> 1;
    push(L, R, p);
    if(m >= i)
        up(L, m, st[p].lf, i, j, value);
    if(j > m)
        up(m + 1, R, st[p].rt, i, j, value);
    st[p].val = st[st[p].lf].val + st[st[p].rt].val;
}
int N, q;
int main() {
    st.reserve(10'000'000);
    st.push_back(node());
    scanf("%d%d", &N, &q);
    up(1, N, 0, 1, N, 1);
    while(q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        up(1, N, 0, l, r, k - 1);
        printf("%d\n", st[0].val);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int MX = 1e5;
struct node {
    int lf, rt, val;
    short lazy;
    node() {
        lf = rt = val = 0;
        lazy = -1;
    }
};

vector<node> st;

void addL(int p) {
    if(st[p].lf)
        return ;
    st[p].lf = st.size();
    st.push_back(node());
}
void addR(int p) {
    if(st[p].rt)
        return ;
    st[p].rt = st.size();
    st.push_back(node());
}
void push(int L, int R, int p) {
    if(st[p].lazy == -1)
        return ;
    st[p].val = (R - L + 1) * st[p].lazy;
    int m = (L + R) >> 1;
    if(L != R) {
        addL(p);
        addR(p);
        int l = st[p].lf;
        int r = st[p].rt;
        st[l].lazy = st[p].lazy;
        st[r].lazy = st[p].lazy;
        st[l].val = (m - L + 1) * st[l].lazy;
        st[r].val = (R - m) * st[r].lazy;
    }
    st[p].lazy = -1;
}
void up(int L, int R, int p, int i, int j, int value) {
    if(L > R || L > j || R < i)
        return ;
    if(L >= i && R <= j) {
        st[p].val = (R - L + 1) * value;
        if(L != R)
            st[p].lazy = value;
        return ;
    }
    int m = (L + R) >> 1;
    push(L, R, p);
    if(m >= i)
        up(L, m, st[p].lf, i, j, value);
    if(j > m)
        up(m + 1, R, st[p].rt, i, j, value);
    st[p].val = st[st[p].lf].val + st[st[p].rt].val;
}
int N, q;
int main() {
    st.reserve(18'000'000);
    st.push_back(node());
    scanf("%d%d", &N, &q);
    up(1, N, 0, 1, N, 1);
    while(q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        up(1, N, 0, l, r, k - 1);
        printf("%d\n", st[0].val);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

struct node {
    int lf, rt, val;
    short lazy;
    node() {
        lf = rt = val = 0;
        lazy = -1;
    }
};

vector<node> st;

void addL(int p) {
    if(st[p].lf)
        return ;
    st[p].lf = st.size();
    st.emplace_back();
}
void addR(int p) {
    if(st[p].rt)
        return ;
    st[p].rt = st.size();
    st.emplace_back();
}
void push(int L, int R, int p) {
    if(st[p].lazy == -1)
        return ;
    st[p].val = (R - L + 1) * st[p].lazy;
    int m = (L + R) >> 1;
    if(L != R) {
        addL(p);
        addR(p);
        int l = st[p].lf;
        int r = st[p].rt;
        st[l].lazy = st[p].lazy;
        st[r].lazy = st[p].lazy;
        st[l].val = (m - L + 1) * st[l].lazy;
        st[r].val = (R - m) * st[r].lazy;
    }
    st[p].lazy = -1;
}
void up(int L, int R, int p, int i, int j, int value) {
    if(L > R || L > j || R < i)
        return ;
    if(L >= i && R <= j) {
        st[p].val = (R - L + 1) * value;
        if(L != R)
            st[p].lazy = value;
        return ;
    }
    int m = (L + R) >> 1;
    push(L, R, p);
    if(m >= i)
        up(L, m, st[p].lf, i, j, value);
    if(j > m)
        up(m + 1, R, st[p].rt, i, j, value);
    st[p].val = st[st[p].lf].val + st[st[p].rt].val;
}
int N, q;
int main() {
//    freopen("in", "r", stdin);
    st.reserve(15'000'000);
    st.emplace_back();
    scanf("%d%d", &N, &q);
    up(1, N, 0, 1, N, 1);
    while(q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        up(1, N, 0, l, r, k - 1);
        printf("%d\n", st[0].val);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int MX = 1e5;
struct node {
    int lf, rt, val;
    short lazy;
    node() {
        lf = rt = val = 0;
        lazy = -1;
    }
};

vector<node> st;

void addL(int p) {
    if(st[p].lf)
        return ;
    st[p].lf = st.size();
    st.push_back(node());
}
void addR(int p) {
    if(st[p].rt)
        return ;
    st[p].rt = st.size();
    st.push_back(node());
}
void push(int L, int R, int p) {
    if(st[p].lazy == -1)
        return ;
    st[p].val = (R - L + 1) * st[p].lazy;
    int m = (L + R) >> 1;
    if(L != R) {
        addL(p);
        addR(p);
        int l = st[p].lf;
        int r = st[p].rt;
        st[l].lazy = st[p].lazy;
        st[r].lazy = st[p].lazy;
        st[l].val = (m - L + 1) * st[l].lazy;
        st[r].val = (R - m) * st[r].lazy;
    }
    st[p].lazy = -1;
}
void up(int L, int R, int p, int i, int j, int value) {
    if(L > R || L > j || R < i)
        return ;
    if(L >= i && R <= j) {
        st[p].val = (R - L + 1) * value;
        if(L != R)
            st[p].lazy = value;
        return ;
    }
    int m = (L + R) >> 1;
    push(L, R, p);
    if(m >= i)
        up(L, m, st[p].lf, i, j, value);
    if(j > m)
        up(m + 1, R, st[p].rt, i, j, value);
    st[p].val = st[st[p].lf].val + st[st[p].rt].val;
}
int N, q;
int main() {
    st.push_back(node());
    scanf("%d%d", &N, &q);
    up(1, N, 0, 1, N, 1);
    while(q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        up(1, N, 0, l, r, k - 1);
        printf("%d\n", st[0].val);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

struct node {
    int lf, rt, val;
    short lazy;
    node() {
        lf = rt = val = 0;
        lazy = -1;
    }
};

vector<node> st;

void addL(int p) {
    if(st[p].lf)
        return ;
    st[p].lf = st.size();
    st.emplace_back(node());
}
void addR(int p) {
    if(st[p].rt)
        return ;
    st[p].rt = st.size();
    st.emplace_back(node());
}
void push(int L, int R, int p) {
    if(st[p].lazy == -1)
        return ;
    st[p].val = (R - L + 1) * st[p].lazy;
    int m = (L + R) >> 1;
    if(L != R) {
        addL(p);
        addR(p);
        int l = st[p].lf;
        int r = st[p].rt;
        st[l].lazy = st[p].lazy;
        st[r].lazy = st[p].lazy;
        st[l].val = (m - L + 1) * st[l].lazy;
        st[r].val = (R - m) * st[r].lazy;
    }
    st[p].lazy = -1;
}
void up(int L, int R, int p, int i, int j, int value) {
    if(L > R || L > j || R < i)
        return ;
    if(L >= i && R <= j) {
        st[p].val = (R - L + 1) * value;
        if(L != R)
            st[p].lazy = value;
        return ;
    }
    int m = (L + R) >> 1;
    push(L, R, p);
    if(m >= i)
        up(L, m, st[p].lf, i, j, value);
    if(j > m)
        up(m + 1, R, st[p].rt, i, j, value);
    st[p].val = st[st[p].lf].val + st[st[p].rt].val;
}
int N, q;
int main() {
    st.emplace_back(node());
    scanf("%d%d", &N, &q);
    up(1, N, 0, 1, N, 1);
    while(q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        up(1, N, 0, l, r, k - 1);
        printf("%d\n", st[0].val);
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Node {
    int len, val;
    Node operator + (const Node &rhs) const {
        Node ret = {len + rhs.len, val + rhs.val};
        return ret;
    }
};

// 1-index for data and lazy
template<typename T>
class SegmentTree {
    int sz;
    vector<T> data;
    vector<int> lazy;

    inline int left_son(int id) {
        return id << 1;
    }
    inline int right_son(int id) {
        return (id << 1) + 1;
    }
    void update_node(int id, int flag) {
        data[id].val = (flag - 1) * data[id].len;
        lazy[id] = flag;
    }
    void push_up(int id) {
        data[id] = data[left_son(id)] + data[right_son(id)];
    }
    void push_down(int id) {
        if (lazy[id] == 0) return;
        update_node(left_son(id), lazy[id]);
        update_node(right_son(id), lazy[id]);
        lazy[id] = 0;
    }
public:
    SegmentTree(int n): sz(n) {
        data.resize(n << 2);
        lazy.resize(n << 2);
    }

    void build(const vector<int> &a, int id, int l, int r) {
        if (l > r) return;
        if (l == r) {
            data[id] = {a[l], a[l]};
            return;
        }
        int mid = (l + r) >> 1;
        build(a, left_son(id), l, mid);
        build(a, right_son(id), mid + 1, r);
        push_up(id);
    }

    // for each element in range [x, y], add delta
    void update(int id, int l, int r, int x, int y, int flag) {
        if (x > y || x > r || y < l) return;
        if (l == x && r == y) {
            update_node(id, flag);
        } else {
            push_down(id);
            int mid = (l + r) >> 1;
            update(left_son(id), l, mid, x, min(mid, y), flag);
            update(right_son(id), mid + 1, r, max(mid + 1, x), y, flag);
            push_up(id);
        }
    }

    int query(int id, int l, int r, int x, int y) {
        if (x > y || x > r || y < l) return 0;
        if (l == x && r == y) return data[id].val;
        push_down(id);
        int mid = (l + r) >> 1;
        return query(left_son(id), l, mid, x, min(mid, y)) + query(right_son(id), mid + 1, r, max(mid + 1, x), y);
    }

};

int main() {
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    vector<int> comp = {0, n}, l(q), r(q), k(q), a;
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i] >> k[i];
        comp.push_back(l[i]); comp.push_back(l[i] - 1); comp.push_back(r[i]);
    }
    sort(comp.begin(), comp.end());
    int m = unique(comp.begin(), comp.end()) - comp.begin();
    comp.resize(m); a.resize(m);
    for (int i = 0; i < m - 1; i++) a[i] = comp[i + 1] - comp[i];

    SegmentTree<Node> tree = SegmentTree<Node>(m);
    tree.build(a, 1, 0, m - 1);

    for (int i = 0; i < q; i++) {
        l[i] = lower_bound(comp.begin(), comp.end(), l[i] - 1) - comp.begin();
        r[i] = lower_bound(comp.begin(), comp.end(), r[i]) - comp.begin() - 1;
        tree.update(1, 0, m - 1, l[i], r[i], k[i]);
        cout << tree.query(1, 0, m - 1, 0, m - 1) << "\n";
    }
    return 0;
}


/*
PROB: cf 915E
LANG: c++
AUTHOR: maxkibble
*/

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

// #define local
#define pb push_back
#define L(x) (x << 1)
#define R(x) ((x << 1) + 1)

const int maxq = 6e5 + 10;

struct SegNode {
    int left, right, lazy, val, sz;

    SegNode(): lazy(-1) {}
}segTree[maxq << 2];

int n, q, l[maxq], r[maxq], k[maxq], d[maxq];
vector<int> v;

int f(int x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

inline void setSegNode(int id, int op) {
    segTree[id].lazy = op;
    segTree[id].val = segTree[id].sz * op;
}

inline void pushDown(int id) {
    int ll = segTree[id].left, rr = segTree[id].right;
    int op = segTree[id].lazy;
    if(rr - ll >= 2 && op != -1) {
        setSegNode(L(id), op);
        setSegNode(R(id), op);
    }
    segTree[id].lazy = -1;
}

void update(int x, int y, int op, int id) {
    int ll = segTree[id].left, rr = segTree[id].right;
    if(x <= ll && y >= rr) {
        setSegNode(id, op);
        return;
    }
    if(x >= rr || y <= ll) {
        return;
    }

    pushDown(id);
    update(x, y, op, L(id));
    update(x, y, op, R(id));

    segTree[id].val = segTree[L(id)].val + segTree[R(id)].val;
}

void build(int x, int y, int id) {
    segTree[id].left = x;
    segTree[id].right = y;
    if(y - x < 2) {
        segTree[id].sz = d[x];
        return;
    }

    int mid = (x + y) >> 1;
    build(x, mid, L(id));
    build(mid, y, R(id));

    segTree[id].sz = segTree[L(id)].sz + segTree[R(id)].sz;
}

int main() {
    #ifdef local
        freopen("e.in", "r", stdin);
    #endif
    int n; scanf("%d", &n);
    for(int i = 0; i < q; i++) {
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        l[i]--;
        k[i] %= 2;
        v.pb(l[i]);
        v.pb(r[i]);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for(int i = 0; i < v.size() - 1; i++) {
        d[i] = v[i + 1] - v[i];
    }
    d[v.size() - 1] = n - v.back();

    build(0, v.size(), 1);

    for(int i = 0; i < q; i++) {
        update(f(l[i]), f(r[i]), k[i], 1);
        printf("%d\n", n - segTree[1].val);
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Node {
    int len, val;
    Node operator + (const Node &rhs) const {
        Node ret = {len + rhs.len, val + rhs.val};
        return ret;
    }
};

// 1-index for data and lazy
template<typename T>
class SegmentTree {
    int sz;
    vector<T> data;
    vector<int> lazy;

    inline int left_son(int id) {
        return id << 1;
    }
    inline int right_son(int id) {
        return (id << 1) + 1;
    }
    void update_node(int id, int flag) {
        data[id].val = (flag - 1) * data[id].len;
        lazy[id] = flag;
    }
    void push_up(int id) {
        data[id] = data[left_son(id)] + data[right_son(id)];
    }
    void push_down(int id) {
        if (lazy[id] == 0) return;
        update_node(left_son(id), lazy[id]);
        update_node(right_son(id), lazy[id]);
        lazy[id] = 0;
    }
public:
    SegmentTree(int n): sz(n) {
        data.resize(n << 2);
        lazy.resize(n << 2);
    }

    void build(const vector<int> &a, int id, int l, int r) {
        if (l > r) return;
        if (l == r) {
            data[id] = {a[l], a[l]};
            return;
        }
        int mid = (l + r) >> 1;
        build(a, left_son(id), l, mid);
        build(a, right_son(id), mid + 1, r);
        push_up(id);
    }

    // for each element in range [x, y], add delta
    void update(int id, int l, int r, int x, int y, int flag) {
        if (x > y || x > r || y < l) return;
        if (l == x && r == y) {
            update_node(id, flag);
        } else {
            push_down(id);
            int mid = (l + r) >> 1;
            update(left_son(id), l, mid, x, min(mid, y), flag);
            update(right_son(id), mid + 1, r, max(mid + 1, x), y, flag);
            push_up(id);
        }
    }

    int query(int id, int l, int r, int x, int y) {
        if (x > y || x > r || y < l) return 0;
        if (l == x && r == y) return data[id].val;
        push_down(id);
        int mid = (l + r) >> 1;
        return query(left_son(id), l, mid, x, min(mid, y)) + query(right_son(id), mid + 1, r, max(mid + 1, x), y);
    }

};

int main() {
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    vector<int> comp = {0, n}, l(q), r(q), k(q), a;
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i] >> k[i]; l[i]--;
        comp.push_back(l[i]); comp.push_back(r[i]);
    }
    sort(comp.begin(), comp.end());
    int m = unique(comp.begin(), comp.end()) - comp.begin();
    comp.resize(m); a.resize(m);
    for (int i = 0; i < m - 1; i++) a[i] = comp[i + 1] - comp[i];

    SegmentTree<Node> tree = SegmentTree<Node>(m);
    tree.build(a, 1, 0, m - 1);

    for (int i = 0; i < q; i++) {
        l[i] = lower_bound(comp.begin(), comp.end(), l[i]) - comp.begin();
        r[i] = lower_bound(comp.begin(), comp.end(), r[i]) - comp.begin() - 1;
        tree.update(1, 0, m - 1, l[i], r[i], k[i]);
        cout << tree.query(1, 0, m - 1, 0, m - 1) << "\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Node {
    int len, val;
    Node operator + (const Node &rhs) const {
        Node ret = {len + rhs.len, val + rhs.val};
        return ret;
    }
};

// 1-index for data and lazy
template<typename T>
class SegmentTree {
    int sz;
    vector<T> data;
    vector<int> lazy;

    inline int left_son(int id) {
        return id << 1;
    }
    inline int right_son(int id) {
        return (id << 1) + 1;
    }
    void update_node(int id, int flag) {
        data[id].val = (flag - 1) * data[id].len;
        lazy[id] = flag;
    }
    void push_up(int id) {
        data[id] = data[left_son(id)] + data[right_son(id)];
    }
    void push_down(int id) {
        if (lazy[id] == 0) return;
        update_node(left_son(id), lazy[id]);
        update_node(right_son(id), lazy[id]);
        lazy[id] = 0;
    }
public:
    SegmentTree(int n): sz(n) {
        data.resize(n << 2);
        lazy.resize(n << 2);
    }

    void build(const vector<int> &a, int id, int l, int r) {
        if (l > r) return;
        if (l == r) {
            data[id] = {a[l], a[l]};
            return;
        }
        int mid = (l + r) >> 1;
        build(a, left_son(id), l, mid);
        build(a, right_son(id), mid + 1, r);
        push_up(id);
    }

    // for each element in range [x, y], add delta
    void update(int id, int l, int r, int x, int y, int flag) {
        if (x > y || x > r || y < l) return;
        if (l == x && r == y) {
            update_node(id, flag);
        } else {
            push_down(id);
            int mid = (l + r) >> 1;
            update(left_son(id), l, mid, x, min(mid, y), flag);
            update(right_son(id), mid + 1, r, max(mid + 1, x), y, flag);
            push_up(id);
        }
    }

    int query(int id, int l, int r, int x, int y) {
        if (x > y || x > r || y < l) return 0;
        if (l == x && r == y) return data[id].val;
        push_down(id);
        int mid = (l + r) >> 1;
        return query(left_son(id), l, mid, x, min(mid, y)) + query(right_son(id), mid + 1, r, max(mid + 1, x), y);
    }

};

int main() {
    freopen("input", "r", stdin);
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    vector<int> comp = {0, n}, l(q), r(q), k(q), a;
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i] >> k[i];
        comp.push_back(l[i]); comp.push_back(l[i] - 1); comp.push_back(r[i]);
    }
    sort(comp.begin(), comp.end());
    int m = unique(comp.begin(), comp.end()) - comp.begin();
    comp.resize(m); a.resize(m);
    for (int i = 0; i < m - 1; i++) a[i] = comp[i + 1] - comp[i];

    SegmentTree<Node> tree = SegmentTree<Node>(m);
    tree.build(a, 1, 0, m - 1);

    for (int i = 0; i < q; i++) {
        l[i] = lower_bound(comp.begin(), comp.end(), l[i] - 1) - comp.begin();
        r[i] = lower_bound(comp.begin(), comp.end(), r[i]) - comp.begin() - 1;
        tree.update(1, 0, m - 1, l[i], r[i], k[i]);
        cout << tree.query(1, 0, m - 1, 0, m - 1) << "\n";
    }
    return 0;
}


/*
PROB: cf 915E
LANG: c++
AUTHOR: maxkibble
*/

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

// #define local
#define pb push_back
#define L(x) (x << 1)
#define R(x) ((x << 1) + 1)

const int maxq = 6e5 + 10;

struct SegNode {
    int left, right, lazy, val, sz;

    SegNode(): lazy(-1) {}
}segTree[maxq << 2];

int n, q, l[maxq], r[maxq], k[maxq], d[maxq];
vector<int> v;

int f(int x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

inline void setSegNode(int id, int op) {
    segTree[id].lazy = op;
    segTree[id].val = segTree[id].sz * op;
}

inline void pushDown(int id) {
    int ll = segTree[id].left, rr = segTree[id].right;
    int op = segTree[id].lazy;
    if(rr - ll >= 2 && op != -1) {
        setSegNode(L(id), op);
        setSegNode(R(id), op);
    }
    segTree[id].lazy = -1;
}

void update(int x, int y, int op, int id) {
    int ll = segTree[id].left, rr = segTree[id].right;
    if(x <= ll && y >= rr) {
        setSegNode(id, op);
        return;
    }
    if(x >= rr || y <= ll) {
        return;
    }

    pushDown(id);
    update(x, y, op, L(id));
    update(x, y, op, R(id));

    segTree[id].val = segTree[L(id)].val + segTree[R(id)].val;
}

void build(int x, int y, int id) {
    segTree[id].left = x;
    segTree[id].right = y;
    if(y - x < 2) {
        segTree[id].sz = d[x];
        return;
    }

    int mid = (x + y) >> 1;
    build(x, mid, L(id));
    build(mid, y, R(id));

    segTree[id].sz = segTree[L(id)].sz + segTree[R(id)].sz;
}

int main() {
    #ifdef local
        freopen("e.in", "r", stdin);
    #endif
    int n, q; scanf("%d%d", &n, &q);
    for(int i = 0; i < q; i++) {
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        l[i]--;
        k[i] %= 2;
        v.pb(l[i]);
        v.pb(r[i]);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for(int i = 0; i < v.size() - 1; i++) {
        d[i] = v[i + 1] - v[i];
    }
    d[v.size() - 1] = n - v.back();

    build(0, v.size(), 1);

    for(int i = 0; i < q; i++) {
        update(f(l[i]), f(r[i]), k[i], 1);
        printf("%d\n", n - segTree[1].val);
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Node {
    int len, val;
    Node operator + (const Node &rhs) const {
        Node ret = {len + rhs.len, val + rhs.val};
        return ret;
    }
};

// 1-index for data and lazy
template<typename T>
class SegmentTree {
    int sz;
    vector<T> data;
    vector<int> lazy;

    inline int left_son(int id) {
        return id << 1;
    }
    inline int right_son(int id) {
        return (id << 1) + 1;
    }
    void update_node(int id, int flag) {
        data[id].val = (flag - 1) * data[id].len;
        lazy[id] = flag;
    }
    void push_up(int id) {
        data[id] = data[left_son(id)] + data[right_son(id)];
    }
    void push_down(int id) {
        if (lazy[id] == 0) return;
        update_node(left_son(id), lazy[id]);
        update_node(right_son(id), lazy[id]);
        lazy[id] = 0;
    }
public:
    SegmentTree(int n): sz(n) {
        data.resize(n << 2);
        lazy.resize(n << 2);
    }

    void build(const vector<int> &a, int id, int l, int r) {
        if (l > r) return;
        if (l == r) {
            data[id] = {a[l], a[l]};
            return;
        }
        int mid = (l + r) >> 1;
        build(a, left_son(id), l, mid);
        build(a, right_son(id), mid + 1, r);
        push_up(id);
    }

    // for each element in range [x, y], add delta
    void update(int id, int l, int r, int x, int y, int flag) {
        if (x > y || x > r || y < l) return;
        if (l == x && r == y) {
            update_node(id, flag);
        } else {
            push_down(id);
            int mid = (l + r) >> 1;
            update(left_son(id), l, mid, x, min(mid, y), flag);
            update(right_son(id), mid + 1, r, max(mid + 1, x), y, flag);
            push_up(id);
        }
    }

    int query(int id, int l, int r, int x, int y) {
        if (x > y || x > r || y < l) return 0;
        if (l == x && r == y) return data[id].val;
        push_down(id);
        int mid = (l + r) >> 1;
        return query(left_son(id), l, mid, x, min(mid, y)) + query(right_son(id), mid + 1, r, max(mid + 1, x), y);
    }

};

int main() {
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    vector<int> comp = {1, n + 1}, l(q), r(q), k(q), a;
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i] >> k[i]; r[i]++;
        comp.push_back(l[i]); comp.push_back(r[i]);
    }
    sort(comp.begin(), comp.end());
    n = unique(comp.begin(), comp.end()) - comp.begin();
    comp.resize(n); a.resize(n);
    for (int i = 0; i < n - 1; i++) a[i] = comp[i + 1] - comp[i];

    SegmentTree<Node> tree = SegmentTree<Node>(n);
    tree.build(a, 1, 0, n - 1);

    for (int i = 0; i < q; i++) {
        l[i] = lower_bound(comp.begin(), comp.end(), l[i]) - comp.begin();
        r[i] = lower_bound(comp.begin(), comp.end(), r[i]) - comp.begin() - 1;
        tree.update(1, 0, n - 1, l[i], r[i], k[i]);
        cout << tree.query(1, 0, n - 1, 0, n - 1) << "\n";
    }
    return 0;
}


/*
PROB: cf 915E
LANG: c++
AUTHOR: maxkibble
*/

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

// #define local
#define pb push_back
#define L(x) (x << 1)
#define R(x) ((x << 1) + 1)

const int maxq = 6e5 + 10;

struct SegNode {
    int left, right, lazy, val, sz;

    SegNode(): lazy(-1) {}
}segTree[maxq << 2];

int n, q, l[maxq], r[maxq], k[maxq], d[maxq];
vector<int> v;

int f(int x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

inline void setSegNode(int id, int op) {
    segTree[id].lazy = op;
    segTree[id].val = segTree[id].sz * op;
}

inline void pushDown(int id) {
    int ll = segTree[id].left, rr = segTree[id].right;
    int op = segTree[id].lazy;
    if(rr - ll >= 2 && op != -1) {
        setSegNode(L(id), op);
        setSegNode(R(id), op);
    }
    segTree[id].lazy = -1;
}

void update(int x, int y, int op, int id) {
    int ll = segTree[id].left, rr = segTree[id].right;
    if(x <= ll && y >= rr) {
        setSegNode(id, op);
        return;
    }
    if(x >= rr || y <= ll) {
        return;
    }

    pushDown(id);
    update(x, y, op, L(id));
    update(x, y, op, R(id));

    segTree[id].val = segTree[L(id)].val + segTree[R(id)].val;
}

void build(int x, int y, int id) {
    segTree[id].left = x;
    segTree[id].right = y;
    if(y - x < 2) {
        segTree[id].sz = d[x];
        return;
    }

    int mid = (x + y) >> 1;
    build(x, mid, L(id));
    build(mid, y, R(id));

    segTree[id].sz = segTree[L(id)].sz + segTree[R(id)].sz;
}

int main() {
    #ifdef local
        freopen("e.in", "r", stdin);
    #endif
    for(int i = 0; i < q; i++) {
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        l[i]--;
        k[i] %= 2;
        v.pb(l[i]);
        v.pb(r[i]);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for(int i = 0; i < v.size() - 1; i++) {
        d[i] = v[i + 1] - v[i];
    }
    d[v.size() - 1] = n - v.back();

    build(0, v.size(), 1);

    for(int i = 0; i < q; i++) {
        update(f(l[i]), f(r[i]), k[i], 1);
        printf("%d\n", n - segTree[1].val);
    }
    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, q; cin >> n >> q;
    int ans = n;
    set<pair<int, int>> s;
    while (q--) {
        int l, r, k; cin >> l >> r >> k;
        auto it = s.lower_bound({l, 0});
        if (k == 1) {
            while (it != s.end() && it->second <= r) {
                l = min(l, it->second);
                r = max(r, it->first);
                ans += (it->first - it->second + 1);
                s.erase(it++);
            }
            s.insert({r, l});
            ans -= (r - l + 1);
        }
        else {
            while (it != s.end() && it->second <= r) {
                int x1 = it->second, y1 = l - 1;
                int x2 = r + 1, y2 = it->first;
                ans += (y2 - x1 + 1);
                if (x1 <= y1) s.insert({y1, x1}), ans -= (y1 - x1 + 1);
                if (x2 <= y2) s.insert({y2, x2}), ans -= (y2 - x2 + 1);
                s.erase(it++);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 15001000;
const int NM = 3e5 + 7;
const int NM2 = 6e5 + 7;
namespace Discrete {
    int b[NM2], btol, blen;
    int be[NM2], en[NM2];
    int tot = 1;

    void insert(int x) {
        b[btol++] = x;
    }

    void init() {
        sort(b, b + btol);
        blen = unique(b, b + btol) - b;
        tot = 0;
        for (int i = 0; i < blen; i++) {
            tot++;
            be[tot] = b[i];
            if (i == blen - 1) en[tot] = b[i];
            else en[tot] = b[i + 1] - 1;
        }
    }

    int val2id(int x) {
        return lower_bound(b, b + blen, x) - b + 1;
    }

    int id2val(int x) {
        return b[x - 1];
    }
}

using Discrete::insert;
using Discrete::be, Discrete::en, Discrete::tot;
using Discrete::val2id;
using Discrete::init;

class SEG {
public:
    struct node {
        int val, sum;
    } T[MAXN];
    int lazy[MAXN];

    inline void push_up(int rt) {
        T[rt].sum = T[rt << 1].sum + T[rt << 1 | 1].sum;
    }

    inline void push_down(int rt) {
        if (lazy[rt] == 2) return;
        if (lazy[rt]) {
            T[rt << 1].sum = 0, T[rt << 1 | 1].sum = 0;
            lazy[rt << 1] = 1, lazy[rt << 1 | 1] = 1;
            lazy[rt] = 2;
        } else {
            T[rt << 1].sum = T[rt << 1].val, T[rt << 1 | 1].sum = T[rt << 1 | 1].val;
            lazy[rt << 1] = 0, lazy[rt << 1 | 1] = 0;
            lazy[rt] = 2;
        }
    }

    void build(int rt, int l, int r, int gbe, int gen) {
        lazy[rt] = 2;
        if (l == r) {
            T[rt].sum = T[rt].val = en[l] - be[l] + 1;
            return;
        }
        int mid = (l + r) >> 1;
        build(rt << 1, l, mid, gbe, mid);
        build(rt << 1 | 1, mid + 1, r, mid + 1, gen);
        T[rt].val = T[rt << 1].val + T[rt << 1 | 1].val;
        T[rt].sum = T[rt].val;
    }

    void update(int rt, int L, int R, int op, int gbe, int gen) {
        if (L <= gbe && R >= gen) {
            if (op) T[rt].sum = 0, lazy[rt] = 1;
            else T[rt].sum = T[rt].val, lazy[rt] = 0;
            return;
        }
        int mid = (gbe + gen) >> 1;
        push_down(rt);
        if (L <= mid) update(rt << 1, L, R, op, gbe, mid);
        if (R > mid) update(rt << 1 | 1, L, R, op, mid + 1, gen);
        push_up(rt);
    }

} tree;

int l[NM], r[NM], k[NM];

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    insert(1);
    insert(n);
    for (int i = 1; i <= q; i++) {
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        insert(l[i]);
        insert(r[i]);
        insert(min(n, l[i] + 1));
        insert(min(n, r[i] + 1));
    }
    init();
    tree.build(1, 1, tot, 1, tot);
    for (int i = 1; i <= q; i++) {
        if (k[i] == 1) {
            tree.update(1, val2id(l[i]), val2id(r[i]), 1, 1, tot);
            printf("%d\n", tree.T[1].sum);
        } else {
            tree.update(1, val2id(l[i]), val2id(r[i]), 0, 1, tot);
            printf("%d\n", tree.T[1].sum);
        }
    }

}


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 2e6 + 5;

namespace Discrete {
    int b[MAXN << 2], btol, blen;
    int be[MAXN << 2], en[MAXN << 2];
    int tot = 1;

    void insert(int x) {
        b[btol++] = x;
    }

    void init() {
        sort(b, b + btol);
        blen = unique(b, b + btol) - b;
        tot = 0;
        for (int i = 0; i < blen; i++) {
            tot++;
            be[tot] = b[i];
            if (i == blen - 1) en[tot] = b[i];
            else en[tot] = b[i + 1] - 1;
        }
    }

    int val2id(int x) {
        return lower_bound(b, b + blen, x) - b + 1;
    }

    int id2val(int x) {
        return b[x - 1];
    }
}

using Discrete::insert;
using Discrete::be, Discrete::en, Discrete::tot;
using Discrete::val2id;
using Discrete::init;

class SEG {
public:
    struct node {
        int l, r;
        int val, sum;
    } T[MAXN << 2];
    int lazy[MAXN << 2];

    inline void push_up(int rt) {
        T[rt].sum = T[rt << 1].sum + T[rt << 1 | 1].sum;
    }

    inline void push_down(int rt) {
        if (lazy[rt] == 2) return ;
        if (lazy[rt]) {
            T[rt << 1].sum = 0, T[rt << 1 | 1].sum = 0;
            lazy[rt << 1] = 1, lazy[rt << 1 | 1] = 1;
            lazy[rt] = 2;
        } else {
            T[rt << 1].sum = T[rt << 1].val, T[rt << 1 | 1].sum = T[rt << 1 | 1].val;
            lazy[rt << 1] = 0, lazy[rt << 1 | 1] = 0;
            lazy[rt] = 2;
        }
    }

    void build(int rt, int l, int r) {
        T[rt].l = l, T[rt].r = r;
        lazy[rt] = 2;
        if (l == r) {
            T[rt].sum = T[rt].val = en[l] - be[l] + 1;
            return;
        }
        int mid = (l + r) >> 1;
        build(rt << 1, l, mid);
        build(rt << 1 | 1, mid + 1, r);
        T[rt].val = T[rt << 1].val + T[rt << 1 | 1].val;
        T[rt].sum = T[rt].val;
    }

    void update(int rt, int L, int R, int op) {
        if (L <= T[rt].l && R >= T[rt].r) {
            if (op) T[rt].sum = 0, lazy[rt] = 1;
            else T[rt].sum = T[rt].val, lazy[rt] = 0;
            return;
        }
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        if (L <= mid) update(rt << 1, L, R, op);
        if (R > mid) update(rt << 1 | 1, L, R, op);
        push_up(rt);
    }

    int query(int rt, int L, int R) {
        if (L <= T[rt].l && T[rt].r <= R) return T[rt].sum;
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        int ans = 0;
        if (L <= mid) ans += query(rt << 1, L, R);
        if (R > mid) ans += query(rt << 1 | 1, L, R);
        return ans;
    }

} tree;

int l[MAXN], r[MAXN], k[MAXN];

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    insert(1);
    insert(n);
    for (int i = 1; i <= q; i++) {
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        insert(l[i]);
        insert(r[i]);
        insert(min(n, l[i] + 1));
        insert(min(n,r[i] + 1));
    }
    init();
    tree.build(1, 1, tot);
    for (int i = 1; i <= q; i++) {
        if (k[i] == 1) {
            tree.update(1, val2id(l[i]), val2id(r[i]), 1);
            printf("%d\n", tree.query(1, 1, tot));
        } else {
            tree.update(1, val2id(l[i]), val2id(r[i]), 0);
            printf("%d\n", tree.query(1, 1, tot));
        }
    }

}


#include <bits/stdc++.h>

using namespace std;
#define IT set<node>::iterator

class ODT {
public:
    struct node {
        int l, r;
        mutable int val;

        node() {}

        node(int _l, int _r = -1, int _val = 0) { l = _l, r = _r, val = _val; }

        bool operator<(const node &tb) const { return l < tb.l; }
    };

    set<node> st;

    IT split(int pos) {
        IT it = st.lower_bound(node(pos));
        if (it != st.end() && it->l == pos) return it;
        --it;
        int ul = it->l, ur = it->r, uv = it->val;
        st.erase(it);
        st.insert(node(ul, pos - 1, uv));
        return st.insert(node(pos, ur, uv)).first;
    }

    int ans = 0;

    void assign_val(int l, int r, int v = 0) {
        IT itr = split(r + 1), itl = split(l);
        for (IT it = itl; it != itr; it++) {
            ans -= (it->r - it->l + 1) * it->val;
        }
        st.erase(itl, itr);
        st.insert(node(l, r, v));
        ans += v * (r - l + 1);
    }

//    int sum(int l, int r) {
//        IT itr = split(r + 1), itl = split(l);
//        int ans = 0;
//        for (; itl != itr; itl++)
//            ans += (itl->r - itl->l + 1) * itl->val;
//        return ans;
//    }

    void insert(int l, int r, int v) {
        st.insert(node(l, r, v));
    }

} tree;

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    tree.insert(1, n, 1);
    tree.ans = n;
    while (q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        if (k == 1) {
            tree.assign_val(l, r, 0);
        } else tree.assign_val(l, r, 1);
        printf("%d\n", tree.ans);
    }
}


#include <bits/stdc++.h>

using namespace std;
#define IT set<node>::iterator

class ODT {
public:
    struct node {
        int l, r;
        mutable int val;

        node() {}

        node(int _l, int _r = -1, int _val = 0) { l = _l, r = _r, val = _val; }

        bool operator<(const node &tb) const { return l < tb.l; }
    };

    set<node> st;

    IT split(int pos) {
        IT it = st.lower_bound(node(pos));
        if (it != st.end() && it->l == pos) return it;
        --it;
        int ul = it->l, ur = it->r, uv = it->val;
        st.erase(it);
        st.insert(node(ul, pos - 1, uv));
        return st.insert(node(pos, ur, uv)).first;
    }

    void assign_val(int l, int r, int v = 0) {
        IT itr = split(r + 1), itl = split(l);
        st.erase(itl, itr);
        st.insert(node(l, r, v));
    }

    int sum(int l, int r) {
        IT itr = split(r + 1), itl = split(l);
        int ans = 0;
        for (; itl != itr; itl++)
            ans += (itl->r - itl->l + 1) * itl->val;
        return ans;
    }

    void insert(int l, int r, int v) {
        st.insert(node(l, r, v));
    }

} tree;

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    tree.insert(1, n, 1);
    tree.insert(n + 1, n + 1, 0);
    while (q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        if (k == 1) {
            tree.assign_val(l, r, 0);
        } else tree.assign_val(l, r, 1);
        printf("%d\n", tree.sum(1, n));
    }
}


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 15001000;

namespace Discrete {
    int b[MAXN], btol, blen;
    int be[MAXN], en[MAXN];
    int tot = 1;

    void insert(int x) {
        b[btol++] = x;
    }

    void init() {
        sort(b, b + btol);
        blen = unique(b, b + btol) - b;
        tot = 0;
        for (int i = 0; i < blen; i++) {
            tot++;
            be[tot] = b[i];
            if (i == blen - 1) en[tot] = b[i];
            else en[tot] = b[i + 1] - 1;
        }
    }

    int val2id(int x) {
        return lower_bound(b, b + blen, x) - b + 1;
    }

    int id2val(int x) {
        return b[x - 1];
    }
}

using Discrete::insert;
using Discrete::be, Discrete::en, Discrete::tot;
using Discrete::val2id;
using Discrete::init;

class SEG {
public:
    struct node {
        int l, r;
        int val, sum;
    } T[MAXN];
    int lazy[MAXN];

    inline void push_up(int rt) {
        T[rt].sum = T[rt << 1].sum + T[rt << 1 | 1].sum;
    }

    inline void push_down(int rt) {
        if (lazy[rt] == 2) return;
        if (lazy[rt]) {
            T[rt << 1].sum = 0, T[rt << 1 | 1].sum = 0;
            lazy[rt << 1] = 1, lazy[rt << 1 | 1] = 1;
            lazy[rt] = 2;
        } else {
            T[rt << 1].sum = T[rt << 1].val, T[rt << 1 | 1].sum = T[rt << 1 | 1].val;
            lazy[rt << 1] = 0, lazy[rt << 1 | 1] = 0;
            lazy[rt] = 2;
        }
    }

    void build(int rt, int l, int r) {
        T[rt].l = l, T[rt].r = r;
        lazy[rt] = 2;
        if (l == r) {
            T[rt].sum = T[rt].val = en[l] - be[l] + 1;
            return;
        }
        int mid = (l + r) >> 1;
        build(rt << 1, l, mid);
        build(rt << 1 | 1, mid + 1, r);
        T[rt].val = T[rt << 1].val + T[rt << 1 | 1].val;
        T[rt].sum = T[rt].val;
    }

    void update(int rt, int L, int R, int op) {
        if (L <= T[rt].l && R >= T[rt].r) {
            if (op) T[rt].sum = 0, lazy[rt] = 1;
            else T[rt].sum = T[rt].val, lazy[rt] = 0;
            return;
        }
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        if (L <= mid) update(rt << 1, L, R, op);
        if (R > mid) update(rt << 1 | 1, L, R, op);
        push_up(rt);
    }

    int query(int rt, int L, int R) {
        if (L <= T[rt].l && T[rt].r <= R) return T[rt].sum;
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        int ans = 0;
        if (L <= mid) ans += query(rt << 1, L, R);
        if (R > mid) ans += query(rt << 1 | 1, L, R);
        return ans;
    }

} tree;

int l[MAXN], r[MAXN], k[MAXN];

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    insert(1);
    insert(n);
    for (int i = 1; i <= q; i++) {
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        insert(l[i]);
        insert(r[i]);
        insert(min(n, l[i] + 1));
        insert(min(n, r[i] + 1));
    }
    init();
    tree.build(1, 1, tot);
    for (int i = 1; i <= q; i++) {
        if (k[i] == 1) {
            tree.update(1, val2id(l[i]), val2id(r[i]), 1);
            printf("%d\n", tree.query(1, 1, tot));
        } else {
            tree.update(1, val2id(l[i]), val2id(r[i]), 0);
            printf("%d\n", tree.query(1, 1, tot));
        }
    }

}


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 1e6 + 5;

namespace Discrete {
    int b[MAXN << 2], btol, blen;
    int be[MAXN << 2], en[MAXN << 2];
    int tot = 1;

    void insert(int x) {
        b[btol++] = x;
    }

    void init() {
        sort(b, b + btol);
        blen = unique(b, b + btol) - b;
        tot = 0;
        for (int i = 0; i < blen; i++) {
            tot++;
            be[tot] = b[i];
            if (i == blen - 1) en[tot] = b[i];
            else en[tot] = b[i + 1] - 1;
        }
    }

    int val2id(int x) {
        return lower_bound(b, b + blen, x) - b + 1;
    }

    int id2val(int x) {
        return b[x - 1];
    }
}

using Discrete::insert;
using Discrete::be, Discrete::en, Discrete::tot;
using Discrete::val2id;
using Discrete::init;

class SEG {
public:
    struct node {
        int l, r;
        int val, sum;
    } T[MAXN << 2];
    int lazy[MAXN << 2];

    inline void push_up(int rt) {
        T[rt].sum = T[rt << 1].sum + T[rt << 1 | 1].sum;
    }

    inline void push_down(int rt) {
        if (lazy[rt] == 2) return ;
        if (lazy[rt]) {
            T[rt << 1].sum = 0, T[rt << 1 | 1].sum = 0;
            lazy[rt << 1] = 1, lazy[rt << 1 | 1] = 1;
            lazy[rt] = 2;
        } else {
            T[rt << 1].sum = T[rt << 1].val, T[rt << 1 | 1].sum = T[rt << 1 | 1].val;
            lazy[rt << 1] = 0, lazy[rt << 1 | 1] = 0;
            lazy[rt] = 2;
        }
    }

    void build(int rt, int l, int r) {
        T[rt].l = l, T[rt].r = r;
        lazy[rt] = 2;
        if (l == r) {
            T[rt].sum = T[rt].val = en[l] - be[l] + 1;
            return;
        }
        int mid = (l + r) >> 1;
        build(rt << 1, l, mid);
        build(rt << 1 | 1, mid + 1, r);
        T[rt].val = T[rt << 1].val + T[rt << 1 | 1].val;
        T[rt].sum = T[rt].val;
    }

    void update(int rt, int L, int R, int op) {
        if (L <= T[rt].l && R >= T[rt].r) {
            if (op) T[rt].sum = 0, lazy[rt] = 1;
            else T[rt].sum = T[rt].val, lazy[rt] = 0;
            return;
        }
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        if (L <= mid) update(rt << 1, L, R, op);
        if (R > mid) update(rt << 1 | 1, L, R, op);
        push_up(rt);
    }

    int query(int rt, int L, int R) {
        if (L <= T[rt].l && T[rt].r <= R) return T[rt].sum;
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        int ans = 0;
        if (L <= mid) ans += query(rt << 1, L, R);
        if (R > mid) ans += query(rt << 1 | 1, L, R);
        return ans;
    }

} tree;

int l[MAXN], r[MAXN], k[MAXN];

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    insert(1);
    insert(n);
    for (int i = 1; i <= q; i++) {
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        insert(l[i]);
        insert(r[i]);
        insert(min(n, l[i] + 1));
        insert(min(n,r[i] + 1));
    }
    init();
    tree.build(1, 1, tot);
    for (int i = 1; i <= q; i++) {
        if (k[i] == 1) {
            tree.update(1, val2id(l[i]), val2id(r[i]), 1);
            printf("%d\n", tree.query(1, 1, tot));
        } else {
            tree.update(1, val2id(l[i]), val2id(r[i]), 0);
            printf("%d\n", tree.query(1, 1, tot));
        }
    }

}


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 6e5 + 5;

namespace Discrete {
    int b[MAXN << 2], btol, blen;
    int be[MAXN << 2], en[MAXN << 2];
    int tot = 1;

    void insert(int x) {
        b[btol++] = x;
    }

    void init() {
        sort(b, b + btol);
        blen = unique(b, b + btol) - b;
        tot = 0;
        for (int i = 0; i < blen; i++) {
            tot++;
            be[tot] = b[i];
            if (i == blen - 1) en[tot] = b[i];
            else en[tot] = b[i + 1] - 1;
        }
    }

    int val2id(int x) {
        return lower_bound(b, b + blen, x) - b + 1;
    }

    int id2val(int x) {
        return b[x - 1];
    }
}

using Discrete::insert;
using Discrete::be, Discrete::en, Discrete::tot;
using Discrete::val2id;
using Discrete::init;

class SEG {
public:
    struct node {
        int l, r;
        int val, sum;
    } T[MAXN << 2];
    int lazy[MAXN << 2];

    inline void push_up(int rt) {
        T[rt].sum = T[rt << 1].sum + T[rt << 1 | 1].sum;
    }

    inline void push_down(int rt) {
        if (lazy[rt] == 2) return ;
        if (lazy[rt]) {
            T[rt << 1].sum = 0, T[rt << 1 | 1].sum = 0;
            lazy[rt << 1] = 1, lazy[rt << 1 | 1] = 1;
            lazy[rt] = 2;
        } else {
            T[rt << 1].sum = T[rt << 1].val, T[rt << 1 | 1].sum = T[rt << 1 | 1].val;
            lazy[rt << 1] = 0, lazy[rt << 1 | 1] = 0;
            lazy[rt] = 2;
        }
    }

    void build(int rt, int l, int r) {
        T[rt].l = l, T[rt].r = r;
        lazy[rt] = 2;
        if (l == r) {
            T[rt].sum = T[rt].val = en[l] - be[l] + 1;
            return;
        }
        int mid = (l + r) >> 1;
        build(rt << 1, l, mid);
        build(rt << 1 | 1, mid + 1, r);
        T[rt].val = T[rt << 1].val + T[rt << 1 | 1].val;
        T[rt].sum = T[rt].val;
    }

    void update(int rt, int L, int R, int op) {
        if (L <= T[rt].l && R >= T[rt].r) {
            if (op) T[rt].sum = 0, lazy[rt] = 1;
            else T[rt].sum = T[rt].val, lazy[rt] = 0;
            return;
        }
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        if (L <= mid) update(rt << 1, L, R, op);
        if (R > mid) update(rt << 1 | 1, L, R, op);
        push_up(rt);
    }

    int query(int rt, int L, int R) {
        if (L <= T[rt].l && T[rt].r <= R) return T[rt].sum;
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        int ans = 0;
        if (L <= mid) ans += query(rt << 1, L, R);
        if (R > mid) ans += query(rt << 1 | 1, L, R);
        return ans;
    }

} tree;

int l[MAXN], r[MAXN], k[MAXN];

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    insert(1);
    insert(n);
    for (int i = 1; i <= q; i++) {
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        insert(l[i]);
        insert(r[i]);
        insert(l[i] + 1);
        insert(min(n,r[i] + 1));
    }
    init();
    tree.build(1, 1, tot);
    for (int i = 1; i <= q; i++) {
        if (k[i] == 1) {
            tree.update(1, val2id(l[i]), val2id(r[i]), 1);
            printf("%d\n", tree.query(1, 1, tot));
        } else {
            tree.update(1, val2id(l[i]), val2id(r[i]), 0);
            printf("%d\n", tree.query(1, 1, tot));
        }
    }

}


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 6e5 + 5;

namespace Discrete {
    int b[MAXN << 2], btol, blen;
    int be[MAXN << 2], en[MAXN << 2];
    int tot = 1;

    void insert(int x) {
        b[btol++] = x;
    }

    void init() {
        sort(b, b + btol);
        blen = unique(b, b + btol) - b;
        tot = 0;
        for (int i = 0; i < blen; i++) {
            tot++;
            be[tot] = b[i];
            if (i == blen - 1) en[tot] = b[i];
            else en[tot] = b[i + 1] - 1;
        }
    }

    int val2id(int x) {
        return lower_bound(b, b + blen, x) - b + 1;
    }

    int id2val(int x) {
        return b[x - 1];
    }
}

using Discrete::insert;
using Discrete::be, Discrete::en, Discrete::tot;
using Discrete::val2id;
using Discrete::init;

class SEG {
public:
    struct node {
        int l, r;
        int val, sum;
    } T[MAXN << 2];
    int lazy[MAXN << 2];

    inline void push_up(int rt) {
        T[rt].sum = T[rt << 1].sum + T[rt << 1 | 1].sum;
    }

    inline void push_down(int rt) {
        if (lazy[rt] == 2) return ;
        if (lazy[rt]) {
            T[rt << 1].sum = 0, T[rt << 1 | 1].sum = 0;
            lazy[rt << 1] = 1, lazy[rt << 1 | 1] = 1;
            lazy[rt] = 2;
        } else {
            T[rt << 1].sum = T[rt << 1].val, T[rt << 1 | 1].sum = T[rt << 1 | 1].val;
            lazy[rt << 1] = 0, lazy[rt << 1 | 1] = 0;
            lazy[rt] = 2;
        }
    }

    void build(int rt, int l, int r) {
        T[rt].l = l, T[rt].r = r;
        lazy[rt] = 2;
        if (l == r) {
            T[rt].sum = T[rt].val = en[l] - be[l] + 1;
            return;
        }
        int mid = (l + r) >> 1;
        build(rt << 1, l, mid);
        build(rt << 1 | 1, mid + 1, r);
        T[rt].val = T[rt << 1].val + T[rt << 1 | 1].val;
        T[rt].sum = T[rt].val;
    }

    void update(int rt, int L, int R, int op) {
        if (L <= T[rt].l && R >= T[rt].r) {
            if (op) T[rt].sum = 0, lazy[rt] = 1;
            else T[rt].sum = T[rt].val, lazy[rt] = 0;
            return;
        }
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        if (L <= mid) update(rt << 1, L, R, op);
        if (R > mid) update(rt << 1 | 1, L, R, op);
        push_up(rt);
    }

    int query(int rt, int L, int R) {
        if (L <= T[rt].l && T[rt].r <= R) return T[rt].sum;
        int mid = (T[rt].l + T[rt].r) >> 1;
        push_down(rt);
        int ans = 0;
        if (L <= mid) ans += query(rt << 1, L, R);
        if (R > mid) ans += query(rt << 1 | 1, L, R);
        return ans;
    }

} tree;

int l[MAXN], r[MAXN], k[MAXN];

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    insert(1);
    insert(n);
    for (int i = 1; i <= q; i++) {
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        insert(l[i]);
        insert(r[i]);
        insert(min(n, l[i] + 1));
        insert(min(n,r[i] + 1));
    }
    init();
    tree.build(1, 1, tot);
    for (int i = 1; i <= q; i++) {
        if (k[i] == 1) {
            tree.update(1, val2id(l[i]), val2id(r[i]), 1);
            printf("%d\n", tree.query(1, 1, tot));
        } else {
            tree.update(1, val2id(l[i]), val2id(r[i]), 0);
            printf("%d\n", tree.query(1, 1, tot));
        }
    }

}


#include <bits/stdc++.h>

using namespace std;
#define IT set<node>::iterator

class ODT {
public:
    struct node {
        int l, r;
        mutable int val;

        node() {}

        node(int _l, int _r = -1, int _val = 0) { l = _l, r = _r, val = _val; }

        bool operator<(const node &tb) const { return l < tb.l; }
    };

    set<node> st;

    IT split(int pos) {
        IT it = st.lower_bound(node(pos));
        if (it != st.end() && it->l == pos) return it;
        --it;
        int ul = it->l, ur = it->r, uv = it->val;
        st.erase(it);
        st.insert(node(ul, pos - 1, uv));
        return st.insert(node(pos, ur, uv)).first;
    }

    void assign_val(int l, int r, int v = 0) {
        IT itl = split(l), itr = split(r + 1);
        st.erase(itl, itr);
        st.insert(node(l, r, v));
    }

    int sum(int l, int r) {
        IT itl = split(l), itr = split(r + 1);
        int ans = 0;
        for (; itl != itr; itl++)
            ans += (itl->r - itl->l + 1) * itl->val;
        return ans;
    }

    void insert(int l, int r, int v) {
        st.insert(node(l, r, v));
    }

} tree;

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    tree.insert(1, n, 1);
    tree.insert(n+1, n+1, 0);
    while (q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        if (k == 1) {
            tree.assign_val(l, r, 0);
        } else tree.assign_val(l, r, 1);
        printf("%d\n", tree.sum(1, n));
    }
}


#include <bits/stdc++.h>

using namespace std;
#define IT set<node>::iterator

class ODT {
public:
    struct node {
        int l, r;
        mutable int val;

        node() {}

        node(int _l, int _r = -1, int _val = 0) { l = _l, r = _r, val = _val; }

        bool operator<(const node &tb) const { return l < tb.l; }
    };

    set<node> st;

    IT split(int pos) {
        IT it = st.lower_bound(node(pos));
        if (it != st.end() && it->l == pos) return it;
        --it;
        int ul = it->l, ur = it->r, uv = it->val;
        st.erase(it);
        st.insert(node(ul, pos - 1, uv));
        return st.insert(node(pos, ur, uv)).first;
    }

    int ans = 0;

    void assign_val(int l, int r, int v = 0) {
        IT itr = split(r + 1), itl = split(l);
        for (IT it = itl; it != itr; it++) {
            ans -= (itl->r - itl->l + 1) * itl->val;
        }
        st.erase(itl, itr);
        st.insert(node(l, r, v));
        ans += v * (r - l + 1);
    }

//    int sum(int l, int r) {
//        IT itr = split(r + 1), itl = split(l);
//        int ans = 0;
//        for (; itl != itr; itl++)
//            ans += (itl->r - itl->l + 1) * itl->val;
//        return ans;
//    }

    void insert(int l, int r, int v) {
        st.insert(node(l, r, v));
    }

} tree;

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    tree.insert(1, n, 1);
    tree.ans = n;
    while (q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        if (k == 1) {
            tree.assign_val(l, r, 0);
        } else tree.assign_val(l, r, 1);
        printf("%d\n", tree.ans);
    }
}


#include <bits/stdc++.h>

using namespace std;
#define IT set<node>::iterator

class ODT {
public:
    struct node {
        int l, r;
        mutable int val;

        node() {}

        node(int _l, int _r = -1, int _val = 0) { l = _l, r = _r, val = _val; }

        bool operator<(const node &tb) const { return l < tb.l; }
    };

    set<node> st;

    IT split(int pos) {
        IT it = st.lower_bound(node(pos));
        if (it != st.end() && it->l == pos) return it;
        --it;
        int ul = it->l, ur = it->r, uv = it->val;
        st.erase(it);
        st.insert(node(ul, pos - 1, uv));
        return st.insert(node(pos, ur, uv)).first;
    }

    void assign_val(int l, int r, int v = 0) {
        IT itl = split(l), itr = split(r + 1);
        st.erase(itl, itr);
        st.insert(node(l, r, v));
    }

    int sum(int l, int r) {
        IT itl = split(l), itr = split(r + 1);
        int ans = 0;
        for (; itl != itr; itl++)
            ans += (itl->r - itl->l + 1) * itl->val;
        return ans;
    }

    void insert(int l, int r, int v) {
        st.insert(node(l, r, v));
    }

} tree;

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    tree.insert(1, n, 1);
   // tree.insert(n+1, n+1, 0);
    while (q--) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        if (k == 1) {
            tree.assign_val(l, r, 0);
        } else tree.assign_val(l, r, 1);
        printf("%d\n", tree.sum(1, n));
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=1e3+5;
set<pii>st;
int main()
{
	int n;
	scanf("%d",&n);
	int q;
	scanf("%d",&q);
	int res=0;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1){
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-(*it).fi+1;
					l=(*it).fi;

					auto it1=it;
					st.erase(it1);
				}
				it=st.lower_bound({l,0});
			}
			if(it==st.end())
			{
				st.insert(pii(l,r));
			}
			else{

				for(;it!=st.end();){

					if((*it).fi>r){
						st.insert(pii(l,r));
						f=true;
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						st.erase(it++);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						int tr=(*it).se;
						st.erase(it++);
						st.insert(pii(l,tr));

						break;
					}

				}
				if(!f)st.insert(pii(l,r));
			}
				res-=t;
				res+=r-l+1;
		}
		else{
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					if((*it).se<r){
						t+=(*it).se-l+1;
						st.insert(pii((*it).fi,l-1));
						st.erase(it++);
					}
					else{
						t+=r-l+1;
						st.insert(pii((*it).fi,l-1));
						st.insert(pii(r+1,(*it).se));
						st.erase(it++);
						f=true;
					}
				}
				it=st.lower_bound({l,0});
			}

			if(it!=st.end()&&!f)
			{

				for(;it!=st.end();){
					if((*it).fi>r){
						dd((*it).fi)
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;

						st.erase(it++);
					}
					else{

						t+=r-(*it).fi+1;
						int tr=(*it).se;

						st.erase(it++);
						st.insert(pii(r+1,tr));

						break;
					}

				}
			}
		//	dd(res)
		//	de(t)
			res-=t;

		}
	/*	for(auto it=st.begin();it!=st.end();++it){
			cout<<it->fi<<" "<<it->se<<endl;
		}*/
		cout<<n-res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=1e3+5;
set<pii>st;
int main()
{
	int n;
	scanf("%d",&n);
	int q;
	scanf("%d",&q);
	int res=0;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1){
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-(*it).fi+1;
					l=(*it).fi;

					auto it1=it;
					st.erase(it1);
				}
				it=st.lower_bound({l,0});
			}
			if(it==st.end())
			{
				st.insert(pii(l,r));
			}
			else{

				for(;it!=st.end();){

					if((*it).fi>r){
						st.insert(pii(l,r));
						f=true;
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						st.erase(it++);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						int tr=(*it).se;
						st.erase(it++);
						st.insert(pii(l,tr));

						break;
					}

				}
				if(!f)st.insert(pii(l,r));
			}
				res-=t;
				res+=r-l+1;
		}
		else{
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					if((*it).se<r){
						t+=(*it).se-l+1;
						st.insert(pii((*it).fi,l-1));
						st.erase(it++);
					}
					else{
						t+=r-l+1;
						st.insert(pii((*it).fi,l-1));
						st.insert(pii(r+1,(*it).se));
						st.erase(it++);
						f=true;
					}
				}
				it=st.lower_bound({l,0});
			}

			if(it!=st.end()&&!f)
			{

				for(;it!=st.end();){
					if((*it).fi>r){

						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;

						st.erase(it++);
					}
					else{

						t+=r-(*it).fi+1;
						int tr=(*it).se;

						st.erase(it++);
						st.insert(pii(r+1,tr));

						break;
					}

				}
			}
		//	dd(res)
		//	de(t)
			res-=t;

		}
	/*	for(auto it=st.begin();it!=st.end();++it){
			cout<<it->fi<<" "<<it->se<<endl;
		}*/
		cout<<n-res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=1e3+5;
set<pii>st;
int main()
{
	int n;
	scanf("%d",&n);
	int q;
	scanf("%d",&q);
	int res=0;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1){
			auto it=st.lower_bound({l,r});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-l;
					l=(*it).fi;
					auto it1=it;
					st.erase(it1);
				}
				it++;
			}
			if(it==st.end())
			{
				st.insert(pii(l,r));
			}
			else{
				for(;it!=st.end();++it){
					if((*it).fi>r){
						st.insert(pii(l,r));
						f=true;
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						auto it1=it;
						st.erase(it1);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						st.insert(pii(l,(*it).se));
						auto it1=it;
						st.erase(it1);
						break;
					}

				}
				if(!f)st.insert(pii(l,r));
			}
				res-=t;
				res+=r-l+1;
		}
		else{
			auto it=st.lower_bound({l,r});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-l+1;

					st.insert(pii((*it).fi,l-1));
				//	dd(l-1)
				//	de((*it).fi)
					auto it1=it;
					st.erase(it1);
				}
				it++;
				it=st.lower_bound({l,r});
			}
			if(it!=st.end())
			{
				for(;it!=st.end();++it){
				//	dd((*it).fi)
				//	de((*it).se)
					if((*it).fi>r){
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						auto it1=it;
						st.erase(it1);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						st.insert(pii(r+1,(*it).se));
						auto it1=it;
						st.erase(it1);
						break;
					}

				}
			}
		//	dd(res)
		//	de(t)
			res-=t;

		}
	/*	for(auto it=st.begin();it!=st.end();++it){
			cout<<it->fi<<" "<<it->se<<endl;
		}*/
		cout<<n-res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=1e3+5;
set<pii>st;
int main()
{
	int n;
	scanf("%d",&n);
	int q;
	scanf("%d",&q);
	int res=0;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1){
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-(*it).fi+1;
					l=(*it).fi;
					r=max(r,(*it).se);
					auto it1=it;
					st.erase(it1);
				}
				it=st.lower_bound({l,0});
			}
			if(it==st.end())
			{
				st.insert(pii(l,r));
			}
			else{

				for(;it!=st.end();){

					if((*it).fi>r){
						st.insert(pii(l,r));
						f=true;
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						st.erase(it++);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						int tr=(*it).se;
						st.erase(it++);
						st.insert(pii(l,tr));

						break;
					}

				}
				if(!f)st.insert(pii(l,r));
			}
				res-=t;
				res+=r-l+1;
		}
		else{
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					if((*it).se<r){
						t+=(*it).se-l+1;
						st.insert(pii((*it).fi,l-1));
						st.erase(it++);
					}
					else{
						t+=r-l+1;
						st.insert(pii((*it).fi,l-1));
						st.insert(pii(r+1,(*it).se));
						st.erase(it++);
						f=true;
					}
				}
				it=st.lower_bound({l,0});
			}

			if(it!=st.end()&&!f)
			{

				for(;it!=st.end();){
					if((*it).fi>r){

						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;

						st.erase(it++);
					}
					else{

						t+=r-(*it).fi+1;
						int tr=(*it).se;

						st.erase(it++);
						st.insert(pii(r+1,tr));

						break;
					}

				}
			}
		//	dd(res)
		//	de(t)
			res-=t;

		}
	/*	for(auto it=st.begin();it!=st.end();++it){
			cout<<it->fi<<" "<<it->se<<endl;
		}*/
		cout<<n-res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=1e3+5;
set<pii>st;
int main()
{
	int n;
	scanf("%d",&n);
	int q;
	scanf("%d",&q);
	int res=0;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1){
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;

			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-(*it).fi+1;

					l=(*it).fi;
					auto it1=it;
					st.erase(it1);
				}
				it=st.lower_bound({l,0});
			}
			if(it==st.end())
			{

				st.insert(pii(l,r));
			}
			else{

				for(;it!=st.end()&&st.size();){

					if((*it).fi>r){
						st.insert(pii(l,r));
						f=true;
						break;
					}
					if((*it).se<=r){

						t+=(*it).se-(*it).fi+1;

						auto it1=it;

						st.erase(it++);

					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						st.insert(pii(l,(*it).se));
						auto it1=it;
						st.erase(it++);
						break;
					}

				}
				if(!f)st.insert(pii(l,r));
			}
		/*	dd(r)
			dd(l)
			dd(res)
			de(t)*/
			res-=t;
			res+=r-l+1;
		}
		else{
			auto it=st.lower_bound({l,0});
			int t=0;

			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-l+1;

					st.insert(pii((*it).fi,l-1));

					auto it1=it;
					st.erase(it++);
				}

			}
			if(it!=st.end())
			{

				for(;it!=st.end()&&st.size();){
				//	dd((*it).fi)
				//	de((*it).se)
					if((*it).fi>r){
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						auto it1=it;
						st.erase(it++);
					}
					else{

						f=true;
						t+=r-(*it).fi+1;

					//	dd((*it).se)
						if(r+1>(*it).fi){

							st.insert(pii(r+1,(*it).se));
							st.erase(it++);
						}
						break;
					}

				}
			}
		//	dd(res)
		//	de(t)
			res-=t;

		}
	/*	for(auto it=st.begin();it!=st.end();++it){
			cout<<it->fi<<" "<<it->se<<endl;
		}*/
		cout<<n-res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=1e3+5;
set<pii>st;
int main()
{
	int n;
	scanf("%d",&n);
	int q;
	scanf("%d",&q);
	int res=0;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1){
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-(*it).fi+1;
					l=(*it).fi;

					auto it1=it;
					st.erase(it1);
				}
				it=st.lower_bound({l,0});
			}
			if(it==st.end())
			{
				st.insert(pii(l,r));
			}
			else{
				de(st.size())
				for(;it!=st.end();){

					if((*it).fi>r){
						st.insert(pii(l,r));
						f=true;
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						st.erase(it++);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						int tr=(*it).se;
						st.erase(it++);
						st.insert(pii(l,tr));

						break;
					}

				}
				if(!f)st.insert(pii(l,r));
			}
				res-=t;
				res+=r-l+1;
		}
		else{
			auto it=st.lower_bound({l,r});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-l+1;

					st.insert(pii((*it).fi,l-1));
					st.erase(it++);
				}
				it=st.lower_bound({l,0});
			}
			if(it!=st.end())
			{
				for(;it!=st.end();){
					if((*it).fi>r){
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						st.erase(it++);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						int tr=(*it).se;
						st.erase(it++);
						st.insert(pii(r+1,tr));

						break;
					}

				}
			}
		//	dd(res)
		//	de(t)
			res-=t;

		}
	/*	for(auto it=st.begin();it!=st.end();++it){
			cout<<it->fi<<" "<<it->se<<endl;
		}*/
		cout<<n-res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=1e3+5;
set<pii>st;
int main()
{
	int n;
	scanf("%d",&n);
	int q;
	scanf("%d",&q);
	int res=0;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1){
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;

			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-(*it).fi+1;

					l=(*it).fi;
					auto it1=it;
					st.erase(it1);
				}
				it=st.lower_bound({l,0});
			}
			if(it==st.end())
			{

				st.insert(pii(l,r));
			}
			else{

				for(;it!=st.end()&&st.size();){

					if((*it).fi>r){
						st.insert(pii(l,r));
						f=true;
						break;
					}
					if((*it).se<=r){

						t+=(*it).se-(*it).fi+1;

						auto it1=it;

						st.erase(it++);

					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						st.insert(pii(l,(*it).se));
						auto it1=it;
						st.erase(it++);
						break;
					}

				}
				if(!f)st.insert(pii(l,r));
			}

			res-=t;
			res+=r-l+1;
		}
		else{
			auto it=st.lower_bound({l,0});
			int t=0;

			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-l+1;

					st.insert(pii((*it).fi,l-1));

					auto it1=it;
					st.erase(it);
				}
				it=st.lower_bound({l,r});
			}
			if(it!=st.end())
			{

				for(;it!=st.end()&&st.size();){

					if((*it).fi>r){
						break;
					}
					if((*it).se<=r){

						t+=(*it).se-(*it).fi+1;
						auto it1=it;

						st.erase(it++);

					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						st.erase(it++);
						st.insert(pii(r+1,(*it).se));
						break;
					}

				}
			}
		//	dd(res)
		//	de(t)
			res-=t;

		}
	/*	for(auto it=st.begin();it!=st.end();++it){
			cout<<it->fi<<" "<<it->se<<endl;
		}*/
		cout<<n-res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=1e3+5;
set<pii>st;
int main()
{
	int n;
	scanf("%d",&n);
	int q;
	scanf("%d",&q);
	int res=0;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1){
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-(*it).fi+1;
					l=(*it).fi;

					auto it1=it;
					st.erase(it1);
				}
				it=st.lower_bound({l,0});
			}
			if(it==st.end())
			{
				st.insert(pii(l,r));
			}
			else{

				for(;it!=st.end();){

					if((*it).fi>r){
						st.insert(pii(l,r));
						f=true;
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						st.erase(it++);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						int tr=(*it).se;
						st.erase(it++);
						st.insert(pii(l,tr));

						break;
					}

				}
				if(!f)st.insert(pii(l,r));
			}
				res-=t;
				res+=r-l+1;
		}
		else{
			auto it=st.lower_bound({l,r});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-l+1;

					st.insert(pii((*it).fi,l-1));
					st.erase(it++);
				}
				it=st.lower_bound({l,0});
			}
			if(it!=st.end())
			{
				for(;it!=st.end();){
					if((*it).fi>r){
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						st.erase(it++);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						int tr=(*it).se;
						st.erase(it++);
						st.insert(pii(r+1,tr));

						break;
					}

				}
			}
		//	dd(res)
		//	de(t)
			res-=t;

		}
	/*	for(auto it=st.begin();it!=st.end();++it){
			cout<<it->fi<<" "<<it->se<<endl;
		}*/
		cout<<n-res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=1e3+5;
set<pii>st;
int main()
{
	int n;
	scanf("%d",&n);
	int q;
	scanf("%d",&q);
	int res=0;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1){
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					t+=(*it).se-(*it).fi+1;
					l=(*it).fi;
					r=max(r,(*it).se);
					auto it1=it;
					st.erase(it1);
				}
				it=st.lower_bound({l,0});
			}
			if(it==st.end())
			{
				st.insert(pii(l,r));
			}
			else{

				for(;it!=st.end();){

					if((*it).fi>r){
						st.insert(pii(l,r));
						f=true;
						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;
						st.erase(it++);
					}
					else{
						f=true;
						t+=r-(*it).fi+1;
						int tr=(*it).se;
						st.erase(it++);
						st.insert(pii(l,tr));

						break;
					}

				}
				if(!f)st.insert(pii(l,r));
			}
				res-=t;
				res+=r-l+1;
		}
		else{
			auto it=st.lower_bound({l,0});
			int t=0;
			bool f=false;
			if(it!=st.begin()){
				it--;
				if((*it).se>=l&&(*it).fi<=l){
					if((*it).se<r){
						t+=(*it).se-l+1;
						st.insert(pii((*it).fi,l-1));
						st.erase(it++);
					}
					else{
						t+=r-l+1;
						st.insert(pii((*it).fi,l-1));
						st.insert(pii(r+1,(*it).se));
						st.erase(it++);
						f=true;
					}
				}
				it=st.lower_bound({l,0});
			}

			if(it!=st.end()&&!f)
			{

				for(;it!=st.end();){
					if((*it).fi>r){

						break;
					}
					if((*it).se<=r){
						t+=(*it).se-(*it).fi+1;

						st.erase(it++);
					}
					else{

						t+=r-(*it).fi+1;
						int tr=(*it).se;

						st.erase(it++);
						st.insert(pii(r+1,tr));

						break;
					}

				}
			}
		//	dd(res)
		//	de(t)
			res-=t;

		}
	/*	for(auto it=st.begin();it!=st.end();++it){
			cout<<it->fi<<" "<<it->se<<endl;
		}*/
		printf("%d\n",n-res);
	}
	return 0;
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif

struct v:map<int,pii> {
	auto split(int x) {
		auto p = lower_bound(x);
		if (p!=end()&&p->x==x) return p;
		if (p==begin()) for(;;);
		--p;
		if (x>p->y.x) return end();
		auto t = *p;
		erase(p);
		emplace(t.x,pii(x-1,t.y.y));
		return emplace(x,t.y).x;
	}
} s;
int main() {
	int n,q;
	scanf("%d%d",&n,&q);
	s[1] = {n,1};
	int ans = n;
	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if (k==1) k = 0;
		else k = 1;
		auto L = s.split(l), R = s.split(r+1);
		while (L!=R) {
			if (L==s.end()) throw;
			ans += (k-L->y.y)*(L->y.x-L->x+1);
			s.erase(L++);
		}
		s[l] = {r,k};
		printf("%d\n", ans);
	}
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif

struct v:map<int,pii> {
	auto split(int x) {
		auto p = lower_bound(x);
		if (p!=end()&&p->x==x) return p;
		if (p==begin()) for(;;);
		--p;
		if (x>p->y.x) return end();
		auto t = *p;
		erase(p);
		emplace(t.x,pii(x-1,t.y.y));
		return emplace(x,t.y).x;
	}
} s;
int main() {
	int n,q;
	scanf("%d%d",&n,&q);
	s[1] = {n,1};
	int ans = n;
	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if (k==1) k = 0;
		else k = 1;
		auto L = s.split(l), R = s.split(r+1);
		if (R!=s.end()&&L->x>R->x) for(;;);
		for (auto t=L; t!=R; ++t) ans += (k-t->y.y)*(t->y.x-t->x+1);
		s.erase(L,R);
		s[l] = {r,k};
		printf("%d\n", ans);
	}
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif

struct v:map<int,pii> {
	auto split(int x) {
		auto p = lower_bound(x);
		if (p!=end()&&p->x==x) return p;
		--p;
		if (x>p->y.x) return end();
		auto t = *p;
		erase(p);
		emplace(t.x,pii(x-1,t.y.y));
		return emplace(x,t.y).x;
	}
} s;
int main() {
	int n,q;
	scanf("%d%d",&n,&q);
	s[1] = {n,1};
	int ans = n;
	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if (k==1) k = 0;
		else k = 1;
		auto L = s.split(l), R = s.split(r+1);
		if (R!=s.end()&&L->x>R->x) for(;;);
		for (auto t=L; t!=R; ++t) ans += (k-t->y.y)*(t->y.x-t->x+1);
		s.erase(L,R);
		s[l] = {r,k};
		printf("%d\n", ans);
	}
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif

int n,q,b[N];
struct {int l,r,k;}e[N];
ll sum[N<<2];
void build(int o, int l, int r) {
	if (l==r) return sum[o]=b[r+1]-b[l],void();
	build(ls),build(rs),sum[o]=sum[lc]+sum[rc];
}
void add(int o, int l, int r, int ql, int qr, int v) {
	if (ql<=l&&r<=qr) {
		if (v==1) sum[o]=0;
		else sum[o]=b[r+1]-b[l];
		return;
	}
	if (sum[o]==b[r+1]-b[l]) {
		sum[lc]=b[mid+1]-b[l];
		sum[rc]=b[r+1]-b[mid+1];
	}
	if (!sum[o]) sum[lc]=sum[rc]=0;
	if (mid>=ql) add(ls,ql,qr,v);
	if (mid<qr) add(rs,ql,qr,v);
	sum[o]=sum[lc]+sum[rc];
}
int main() {
	scanf("%d%d",&n,&q);
	b[++*b]=1,b[++*b]=n+1;
	REP(i,1,q) {
		scanf("%d%d%d",&e[i].l,&e[i].r,&e[i].k);
		b[++*b]=e[i].l;
		b[++*b]=++e[i].r;
	}
	sort(b+1,b+1+*b);
	*b=unique(b+1,b+1+*b)-b-1;
	build(1,1,*b-1);
	REP(i,1,q) {
		int l=lower_bound(b+1,b+1+*b,e[i].l)-b;
		int r=lower_bound(b+1,b+1+*b,e[i].r)-b-1;
		add(1,1,*b-1,l,r,e[i].k);
		printf("%lld\n",sum[1]);
	}
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif

struct v:map<int,pair<int,int> > {
	auto split(int x) {
		auto p = lower_bound(x);
		if (p!=end()&&p->x==x) return p;
		--p;
		if (x>p->y.x) return end();
		auto t = *p;
		erase(p);
		emplace(t.x,pair<int,ll>(x-1,t.y.y));
		return emplace(x,t.y).x;
	}
} s;
int main() {
	int n,q;
	scanf("%d%d",&n,&q);
	s[1] = {n,1};
	int ans = n;
	while (q--) {
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if (k==1) k = 0;
		else k = 1;
		auto L = s.split(l), R = s.split(r+1);
		for (auto t=L; t!=R; ++t) ans += (k-t->y.y)*(t->y.x-t->x+1);
		s.erase(L,R);
		s[l] = {r,k};
		printf("%d\n", ans);
	}
}