前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CodeForces 668B Little Artem and Dance

CodeForces 668B Little Artem and Dance

作者头像
ShenduCC
发布2018-04-26 17:15:29
6960
发布2018-04-26 17:15:29
举报
文章被收录于专栏:算法修养算法修养

B. Little Artem and Dance

time limit per test

2 second

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 number 3swaps 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 000, 1 ≤ 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

代码语言:javascript
复制
6 3
1 2
2
1 2

output

代码语言:javascript
复制
4 3 6 5 2 1

input

代码语言:javascript
复制
2 3
1 1
2
1 -2

output

代码语言:javascript
复制
1 2

input

代码语言:javascript
复制
4 2
2
1 3

output

1 4 3 2

先把1,2的位置确定了,

别的数字的位置变动和1,2肯定是一样的

代码语言:javascript
复制
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;
#define MAX 1000000
int n,q;
int c[MAX+5];
int x,y;
int main()
{
    scanf("%d%d",&n,&q);
    int a=1;int b=2;
    for(int i=1;i<=q;i++)
    {
       scanf("%d",&x);
       if(x==1)
       {
           scanf("%d",&y);
           a=(a+y+n)%n;
		   if(a==0)
			   a=n;
		   b=(b+y+n)%n;
		   if(b==0)
			   b=n;
       }
       else
       {
           if(a&1) a+=1;
           else a-=1;
           if(b&1) b+=1;
           else  b-=1;
       }
    }
	a-=1;
	b-=2;
    for(int i=1;i<=n;i++)
    {
        if(i&1)
        {
            int pos=(i+a)%n;
            if(pos==0)
                pos=n;
            c[pos]=i;
        }
        else
        {
            int pos=(i+b)%n;
            if(pos==0)
                pos=n;
            c[pos]=i;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(i==n)
            printf("%d\n",c[i]);
        else
            printf("%d ",c[i]);
    }
    return 0;

}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-05-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档