1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	short state[n];
	for(int i=0;i<n;i++)
	{
		state[i] = 5;
	}
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		for(int j=a-1;j<b;j++)
		{
			if(c==1)
				{
				if (state[j] == 5) state[j] = 3;
				else if (state[j] == 3) state[j] = 3;
				else if (state[j] == 2) state[j] = 1;
				else if (state[j] == 0) state[j] = 0;
				else if (state[j] == 1) state[j] = 1;
				}
			else if(c==2)
				{
				if (state[j] == 5) state[j] = 2;
				else if (state[j] == 3) state[j] = 1;
				else if (state[j] == 2) state[j] = 2;
				else if (state[j] == 0) state[j] = 0;
				else if (state[j] == 1) state[j] = 1;
				}
			else state[j] = 0;
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		if(state[i]==1)	ans+=1;
	}
	cout << ans;
	
	return 0;
}