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
#include <cstring>
#include <bitset>
#include <iostream>
using namespace std;

#define N 1000004
//#define N 32

static char arr[4][N] = { 0 };

int main() {
	int n, m;
	scanf("%d %d", &n, &m);


        memset (arr[1],'0', 3 * N);

	for (int i = 0; i < m; i++) {
                unsigned l, r, c;
		scanf("%u %u %u ", &l, &r, &c);

		r++;

                char *a = &arr[c][0];
                memset (a + l,'1', r - l);
	}

        std::bitset<N> fin = std::bitset<N>(arr[1]) & std::bitset<N>(arr[2]) & ~std::bitset<N>(arr[3]);

	printf("%d\n", (int)fin.count());



	return 0;
}