CodeForces

来源:互联网 发布:软件的摊销年限 编辑:程序博客网 时间:2024/06/06 15:45

题目:

B. Little Artem and Dance
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.

More detailed, there are n pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:

  1. Value x and some direction are announced, and all boys move x positions in the corresponding direction.
  2. Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that n is even.

Your task is to determine the final position of each boy.

Input

The first line of the input contains two integers n and q (2 ≤ n ≤ 1 000 0001 ≤ q ≤ 2 000 000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that n is even.

Next q lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as x ( - n ≤ x ≤ n), where 0 ≤ x ≤ n means all boys moves x girls in clockwise direction, while  - x means all boys move x positions in counter-clockwise direction. There is no other input for commands of the second type.

Output

Output n integers, the i-th of them should be equal to the index of boy the i-th girl is dancing with after performing all q moves.

Examples
input
6 31 221 2
output
4 3 6 5 2 1
input
2 31 121 -2
output
1 2
input
4 221 3
output
1 4 3 2

思路:

原题题意太复杂,我把题意简化一下,有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 longlongusing 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;}


0 0
原创粉丝点击