1 //Cross linked list codeforces Round #367 E working routine2 //Test instructions: give you a matrix, Q-Ask, two sub-matrices per exchange, ask the final matrix3 //idea: violence must not. We can create a cross-linked list of each element, record the right and bottom elements, and subscript each element (starting at 0), each asking for only four points to be exchanged. 4 //to establish a matrix (n+1) * (m+1)5 6#include <bits/stdc++.h>7 using namespacestd;8 #defineLL Long Long9 Const DoubleINF =123456789012345.0;Ten ConstLL MOD =100000000LL; One Const intN =1010*1010; A #defineCLC (A, B) memset (A,b,sizeof (a)) - Const DoubleEPS = 1e-7; - voidFre () {freopen ("In.txt","R", stdin);} the voidFreout () {freopen ("OUT.txt","W", stdout);} -InlineintRead () {intx=0, f=1;CharCh=getchar (); while(ch>'9'|| ch<'0') {if(ch=='-') f=-1; Ch=getchar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; Ch=getchar ();}returnx*F;} - - intn,m,q; + structnode{ - intv,r,d; + }a[n]; A at intChgintYintx) { - returny* (m+1)+x; - } - - intMain () { -scanf"%d%d%d",&n,&m,&q); in for(intI=1; i<=n;i++){ - for(intj=1; j<=m;j++){ toscanf"%d",&A[chg (i,j)].v); + } - } the * for(intI=0; i<=n;i++){ $ for(intj=0; j<=m;j++){Panax NotoginsengA[chg (i,j)].r=chg (i,j+1); -A[chg (i,j)].d=chg (i+1, j); the } + } A while(q--){ the intx1,y1,x2,y2,h,w; +scanf"%d%d%d%d%d%d",&y1,&x1,&y2,&x2,&h,&W); - intp1=0, p2=0; $ for(intI=1; i<y1;i++) p1=a[p1].d; $ for(intI=1; i<x1;i++) p1=A[P1].R; - for(intI=1; i<y2;i++) p2=a[p2].d; - for(intI=1; i<x2;i++) p2=A[P2].R; the intt1=P1; - intT2=P2;Wuyi for(intI=1; i<=h;i++){ thet1=a[t1].d; -T2=a[t2].d; Wu swap (A[T1].R,A[T2].R); - } About for(intI=1; i<=w;i++){ $t1=A[T1].R; -T2=A[T2].R; - swap (A[T1].D,A[T2].D); - } AT1=p1,t2=P2; + for(intI=1; i<=w;i++){ thet1=A[T1].R; -T2=A[T2].R; $ swap (A[T1].D,A[T2].D); the } the for(intI=1; i<=h;i++){ thet1=a[t1].d; theT2=a[t2].d; - swap (A[T1].R,A[T2].R); in } the } the intp=0; About for(intI=1; i<=n;i++){ thep=a[p].d; the intq=p; the for(intj=1; j<=m;j++){ +q=A[Q].R; -printf"%d", A[Q].V); the }Bayiprintf"\ n"); the } the return 0; -}
Cross linked list codeforces Round #367 E working routine