题目:
原题题意太复杂,我把题意简化一下,有n个数(编号是从1~n),m个操作,每个操作有一个数x,当x=1的时候,他会再给你一个数q,意思是把这这些数想右移动q位(比如地一组样例原来是:1 2 3 4 5 6,经过一个操作 1 2后就会变成:5 6 1 2 3 4),当x=2的时候就把这些数的奇数位置和偶数位置互换一下。。
这个题比赛的时候我们想的是暴力,结果果然超时了,看了题解才知道,有个规律。
仔细观察这些数,会发现奇数位置和偶数位置的数的相对位置永远不变,这样就好做多了,我们只需要把这一组数的1 2的位置一直维护,剩下的数可以由这两个位置推出来
代码:
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include<set>
#include<iostream>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10000007
#define debug() puts("whatthefuck!!!")
#define N 1111111
#define M 1000000
#define ll longlong
using namespace std;
int ans[N];
int main()
{
int p0=0,p1=1;//p0是1的位置,p1是2的位置
int n,q;
scanf("%d%d",&n,&q);
for(int i=0; i<q; ++i)
{
int op;
scanf("%d",&op);
if(op==1)
{
int x;
scanf("%d",&x);
p0=(p0+x+n)%n;
p1=(p1+x+n)%n;
}
else
{
p0=p0^1;
p1=p1^1;
}
}
for(int i=0; i<n; i+=2)
{
ans[(p0+i)%n]=i+1;
}
for(int i=1; i<n; i+=2)
{
ans[(p1+i-1)%n]=i+1;
}
for(int i=0; i<n; ++i)
{
printf("%d ",ans[i]);
}
return 0;
}