CF1214G.Feeling Good
普及/提高-
通过率:0%
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×m , each cell of which may be green or blue and may change between these two colors. We will denote as (x,y) ( 1≤x≤n , 1≤y≤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 (x1,y1) , (x1,y2) , (x2,y1) , (x2,y2) for some 1≤x1<x2≤n , 1≤y1<y2≤m , that colors of (x1,y1) and (x2,y2) coincide and colors of (x1,y2) and (x2,y1) 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≤a≤n , 1≤l≤r≤m ). On such change colors of all cells (a,b) such that l≤b≤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 x1 , y1 , x2 , y2 such that four cells (x1,y1) , (x1,y2) , (x2,y1) , (x2,y2) are the good mood certificate.
输入格式
The first line of input contains three integers n , m , q ( 1≤n,m≤2000 , 1≤q≤500000 ), the sizes of the table and the number of changes respectively.
Each of the following q lines contains 3 integers ai , li , ri ( 1≤ai≤n , 1≤li≤ri≤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≤i≤q .
If chameleon is in bad mood, print the only integer −1 .
Otherwise, print four integers x1 , y1 , x2 , y2 ( 1≤x1<x2≤n , 1≤y1<y2≤m ) such that four cells (x1,y1) , (x1,y2) , (x2,y1) , (x2,y2) 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