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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <cstdio>

int bC[31250] = {0};
int yC[31250] = {0};
int rC[31250] = {0};

void SetBit(int A[], long k)
{
    A[k / 32] |= 1 << (k % 32);
}

int TestBit(int A[], long k)
{
    return ((A[k / 32] & (1 << (k % 32))) != 0);
}

void UpdateBits(int A[], long l, long r)
{
    for (long j = l; j <= r; j++)
    {
        SetBit(A, j);
    }
}

int main()
{
    long n, m, l, r, count = 0;
    int k;

    scanf("%ld%ld", &n, &m);

    for (int i = 0; i < m; i++)
    {
        scanf("%ld%ld%d", &l, &r, &k);

        if (k == 1)
        {
            UpdateBits(yC, l, r);
        }
        else if (k == 2)
        {
            UpdateBits(bC, l, r);
        }
        else
        {
            UpdateBits(rC, l, r);
        }
    }

    for (int i = 1; i <= n; i++)
    {
        if (TestBit(rC, i) == 0)
        {
            if (TestBit(yC, i) == 1 && TestBit(bC, i) == 1)
            {
                count++;
            }
        }
    }
    printf("%ld\n", count);
    return 0;
}