#B4047. Greenery Construction Damage

    ID: 11704 Type: Default 1000ms 256MiB

Greenery Construction Damage

Greenery Construction Damage

Outside a school there are \(m\) trees arranged from left to right and numbered \(1,2,\ldots,m\). In addition, between the \(i\)-th tree and the \((i+1)\)-th tree there is a lawn. Trees and lawns together are referred to as greenery.

There are \(n\) construction operations performed in sequence. Each operation is one of the following two types:

  • \(1\; l\; r\): This operation destroys all the greenery between the \(l\)-th tree and the \(r\)-th tree excluding the \(l\)-th and the \(r\)-th trees.
  • \(2\; l\; r\): This operation destroys all the greenery between the \(l\)-th tree and the \(r\)-th tree including the \(l\)-th and the \(r\)-th trees.

After all \(n\) operations are completed, your task is to calculate the number of trees and the number of lawns that have not been destroyed.

Note: The lawns correspond to the intervals between consecutive trees; that is, there are initially \(m-1\) lawns.

inputFormat

The first line contains two integers \(m\) and \(n\) \( (2 \le m \le 10^5, 0 \le n \le 10^5)\), representing the number of trees and the number of operations respectively.

Each of the following \(n\) lines contains three integers: \(op\), \(l\), and \(r\). \(op\) is either 1 or 2, representing the type of operation. It is guaranteed that \(1 \leq l < r \leq m\).

outputFormat

Output two integers separated by a space: the number of trees and the number of lawns that remain intact after all the operations.

sample

5 2
1 2 4
2 3 5
2 1