A12768 | Feeling Good
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Recently biologists came to a fascinating conclusion about how to find a chameleon mood. Consider chameleon body to be a rectangular table $n \times m$ , each cell of which may be green or blue and may change between these two colors. We will denote as $(x, y)$ ( $1 \leq x \leq n$ , $1 \leq y \leq m$ ) the cell in row $x$ and column $y$ .
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 $(x_1, y_1)$ , $(x_1, y_2)$ , $(x_2, y_1)$ , $(x_2, y_2)$ for some $1 \leq x_1 < x_2 \leq n$ , $1 \leq y_1 < y_2 \leq m$ , that colors of $(x_1, y_1)$ and $(x_2, y_2)$ coincide and colors of $(x_1, y_2)$ and $(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 $a$ , $l$ , $r$ ( $1 \leq a \leq n$ , $1 \leq l \leq r \leq m$ ). On such change colors of all cells $(a, b)$ such that $l \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 $x_1$ , $y_1$ , $x_2$ , $y_2$ such that four cells $(x_1, y_1)$ , $(x_1, y_2)$ , $(x_2, y_1)$ , $(x_2, y_2)$ are the good mood certificate.
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 $(x_1, y_1)$ , $(x_1, y_2)$ , $(x_2, y_1)$ , $(x_2, y_2)$ for some $1 \leq x_1 < x_2 \leq n$ , $1 \leq y_1 < y_2 \leq m$ , that colors of $(x_1, y_1)$ and $(x_2, y_2)$ coincide and colors of $(x_1, y_2)$ and $(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 $a$ , $l$ , $r$ ( $1 \leq a \leq n$ , $1 \leq l \leq r \leq m$ ). On such change colors of all cells $(a, b)$ such that $l \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 $x_1$ , $y_1$ , $x_2$ , $y_2$ such that four cells $(x_1, y_1)$ , $(x_1, y_2)$ , $(x_2, y_1)$ , $(x_2, y_2)$ are the good mood certificate.
输入格式
The first line of input contains three integers $n$ , $m$ , $q$ ( $1 \leq n, m \leq 2000$ , $1 \leq q \leq 500\,000$ ), the sizes of the table and the number of changes respectively.
Each of the following $q$ lines contains 3 integers $a_i$ , $l_i$ , $r_i$ ( $1 \leq a_i \leq n$ , $1 \leq l_i \leq r_i \leq m$ ), describing $i$ -th coloring change.
Each of the following $q$ lines contains 3 integers $a_i$ , $l_i$ , $r_i$ ( $1 \leq a_i \leq n$ , $1 \leq l_i \leq r_i \leq m$ ), describing $i$ -th coloring change.
输出格式
Print $q$ lines. In the $i$ -th line report the chameleon mood after first $i$ color changes for all $1 \leq i \leq q$ .
If chameleon is in bad mood, print the only integer $-1$ .
Otherwise, print four integers $x_1$ , $y_1$ , $x_2$ , $y_2$ ( $1 \leq x_1 < x_2 \leq n$ , $1 \leq y_1 < y_2 \leq m$ ) such that four cells $(x_1, y_1)$ , $(x_1, y_2)$ , $(x_2, y_1)$ , $(x_2, y_2)$ are the good mood certificate. If there are several ways to choose such four integers, print any valid one.
If chameleon is in bad mood, print the only integer $-1$ .
Otherwise, print four integers $x_1$ , $y_1$ , $x_2$ , $y_2$ ( $1 \leq x_1 < x_2 \leq n$ , $1 \leq y_1 < y_2 \leq m$ ) such that four cells $(x_1, y_1)$ , $(x_1, y_2)$ , $(x_2, y_1)$ , $(x_2, y_2)$ are the good mood certificate. If there are several ways to choose such four integers, print any valid one.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted