ACS  A concrete simulation
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 ;
"C x y" swap the xth and yth column of M ;
"Q x y" write out M(x,y) ;
"W z" write out x and y where z=M(x,y).
Input
A list of valid commands. Input terminated by EOF.
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 ( interpreted as above ) separated by a space.
Input: 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 Output: 5679 1 2 1 1 1 5680 2 2 2 1 2
hide comments
aksam:
20150601 08:32:54
my 100 classical problem :D 

Rajat (1307086):
20150401 21:57:34
Try O(1) for all queries. AC in .05


achint mittal:
20150209 21:09:34
please can anyone give more testcases.. 

Malinga:
20150101 20:03:41
easy problem..got ac in 0.01 sec ..O(1) for all the queries..I used two 1236 length arrays and two 5678 length arrays.. 

Rahul Jain:
20141219 20:02:18
guys, please tell me some tricky cases


Harsh Rumalwala:
20141219 19:04:15
Done without precomputation.Need to think a bit!!!Corner cases gave me a WA. 

Shaktiman:
20140903 10:49:11
Q O(1)


Divyank Duvedi:
20140622 13:45:23
What is Matrix's initial form is it : a[r][c]=r*c ? 

Rishab Banerjee:
20140419 19:37:37
O(1) per query is not required....my solution took O(1) in R and C


Bumbler:
20140414 11:40:12
TLE with FAST I/O. and works fine without it . Please lemme know the reason behind this .

Added by:  czylabsonasa 
Date:  20050610 
Time limit:  7s 
Source limit:  7777B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  Folklore 