CF915E.Physical Education Lessons

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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!

今年,亚历克斯完成了中学学业,如今成为贝尔兰国立大学(BSU)的一年级学生。令他大为惊讶的是:尽管他学习的是编程专业,却仍需参加体育课。学期即将结束,但不幸的是,亚历克斯至今一节体育课都未曾上过!

由于亚历克斯不想被退学,他想了解距离学期结束还剩多少个工作日,以便在这些日子里补上体育课。然而,在BSU计算剩余工作日数却是一件相当复杂的事情:

距离学期结束还剩 n 天(编号为 1 到 n),初始时所有这些天均为工作日。随后,校方工作人员将依次发布 q 条指令,一条接一条。每条指令由三个整数 l、r 和 k 描述:

  • 若 k = 1,则区间 [l, r](含端点)内的所有日期均变为非工作日;若其中某些日期曾被先前某条指令设为工作日,则这些日期仍将变为非工作日;
  • 若 k = 2,则区间 [l, r](含端点)内的所有日期均变为工作日;若其中某些日期曾被先前某条指令设为非工作日,则这些日期仍将变为工作日。

请帮助亚历克斯计算每次指令发布后剩余的工作日数量!

输入格式

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).

第一行包含一个整数 nn,第二行包含一个整数 qq(1 ≤ n ≤ 1091 \leq n \leq 10^9,1 ≤ q ≤ 3⋅1051 \leq q \leq 3\cdot10^5),分别表示学期结束前剩余的天数和订单数量。

接下来是 qq 行,其中第 ii 行包含三个整数 lil_i、rir_i 和 kik_i,表示第 ii 个订单(1 ≤ li ≤ ri ≤ n1 \leq l_i \leq r_i \leq n,1 ≤ ki ≤ 21 \leq k_i \leq 2)。

输出格式

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.

输出 qq 个整数。其中第 ii 个整数必须等于在前 ii 个订单发布后,到学期结束前剩余的工作日天数。

输入输出样例

  • 输入#1

    4
    6
    1 2 1
    3 4 1
    2 3 2
    1 3 2
    2 4 1
    1 4 2

    输出#1

    2
    0
    2
    3
    1
    4

输入解题思路,AI测评打分。不知道怎么写?

首页