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
#include <cstdio>

const char WHITE = 0x00, YELLOW = 0x01, BLUE = 0x02, RED = 0x04,
    GREEN = BLUE | YELLOW, ORANGE = YELLOW | RED, VIOLET = BLUE | RED, BROWN = YELLOW | BLUE | RED, PROCESSED = 0x10;

const char NUM_TO_COLOUR[] = { YELLOW, BLUE, RED };     //NUM_TO_COLOUR[k - 1] = COLOUR_CODE

char cans[1000000];     //as global variable because it will be zero initialized = as WHITE colour

typedef long long unsigned llu;

int main()
{
    llu n, m, l, r, k, counter = 0; //n - liczba puszek z farba, m - ilosc operacji, l - lewa strona przedialu, r - prawa strona przedzialu, k - kolor barwnika, counter - licznik puszek z zielona farb¹
    char current_dye = WHITE;
    scanf("%llu %llu", &n, &m); //first input line;
    for (llu i = 0; i < m; i++) {
        scanf("%llu %llu %llu", &l, &r, &k); //current operation
        current_dye = NUM_TO_COLOUR[k - 1];  //get current dye colour once in every operation
        for (llu j = l - 1; j < r; j++) {
            cans[j] |= current_dye;  //add current dye to paint can = OR acctual can content with dye colour code
        }
    }
    for(llu i = 0; i < n; i++) {
        if(cans[i] == GREEN)
            ++counter;
    }
    printf("%llu", counter);
    return 0;
}