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 2 dances with a girl number 2and 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 3 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 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
6 3
1 2
2
1 2
Output
4 3 6 5 2 1
Input
2 3
1 1
2
1 -2
Output
1 2
Input
4 2
2
1 3
Output
1 4 3 2

题意:有n对男女围成一个圈跳舞,初始状态时,按顺时针给他们标上1-n号,男生1号和女生1号跳舞,男生2号和女生2号.....男生n号和女生n号。然后就下来有2种操作,操作1是所有男生移动 i 个位置,若 i 为负数,则向顺时针移动i个位置;
否则,操作2是相邻的两个男生交换位置。在所有操作中,牛生是不动的。问,在一系列操作之后,女生1-n对应的男生分别是多少号。 思路:在移动的过程中,一个数左右的数虽然在不断的改变,但是可以发现一点,所有奇数的相对位置不会改变,所有偶数的相对位置不会改变。
因为如果是移动一定的位置,是不会改变所有数的相对位置的;而如果是交换,则奇数之间是同步交换的,而偶数之间也是同步交换的。
所以,不管如何操作,一个奇数左边的第一个奇数和右边的第一个奇数都是不会改变的,偶数也是如此。(即相对位置没有改变)。
所以,这题的解法就明了了:我们可以记录下数字1和2的位置,开始时,数字1就在第一位,数字2就在第二位,若他们移动,标记也跟着移动。
确定了1和2的位置之后,就能推出所有数的位置了。 代码:
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#define eps 1e-7
#define ll long long
#define inf 0x3f3f3f3f
#define pi 3.141592653589793238462643383279
using namespace std;
int ans[];
int main()
{
int n,m,oper,far;
while(cin>>n>>m)
{
int sum = ;
int flag1 = ,flag2 = ; //flag1标记1的位置(初始在第一个位置 0),flag2标记2的位置(初始在第二个位置1)
for(int i=; i<m; ++i)
{
scanf("%d",&oper);
if(oper == ) //如果是操作1,表示是平移
{
scanf("%d",&far);
flag1 += far; //标记也平移
flag2 += far;
flag1 = (flag1%n + n)%n; //为防止超过范围,要进行取模
flag2 = (flag2%n + n)%n;
}
else //操作2是交换
{
if(flag1%==) flag1++; //若 1 在偶数位置,则说明是和右边的交换
else flag1--; //否则和左边交换(下标从 0 开始) if(flag2%==) flag2++; // 2 同理
else flag2--; flag1 = (flag1%n + n)%n; //取模防越界
flag2 = (flag2%n + n)%n;
}
}
for(int i=; i<n; i+=) //根据1,2的位置推出所有数的位置
{
ans[(flag1+i)%n] = i+;
ans[(flag2+i)%n] = i+;
}
for(int i=; i<n; ++i)
printf("%d%c",ans[i],i==n-?'\n':' ');
}
return ;
}

CodeForces - 669D——(思维题)的更多相关文章

  1. Codeforces 424A (思维题)

    Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  2. Vova and Trophies CodeForces - 1082B(思维题)

    Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trop ...

  3. CodeForces - 417B (思维题)

    Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status ...

  4. CodeForces - 417A(思维题)

    Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit  ...

  5. B - Sonya and Exhibition CodeForces - 1004B (思维题)

    B. Sonya and Exhibition time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题

    http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...

  7. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  8. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

  10. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

随机推荐

  1. 7z 7zip 日期、时间,文件名

    from: http://hi.baidu.com/guicomeon/item/c0957c373972fbc52f8ec26e 先说明一点,要注意区分当前所使用的系统,中文系统和英文系统是有区别的 ...

  2. bzoj1811 mea

    Description 考虑一个非递减的整数序列 S1,....Sn+1(Si<=Si+1  1<=i<=n). 序列M1...Mn是定义在序列S的基础上,关系式为 Mi=( Si ...

  3. Java 将字符串转换为字符数组 toCharArray()

    Java 手册 toCharArray public char[] toCharArray() 将此字符串转换为一个新的字符数组. 返回: 一个新分配的字符数组,它的长度是此字符串的长度,它的内容被初 ...

  4. ROS创建Web代理(Web proxy)给QQ使用HTTP代理

    使用Web代理可以提高网页的访问速度,因为访问的数据会存储在内存或是硬盘中,就会直接从代理服务器中读取.同时,为了提高网络访问的安全性,可以给Web代理服务器设置相应的权限,使它的安全性得到提高. 下 ...

  5. win7右下角的网络连接图标不见了~终极必杀技

    1.打开程序管理器(ctrl+alt+delete) 2.在进程那里找到"explorer.exe",然后按结束进程(此时工具栏会消失) 3.然后在文件(程序管理器左上角),点击& ...

  6. MySQL创建函数报“ERROR 1418 ”错误,不能创建函数

    MySQL创建函数报ERROR 1418错误,不能创建函数,根据官方提示是说,不能创建函数可能是一个安全设置方面的配置或功能未开启原因,下面我们一起来看.   错误 ERROR 1418 (HY000 ...

  7. django2.0设置默认访问路由

    搭建完毕后,打开域名,直接来个报错,如果没有访问的地址,是不合适的 在urls.py中定义,默认访问的路由 from django.contrib import admin from django.u ...

  8. verilog 计算机网络 仿真 激励 pcap

    做verilog网络逻辑时,需要产生正确的数据包格式激励,手写激励真烦人,现在让testbench读取pcap文件,则可以精确还原数据包的bit与时序,省去了一大批麻烦 1.设计读取逻辑 `times ...

  9. Spring MVC 学习 之 - URL参数传递

    在学习 Spring Mvc 过程中,有必要来先了解几个关键参数:    @Controller: 在类上注解,则此类将编程一个控制器,在项目启动 Spring 将自动扫描此类,并进行对应URL路由映 ...

  10. Spring JDBC Framework详解——批量JDBC操作、ORM映射

    转自:https://blog.csdn.net/yuyulover/article/details/5826948 一.spring JDBC 概述 Spring 提供了一个强有力的模板类JdbcT ...