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
#include <bits/stdc++.h>

using namespace std;
const long long siz=4e6;
long long l,r,k,n,m,drz[siz],pot2=1,wynik;
void inserrt(int ll, int rr, int kk)
{
    ll+=pot2;
    rr+=pot2;
    if(ll==rr)
    {
        drz[ll]|=kk;
    }
    else
    {
        drz[ll]|=kk;
        drz[rr]|=kk;
        while(rr-ll>1)
        {
            if(rr%2==1)
            {
                drz[rr-1]|=kk;
            }
            if(ll%2==0)
            {
                drz[ll+1]|=kk;
            }
            ll/=2;
            rr/=2;
        }
    }
}
int query(int poz)
{
    poz+=pot2;
    int wyn=0;
    while(poz!=0)
    {
        wyn|=drz[poz];
        poz/=2;
    }
    return wyn;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    while(pot2<=n)
    {
        pot2*=2;
    }
    for(int i=0;i<m;i++)
    {
        cin >> l >> r >> k;
        if(k==3)
            k=4;
        inserrt(l,r,k);
    }
    for(int i=1;i<=n;i++)
    {
        if(query(i)==3)
            wynik++;
            //cout << query(i)<<" ";
    }
    cout << wynik;

    return 0;
}