E. Physical Education Lessons

Codeforces
IDCF915E
Time1000ms
Memory256MB
Difficulty
data structuresimplementationsortings
English · Original
Chinese · Translation
Formal · Original
This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is very soon, but, unfortunately, Alex still hasn't attended a single lesson! Since Alex doesn't want to get expelled, he wants to know the number of working days left until the end of the term, so he can attend physical education lessons during these days. But in BSU calculating the number of working days is a complicated matter: There are _n_ days left before the end of the term (numbered from 1 to _n_), and initially all of them are working days. Then the university staff sequentially publishes _q_ orders, one after another. Each order is characterised by three numbers _l_, _r_ and _k_: * If _k_ = 1, then all days from _l_ to _r_ (inclusive) become non-working days. If some of these days are made working days by some previous order, then these days still become non-working days; * If _k_ = 2, then all days from _l_ to _r_ (inclusive) become working days. If some of these days are made non-working days by some previous order, then these days still become working days. Help Alex to determine the number of working days left after each order! ## Input The first line contains one integer _n_, and the second line — one integer _q_ (1 ≤ _n_ ≤ 109, 1 ≤ _q_ ≤ 3·105) — the number of days left before the end of the term, and the number of orders, respectively. Then _q_ lines follow, _i_\-th line containing three integers _l__i_, _r__i_ and _k__i_ representing _i_\-th order (1 ≤ _l__i_ ≤ _r__i_ ≤ _n_, 1 ≤ _k__i_ ≤ 2). ## Output Print _q_ integers. _i_\-th of them must be equal to the number of working days left until the end of the term after the first _i_ orders are published. [samples]
今年,Alex 完成了中学学业,现在他是 Berland 国立大学的一年级学生。让他感到惊讶的是,尽管他学习编程,但仍需参加体育课。学期即将结束,但不幸的是,Alex 至今尚未参加过一节体育课! 由于不想被开除,Alex 想知道学期结束前还剩多少个工作日,以便在这几天里参加体育课。但在 BSU,计算工作日数量是一项复杂的工作: 距离学期结束还有 #cf_span[n] 天(编号从 #cf_span[1] 到 #cf_span[n]),最初所有这些天都是工作日。随后,大学工作人员按顺序发布 #cf_span[q] 项命令,每项命令由三个数字 #cf_span[l]、#cf_span[r] 和 #cf_span[k] 描述: 帮助 Alex 确定每条命令发布后剩余的工作日数量! 第一行包含一个整数 #cf_span[n],第二行包含一个整数 #cf_span[q](#cf_span[1 ≤ n ≤ 10^9],#cf_span[1 ≤ q ≤ 3·10^5])——分别表示学期结束前剩余的天数和命令数量。 接下来 #cf_span[q] 行,第 #cf_span[i] 行包含三个整数 #cf_span[li]、#cf_span[ri] 和 #cf_span[ki],表示第 #cf_span[i] 条命令(#cf_span[1 ≤ li ≤ ri ≤ n],#cf_span[1 ≤ ki ≤ 2])。 请输出 #cf_span[q] 个整数。第 #cf_span[i] 个整数必须等于发布前 #cf_span[i] 条命令后剩余的工作日数量。 ## Input 第一行包含一个整数 #cf_span[n],第二行包含一个整数 #cf_span[q](#cf_span[1 ≤ n ≤ 10^9],#cf_span[1 ≤ q ≤ 3·10^5])——分别表示学期结束前剩余的天数和命令数量。接下来 #cf_span[q] 行,第 #cf_span[i] 行包含三个整数 #cf_span[li]、#cf_span[ri] 和 #cf_span[ki],表示第 #cf_span[i] 条命令(#cf_span[1 ≤ li ≤ ri ≤ n],#cf_span[1 ≤ ki ≤ 2])。 ## Output 请输出 #cf_span[q] 个整数。第 #cf_span[i] 个整数必须等于发布前 #cf_span[i] 条命令后剩余的工作日数量。 [samples]
Let $ n \in \mathbb{N} $ be the total number of days, initially all working. Let $ q \in \mathbb{N} $ be the number of orders. Each order $ i \in \{1, \dots, q\} $ is a triple $ (l_i, r_i, k_i) $, where: - $ 1 \leq l_i \leq r_i \leq n $, - $ k_i \in \{1, 2\} $. Define a set $ W \subseteq \{1, 2, \dots, n\} $, initially $ W = \{1, 2, \dots, n\} $, representing working days. For each order $ i $: - If $ k_i = 1 $, then $ W \leftarrow W \setminus \{l_i, l_i+1, \dots, r_i\} $ (mark days as non-working). - If $ k_i = 2 $, then $ W \leftarrow W \cup \{l_i, l_i+1, \dots, r_i\} $ (mark days as working). Let $ w_i = |W| $ after the $ i $-th order. **Objective:** Output $ w_1, w_2, \dots, w_q $.
Samples
Input #1
4
6
1 2 1
3 4 1
2 3 2
1 3 2
2 4 1
1 4 2
Output #1
2
0
2
3
1
4
API Response (JSON)
{
  "problem": {
    "name": "E. Physical Education Lessons",
    "description": {
      "content": "This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend phys",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF915E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend phys...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "今年,Alex 完成了中学学业,现在他是 Berland 国立大学的一年级学生。让他感到惊讶的是,尽管他学习编程,但仍需参加体育课。学期即将结束,但不幸的是,Alex 至今尚未参加过一节体育课!\n\n由于不想被开除,Alex 想知道学期结束前还剩多少个工作日,以便在这几天里参加体育课。但在 BSU,计算工作日数量是一项复杂的工作:\n\n距离学期结束还有 #cf_span[n] 天(编号从 #cf_sp...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ n \\in \\mathbb{N} $ be the total number of days, initially all working.  \nLet $ q \\in \\mathbb{N} $ be the number of orders.  \n\nEach order $ i \\in \\{1, \\dots, q\\} $ is a triple $ (l_i, r_i, k_i) $...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments