A. 矩阵移位

    传统题 文件IO:matrix 3500ms 256MiB

矩阵移位

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

题目描述

给定一个 n×nn\times n 的矩阵,保证每一行和每一列都是一个从 1n1∼n 的排列。矩阵行编号从上到下,列编号从左到右。

现在,有一个长为 kk 的操作序列,包含六种操作:

  • R:矩阵向右循环移动一位。(最后一列元素移到第一列,其它每个元素右移一列)
  • L:矩阵向左循环移动一位。(第一列元素移到最后一列,其它每个元素左移一列)
  • D:矩阵向下循环移动一位。(最后一行元素移到第一行,其它每个元素下移一行)
  • U:矩阵向上循环移动一位。(第一行元素移到最后一行,其它每个元素上移一行)
  • I:将每行替换为它的逆排列。(如果替换完之后会不满足每行每列都是排列,就不替换)
  • C:将每列替换为它的逆排列。(如果替换完之后会不满足每行每列都是排列,就不替换)

现在,有 qq 次询问,每次给定 l,r,x,yl,r,x,y,询问当对初始矩阵依次执行第 l,l+1,,rl,l+1,\dots ,r 次操作后,(x,y)(x,y) 处的值是多少?

输入格式

第一行三个正整数 n,k,qn,k,q

接下来 nn 行,是一个 n×nn\times n 的矩阵。

接下来一个长为 kk 的字符串,表示操作序列。

接下来 qq 行,每行四个正整数 l,r,x,yl,r,x,y,表示询问。

输出格式

一共 qq 行,每行一个正整数,表示答案。

本来应该是这样的,但是输出太大了,把 OJ 弄炸了。令第 ii 次询问的答案为 sis_i,你只需要输出一行,表示所有 i×sii\times s_i按位异或的结果。样例并没有做这样的修改,你需要自己计算。

样例

3 2 1
1 2 3
2 3 1
3 1 2
DR
1 2 1 1
2
5 10 3
1 2 3 4 5 
5 3 2 1 4 
4 1 5 2 3 
3 4 1 5 2 
2 5 4 3 1 
DIIIRRDIRR
10 10 2 3
5 9 1 2
3 6 4 5
3
2
1

大样例

限制

数据范围 nn kk qq 特殊性质
11 =100=100 =500=500 =1=1
22 =500=500 l=1l=1
343∼4 =1000=1000 =105=10^5 =1=1 l=1,r=kl=1,r=k
55 =105=10^5 l=1l=1
676∼7
8108∼10 =107=10^7

由于本题输入输出较多,此处提供快速读入输出模板。本题时限以此模板的运行时间为基准。

#include<bits/stdc++.h>

using namespace std;

struct FastIO{
	static const int IOSIZE = 65536;
	char in[IOSIZE],*p,*pp,out[IOSIZE],*q,*qq,ch[20],*t,b;
	FastIO():p(in),pp(in),q(out),qq(out+IOSIZE),t(ch),b(1){}
	~FastIO(){fwrite(out,1,q-out,stdout);}
	char getch(){ return p==pp&&(pp=(p=in)+fread(in,1,IOSIZE,stdin),p==pp)?b=0,EOF:*p++; }
	void putch(char x){ q==qq&&(fwrite(out,1,q-out,stdout),q=out),*q++=x; }
	void puts(const char str[]){fwrite(out,1,q-out,stdout),fwrite(str,1,strlen(str),stdout),q=out;}
	#define indef(T) FastIO& operator>>(T& x){\
		x=0;char f=0,ch;\
		while(!isdigit(ch=getch())&&b)f|=ch=='-';\
		while(isdigit(ch))x=x*10+(ch^48),ch=getch();\
		return x=f?-x:x,*this;\
	}
	indef(int)
	indef(long long)
	FastIO& operator>>(char& ch){return ch=getch(),*this;}
	FastIO& operator>>(char* s){
		char ch;
		while(isspace(ch=getch())&&b);
		while(!isspace(ch)&&b)*(s++)=ch,ch=getch();
        *s='\0';
		return *this;
	}
	FastIO& operator>>(string& s){
		s="";char ch;
		while(isspace(ch=getch())&&b);
		while(!isspace(ch)&&b)s+=ch,ch=getch();
		return *this;
	}
	#define outdef(_T) inline FastIO& operator<<(_T x){\
		!x&&(putch('0'),0),x<0&&(putch('-'),x=-x);\
		while(x)*t++=x%10+48,x/=10;\
		while(t!=ch)putch(*--t);\
		return *this;\
	}
	outdef(int)
	outdef(long long)
	FastIO& operator<<(char ch){return putch(ch),*this;}
	FastIO& operator<<(const char str[]){return puts(str),*this;}
	FastIO& operator<<(const string& s){return puts(s.c_str()),*this;}
	operator bool(){return b;}
}io;

const int MX=1000,MXK=100000;

int n,k,q;
char op[MXK];
int a[MX][MX];

int main(){
    freopen("matrix.in","r",stdin);
    freopen("matrix.out","w",stdout);
    io>>n>>k>>q;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            io>>a[i][j];
    io>>op;
    for(int i=0;i<q;i++){
        int l,r,x,y;
        io>>l>>r>>x>>y;
        int ans=0;
        io<<ans<<'\n';
    }
    return 0;
}

20260124模拟赛

未参加
状态
已结束
规则
OI
题目
3
开始于
2026-1-24 8:00
结束于
2026-1-24 12:30
持续时间
4.5 小时
主持人
参赛人数
29