CF487D.Conveyor Belts

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Automatic Bakery of Cyberland (ABC) recently bought an n×mn×m rectangle table. To serve the diners, ABC placed seats around the table. The size of each seat is equal to a unit square, so there are 2(n+m)2(n+m) seats in total.

ABC placed conveyor belts on each unit square on the table. There are three types of conveyor belts: "^", "<" and ">". A "^" belt can bring things upwards. "<" can bring leftwards and ">" can bring rightwards.

Let's number the rows with 11 to nn from top to bottom, the columns with 11 to mm from left to right. We consider the seats above and below the top of the table are rows 00 and n+1n+1 respectively. Also we define seats to the left of the table and to the right of the table to be column 00 and m+1m+1 . Due to the conveyor belts direction restriction there are currently no way for a diner sitting in the row n+1n+1 to be served.

Given the initial table, there will be qq events in order. There are two types of events:

  • "A xx yy " means, a piece of bread will appear at row xx and column yy (we will denote such position as (x,y)(x,y) ). The bread will follow the conveyor belt, until arriving at a seat of a diner. It is possible that the bread gets stuck in an infinite loop. Your task is to simulate the process, and output the final position of the bread, or determine that there will be an infinite loop.
  • "C xx yy cc " means that the type of the conveyor belt at (x,y)(x,y) is changed to cc .

Queries are performed separately meaning that even if the bread got stuck in an infinite loop, it won't affect further queries.

输入格式

The first line of input contains three integers nn , mm and qq ( 1<=n<=105,1<=m<=10,1<=q<=1051<=n<=10^{5},1<=m<=10,1<=q<=10^{5} ), separated by a space.

Next nn lines, each line contains mm characters, describing the table. The characters can only be one of "<^>".

Next qq lines, each line describes an event. The format is "C x y c" or "A x y" (Consecutive elements are separated by a space). It's guaranteed that 1<=x<=n,1<=y<=m1<=x<=n,1<=y<=m . cc is a character from the set "<^>".

There are at most 1000010000 queries of "C" type.

输出格式

For each event of type "A", output two integers txtx , tyty in a line, separated by a space, denoting the destination of (x,y)(x,y) is (tx,ty)(tx,ty) .

If there is an infinite loop, you should output tx=ty=1tx=ty=-1 .

输入输出样例

  • 输入#1

    2 2 3
    >>
    ^^
    A 2 1
    C 1 2 <
    A 2 1

    输出#1

    1 3
    -1 -1
    
  • 输入#2

    4 5 7
    ><<^<
    ^<^^>
    >>>^>
    >^>>^
    A 3 1
    A 2 2
    C 1 4 <
    A 3 1
    C 1 2 ^
    A 3 1
    A 2 2

    输出#2

    0 4
    -1 -1
    -1 -1
    0 2
    0 2
    

说明/提示

For the first sample:

If the bread goes from (2,1)(2,1) , it will go out of the table at (1,3)(1,3) .

After changing the conveyor belt of (1,2)(1,2) to "<", when the bread goes from (2,1)(2,1) again, it will get stuck at "><", so output is (1,1)(-1,-1) .

首页