【Codeforces 706E】Working routine

题目传送门:http://codeforces.com/problemset/problem/706/E
官方题解:http://codeforces.com/blog/entry/46510

这个题感觉出得很好啊!
没想到链表还能这么考!秒啊!
23781763871263

#include<iostream>
#include<cstdio>
using namespace std;

const int MAXN = 1000+9;

int d[MAXN*MAXN],r[MAXN*MAXN],mat[MAXN*MAXN],m,n,q,vout[MAXN][MAXN];

inline int read(){
	char c=getchar(); int ret = 0;
	while (c<'0'||c>'9') c=getchar();
	while (c<='9'&&c>='0') ret = ret*10+c-'0', c=getchar();
	return ret;
}

#define id(x, y) ((x)+1 + (y)*(n+2))

inline void change(int x1, int y1, int x2, int y2, int x, int y){
	int p1 = id(0,0), p2 = id(0,0); 
	for (int j=1;j<y1;j++) p1 = d[p1]; for (int i=1;i<=x1;i++) p1 = r[p1];
	for (int j=1;j<y2;j++) p2 = d[p2]; for (int i=1;i<=x2;i++) p2 = r[p2];
	for (int i=1;i<=x;i++) swap(d[p1], d[p2]), p1 = r[p1], p2 = r[p2];
	p1 = id(0,0), p2 = id(0,0); 
	for (int j=1;j<y1+y;j++) p1 = d[p1]; for (int i=1;i<=x1;i++) p1 = r[p1];
	for (int j=1;j<y2+y;j++) p2 = d[p2]; for (int i=1;i<=x2;i++) p2 = r[p2];
	for (int i=1;i<=x;i++) swap(d[p1], d[p2]), p1 = r[p1], p2 = r[p2];
	
	
	p1 = id(0,0), p2 = id(0,0); 
	for (int i=1;i<x1;i++) p1 = r[p1]; for (int j=1;j<=y1;j++) p1 = d[p1]; 
	for (int i=1;i<x2;i++) p2 = r[p2]; for (int j=1;j<=y2;j++) p2 = d[p2];
	for (int j=1;j<=y;j++) swap(r[p1], r[p2]), p1 = d[p1], p2 = d[p2];
	p1 = id(0,0), p2 = id(0,0); 
	for (int i=1;i<x1+x;i++) p1 = r[p1]; for (int j=1;j<=y1;j++) p1 = d[p1]; 
	for (int i=1;i<x2+x;i++) p2 = r[p2]; for (int j=1;j<=y2;j++) p2 = d[p2];
	for (int j=1;j<=y;j++) swap(r[p1], r[p2]), p1 = d[p1], p2 = d[p2];
}

inline void trans(){
	int head = id(0,0); 
	for (int j=1;j<=m;j++) {
		head = d[head];
		for (int i=1,w=r[head];i<=n;i++,w=r[w])
			vout[i][j] = mat[w];
	}
	for (int j=1;j<=m;j++) {for (int i=1;i<=n;i++) printf("%d ",vout[i][j]); printf("\n");}
}

int main(){
	m = read(); n = read(); q = read();
	for (int j=1;j<=m;j++) for (int i=1;i<=n;i++) mat[id(i,j)] = read();
	for (int j=0;j<=m+1;j++) for (int i=0;i<=n+1;i++) d[id(i,j)] = id(i,j+1), r[id(i,j)] = id(i+1,j);
	
	for (int k=1,x1,x2,y1,y2,lh,lw;k<=q;k++) {
		y1 = read(), x1 = read();
		y2 = read(), x2 = read();
		lh = read(), lw = read();
		change(x1,y1,x2,y2,lw,lh);
	} trans();
	return 0;
}

36 thoughts to “【Codeforces 706E】Working routine”

  1. 484765 686250We dont trust this amazing submit. Nevertheless, I saw it gazed for Digg along with Ive determined you can be appropriate so i ended up being imagining within the completely wrong way. Persist with writing top quality stuff along these lines. 245366

  2. 565044 668338Hi. Thank you for producing this internet site . I m working on betting online niche and have located this web site making use of search on bing . Will be certain to look a lot more of your content . Gracias , see ya. :S 576229

  3. Good day! This post couldn’t be written any better! Reading through this
    post reminds me of my good old room mate!
    He always kept chatting about this. I will forward this post
    to him. Fairly certain he will have a good read. Many thanks for sharing!

  4. 216057 561350It is truly a fantastic and valuable piece of info. Im happy which you just shared this beneficial info with us. Please stay us informed like this. Thank you for sharing. 899909

  5. Greetings from Los angeles! I’m bored to death at work so I decided to check out
    your site on my iphone during lunch break. I enjoy the knowledge you present here and can’t wait to take
    a look when I get home. I’m shocked at how quick your
    blog loaded on my phone .. I’m not even using WIFI, just
    3G .. Anyways, great site!

  6. Wonderful beat ! I wish to apprentice even as you
    amend your website, how could i subscribe for a blog site?
    The account aided me a acceptable deal. I have been tiny bit familiar of this your
    broadcast offered shiny clear concept

  7. Thanks on your marvelous posting! I really enjoyed reading it,
    you are a great author. I will remember to bookmark your blog and may come back at some point.
    I want to encourage you continue your great writing, have a
    nice holiday weekend!

  8. Nice post. I was checking continuously this blog and I am impressed!
    Very helpful info specifically the remaining phase 🙂 I
    handle such information much. I used to be looking for this
    particular information for a very lengthy time. Thanks and good luck.

  9. This is very interesting, You are a very skilled blogger.

    I’ve joined your feed and look forward to seeking more of your wonderful post.
    Also, I have shared your website in my social networks!

  10. Hello, Neat post. There is an issue together with your
    site in internet explorer, would test this?
    IE still is the marketplace chief and a good element
    of other folks will miss your wonderful writing due to this problem.

  11. I like what you guys are up also. Such clever work and reporting! Keep up the superb works guys I¡¦ve incorporated you guys to my blogroll. I think it’ll improve the value of my web site

  12. Wonderful paintings! This is the kind of info that are meant to be shared around the web. Shame on the search engines for no longer positioning this submit upper! Come on over and discuss with my website . Thank you

  13. Very well written article. It will be supportive to everyone who utilizes it, as well as yours truly 🙂 . Keep up the good work – can’r wait to read more posts.

  14. Hi, Neat post. There’s an issue together with your web site in internet explorer, would test this?
    IE still is the marketplace chief and a good element of folks will leave out your fantastic
    writing due to this problem.

  15. You are so interesting! I do not think I have read
    a single thing like that before. So wonderful to find someone with genuine thoughts on this
    topic. Seriously.. thanks for starting this up. This web site
    is one thing that is needed on the web, someone with a
    bit of originality!

Leave a Reply

Your email address will not be published. Required fields are marked *