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
// kol | Solution by Mikołaj Zabłocki (Dominik Korsa)
// https://sio2.mimuw.edu.pl/c/pa-2020-1/p/kol/

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  cin >> n >> m;

  vector<vector<bool>> cans(n, vector<bool>(3, false));

  int validCount = 0;

  for (int i = 0; i < m; i++) {
    int l, r, k;
    cin >> l >> r >> k;
    l--; r--; k--;
    for (int j = l; j <= r; j++) {
      bool currentlyValid = cans[j][0] && cans[j][1] && !cans[j][2];
      cans[j][k] = true;
      bool newValid = cans[j][0] && cans[j][1] && !cans[j][2];
      if (currentlyValid && !newValid) validCount--;
      if (!currentlyValid && newValid) validCount++;
    }
  }

  cout << validCount;

  return 0;
}