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
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include<bits/stdc++.h>
using namespace std;
int licz;
typedef long long LL;
const int BASE = 1048576;

LL tab[2*BASE+7];
LL tab2[2*BASE+7];
LL tab3[2*BASE+7];

void insert(int a, int b, int c)
{
    a += BASE;b += BASE;

    tab[a] += c;
    if(a != b) tab[b] += c;

    while(a/2 != b/2)
    {
        if(a%2 == 0) tab[a+1] += c;
        if(b%2 == 1) tab[b-1] += c;

        a /= 2;b /= 2;
    }
}

LL query(int a)
{
    LL wyn = 0;
    a += BASE;

    while(a > 0)
    {
        wyn += tab[a];
        a /= 2;
    }

    return wyn;
}
void insert2(int a, int b, int c)
{
    a += BASE;b += BASE;

    tab2[a] += c;
    if(a != b) tab2[b] += c;

    while(a/2 != b/2)
    {
        if(a%2 == 0) tab2[a+1] += c;
        if(b%2 == 1) tab2[b-1] += c;

        a /= 2;b /= 2;
    }
}

LL query2(int a)
{
    LL wyn = 0;
    a += BASE;

    while(a > 0)
    {
        wyn += tab2[a];
        a /= 2;
    }

    return wyn;
}
void insert3(int a, int b, int c)
{
    a += BASE;b += BASE;

    tab3[a] += c;
    if(a != b) tab3[b] += c;

    while(a/2 != b/2)
    {
        if(a%2 == 0) tab3[a+1] += c;
        if(b%2 == 1) tab3[b-1] += c;

        a /= 2;b /= 2;
    }
}

LL query3(int a)
{
    LL wyn = 0;
    a += BASE;

    while(a > 0)
    {
        wyn += tab3[a];
        a /= 2;
    }

    return wyn;
}

int n,k;

int main()
{
    cin >> n >> k;

    for(int i = 1;i <= k;i++)
    {
        int t,a,b,c;
        cin >> a >> b >> c;
        if(c == 1)
            insert(a,b,1);
        if(c == 2)
            insert2(a,b,1);
        if(c == 3)
            insert3(a,b,1);
    }
    for(int i=1;i <= n;i++)
        if(query(i) > 0 && query2(i) > 0 && query3(i) == 0)
            licz++;
    cout << licz << endl;

    return 0;
}