CF1214G.Feeling Good

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Recently biologists came to a fascinating conclusion about how to find a chameleon mood. Consider chameleon body to be a rectangular table n×mn \times m, each cell of which may be green or blue and may change between these two colors. We will denote as (x,y)(x, y) (1≤x≤n1 \leq x \leq n, 1≤y≤m1 \leq y \leq m) the cell in row xx and column yy.

Let us define a chameleon good mood certificate to be four cells which are corners of some subrectangle of the table, such that colors in opposite cells among these four are similar, and at the same time not all of the four cell colors are similar. Formally, it is a group of four cells (x1,y1)(x_1, y_1), (x1,y2)(x_1, y_2), (x2,y1)(x_2, y_1), (x2,y2)(x_2, y_2) for some 1≤x1<x2≤n1 \leq x_1 \lt x_2 \leq n, 1≤y1<y2≤m1 \leq y_1 \lt y_2 \leq m, that colors of (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) coincide and colors of (x1,y2)(x_1, y_2) and (x2,y1)(x_2, y_1) coincide, but not all of the four cells share the same color. It was found that whenever such four cells are present, chameleon is in good mood, and vice versa: if there are no such four cells, chameleon is in bad mood.

You are asked to help scientists write a program determining the mood of chameleon. Let us consider that initially all cells of chameleon are green. After that chameleon coloring may change several times. On one change, colors of contiguous segment of some table row are replaced with the opposite. Formally, each color change is defined by three integers aa, ll, rr (1≤a≤n1 \leq a \leq n, 1≤l≤r≤m1 \leq l \leq r \leq m). On such change colors of all cells (a,b)(a, b) such that l≤b≤rl \leq b \leq r are replaced with the opposite.

Write a program that reports mood of the chameleon after each change. Additionally, if the chameleon mood is good, program should find out any four numbers x1x_1, y1y_1, x2x_2, y2y_2 such that four cells (x1,y1)(x_1, y_1), (x1,y2)(x_1, y_2), (x2,y1)(x_2, y_1), (x2,y2)(x_2, y_2) are the good mood certificate.

最近,生物学家得出了一个关于如何判断变色龙情绪的有趣结论。将变色龙的身体建模为一个 n×mn \times m 的矩形表格,其中每个格子为绿色或蓝色,并可在两种颜色之间切换。我们用 (x,y)(x, y)(1≤x≤n1 \leq x \leq n,1≤y≤m1 \leq y \leq m)表示第 xx 行、第 yy 列的格子。

我们将变色龙“情绪良好”的认证图案定义为表格中某个子矩形的四个角所对应的格子,满足:两组对角格子的颜色分别相同,但四个格子并非全部同色。形式化地,它是一组四个格子 (x1,y1)(x_1, y_1)、(x1,y2)(x_1, y_2)、(x2,y1)(x_2, y_1)、(x2,y2)(x_2, y_2),其中 1≤x1<x2≤n1 \leq x_1 < x_2 \leq n,1≤y1<y2≤m1 \leq y_1 < y_2 \leq m,且 (x1,y1)(x_1, y_1) 与 (x2,y2)(x_2, y_2) 颜色相同,(x1,y2)(x_1, y_2) 与 (x2,y1)(x_2, y_1) 颜色也相同,但四个格子并非全部同色。研究发现:只要存在这样一组四格,变色龙即处于良好情绪;反之,若不存在任何这样的四格,则变色龙处于不良情绪。

你需要帮助科学家编写一个程序,用于判定每次染色变化后变色龙的情绪状态。初始时,变色龙所有格子均为绿色。随后,变色龙的颜色可能发生若干次变化。每次变化将某一行中一个连续区间的格子颜色翻转(即绿色变蓝色,蓝色变绿色)。形式化地,每次颜色变化由三个整数 aa、ll、rr(1≤a≤n1 \leq a \leq n,1≤l≤r≤m1 \leq l \leq r \leq m)指定:对所有满足 l≤b≤rl \leq b \leq r 的格子 (a,b)(a, b),将其颜色翻转。

请编写一个程序,在每次变化后报告变色龙的情绪状态。此外,若情绪为良好,程序还需输出任意一组满足条件的四元组 x1x_1、y1y_1、x2x_2、y2y_2,使得四个格子 (x1,y1)(x_1, y_1)、(x1,y2)(x_1, y_2)、(x2,y1)(x_2, y_1)、(x2,y2)(x_2, y_2) 构成一个“情绪良好”的认证图案。

输入格式

The first line of input contains three integers nn, mm, qq (1≤n,m≤20001 \leq n, m \leq 2000, 1≤q≤500 0001 \leq q \leq 500\,000), the sizes of the table and the number of changes respectively.

Each of the following qq lines contains 3 integers aia_i, lil_i, rir_i (1≤ai≤n1 \leq a_i \leq n, 1≤li≤ri≤m1 \leq l_i \leq r_i \leq m), describing ii-th coloring change.

输入的第一行包含三个整数 nn、mm、qq(1≤n,m≤20001 \leq n, m \leq 2000,1≤q≤500 0001 \leq q \leq 500\,000),分别表示表格的尺寸以及修改操作的次数。

接下来的 qq 行中,每行包含三个整数 aia_i、lil_i、rir_i(1≤ai≤n1 \leq a_i \leq n,1≤li≤ri≤m1 \leq l_i \leq r_i \leq m),描述第 ii 次染色修改操作。

输出格式

Print qq lines. In the ii-th line report the chameleon mood after first ii color changes for all 1≤i≤q1 \leq i \leq q.

If chameleon is in bad mood, print the only integer −1-1.

Otherwise, print four integers x1x_1, y1y_1, x2x_2, y2y_2 (1≤x1<x2≤n1 \leq x_1 \lt x_2 \leq n, 1≤y1<y2≤m1 \leq y_1 \lt y_2 \leq m) such that four cells (x1,y1)(x_1, y_1), (x1,y2)(x_1, y_2), (x2,y1)(x_2, y_1), (x2,y2)(x_2, y_2) are the good mood certificate. If there are several ways to choose such four integers, print any valid one.

输出 qq 行。在第 ii 行中,报告前 ii 次颜色变化后变色龙的情绪状态(对所有 1≤i≤q1 \leq i \leq q)。

若变色龙处于“坏心情”状态,则仅输出整数 −1-1。

否则,输出四个整数 x1x_1、y1y_1、x2x_2、y2y_2(满足 1≤x1<x2≤n1 \leq x_1 \lt x_2 \leq n 且 1≤y1<y2≤m1 \leq y_1 \lt y_2 \leq m),使得四个格子 (x1,y1)(x_1, y_1)、(x1,y2)(x_1, y_2)、(x2,y1)(x_2, y_1)、(x2,y2)(x_2, y_2) 构成“好心情”的证明。若存在多种选择方式,输出任意一组合法解即可。

输入输出样例

  • 输入#1

    2 2 6
    1 1 1
    2 2 2
    2 1 1
    1 2 2
    2 2 2
    1 1 1

    输出#1

    -1
    1 1 2 2
    -1
    -1
    -1
    1 1 2 2
  • 输入#2

    4 3 9
    2 2 3
    4 1 2
    2 1 3
    3 2 2
    3 1 3
    1 2 2
    4 2 3
    1 1 3
    3 1 3

    输出#2

    -1
    2 1 4 3
    -1
    2 1 3 2
    3 2 4 3
    1 1 2 2
    1 1 2 2
    -1
    2 1 3 2

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

首页