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
#include<iostream>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int puszki1[n];
    int puszki2[n];
    int puszki3[n];
    for(int i = 0; i < n; i++)
    {
        puszki1[i] = 0;
        puszki2[i] = 0;
        puszki3[i] = 0;
    }
    int a, b, c;
    for(int i = 0; i < m; i++)
    {
        cin >> a >> b >> c;
        if(c == 1)
        {
            puszki1[a-1] += 1;
            puszki1[b] -=1;
        }
        if(c == 2)
        {
            puszki2[a-1] +=1;
            puszki2[b] -= 1;
        }
        if(c == 3)
        {
            puszki3[a-1] += 1;
            puszki3[b] -= 1;
        }
    }
    for(int i = 1; i < n; i++)
    {
        puszki1[i] = puszki1[i] + puszki1[i-1];
        puszki2[i] = puszki2[i] + puszki2[i-1];
        puszki3[i] = puszki3[i] + puszki3[i-1];
    }
    int counter = 0;
    for(int i = 0; i < n; i++)
    {
        if(puszki1[i] >= 1 && puszki2[i] >= 1 && puszki3[i] <1)
            counter+=1;
    }
    cout << counter;
}