×_7_12_2013 J: Matrix Operation

Problem J: Matrix Operation

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 52   Solved: 24
[ Submit][ Status][ Web Board]

Description

You are given a matrix M of type 1234x5678. It is initially filled with integers 1...1234x5678 in row major 
order. Your task is to process a list of commands manipulating M. There are 4 types of commands:  
"R x y" swap the xth and yth row of M; 1<=x, y<=1234. 
"C x y" swap the xth and yth column of M; 1<=x, y<=5678. 
"Q x y" write out M(x, y); 1<=x<=1234.1<=y<=5678. 
"W z" write out x and y where z=M(x, y). 1<=z<=7006652 (1234 * 5678) 

Input

The input file contains several test cases. The first line is N: the number of test cases. Then follows N lines. 
A list of valid commands.1 <= N <= 10000. 

Output

For each "Q x y" write out one line with the current value of M(x, y), for each "W z" write out one line with 
the value of x and y (described as above) separated by a space. 

Sample Input

10 

 R 1 2 

 Q 1 1 

 Q 2 1

 W 1 

 W 5679 

 C 1 2 

 Q 1 1 

 Q 2 1 

 W 1 

 W 5679

Sample Output

5679 

 1 

 2 1 

 1 1 

 5680 

 2 

 2 2

 1 2

你可能感兴趣的:(×_7_12_2013 J: Matrix Operation)