题目链接:http://codeforces.com/problemset/problem/669/D

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 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 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.整体绕着这个圆圈走x步(正数为顺时针,负数为逆时针)
2.和位置数为奇数的女生跳舞的那个男生要和和位置数为偶数女生跳舞的那个男生交换以下位置,比如和一号女生跳舞的男生要和二号女生跳舞的那个男生交换位置,和3号女生跳舞的那个男生要和4号女生跳舞的那个男生交换位置,以此类推。 解题思路:这个题目看起来挺简单的,就是每次输入一个指令执行完相应的操作就行了的,可是呢,我们来看那一下范围:2 ≤ n ≤ 1 000 000, 1 ≤ q ≤ 2 000 000(n为人数,q为指令数),这么大的区间,如果我们一个一个执行操作的话,需要好多次循环,这样肯定是会超时的,所以我们想是否有什么巧妙的方法可以一次性知道他们最后的位置会怎样呢?可能先想到得应该是记录下执行了几次1操作执行了几次2操作,然后根据1操作的次数和2操作的次数来确定最后他们的位置吧,但是这样确实错的,因为先交换位置再整体移动和先整体移动在交换是不一样的,反正很乱,而且也不行,自己带几组数据试试就知道了。这时候,我们就仔细分析下两个操作的特点,第一个操作就是整体移动多少个位置,而第二个操作就是简单两个人交换位置,总人数为偶数,仔细想想我们就可以发现奇数位置的男生的相对位置压根就是不改变的,偶数位置的男生也是如此,意思就是1 3 5 7 9 ……这些男生的相对位置不会发生改变,同样2 4 6 8 ……也是如此。那题目就可以变得简单了,我们直接从开始几率1号男生和2号男生的位置就好了,就相当于记录了全部的奇数位置的男生和偶数位置的男生了,每次操作,我们对1号男生和2号男生进行更新即可,全部指令执行完毕后,我们通过1号2号男生的位置就可以填不上其他男生的位置了。思路就是这样子的,不过感觉好像不是很简单想出来那。。。。
附上AC代码:
 #include<iostream>
#include<cstdio>
using namespace std;
int n,q,k,cnt;
int d[]; int main()
{
scanf("%d%d",&n,&q);
int fir=,sec=; //用来记录1号男生和2号男生的位置
while(q--)
{
scanf("%d",&k);
if(k==)
{
scanf("%d",&cnt); //整体移动cnt个位置,注意是个圈
fir=(fir+cnt+n)%n;
sec=(sec+cnt+n)%n;
}
else
{
if(fir%==) //交换位置,先判断两个人的相对位置
{
fir=(fir++n)%n;
sec=(sec-+n)%n;
}
else
{
fir=(fir-+n)%n;
sec=(sec++n)%n;
}
}
}
for(int i=;i<n;i+=)
{
d[(fir+i)%n]=i+; //奇数列男生位置填充
d[(sec+i)%n]=i+; //偶数列男生位置填充
}
for(int i=;i<n;i++)
{
if(i==) printf("%d",d[i]);
else printf(" %d",d[i]);
}
printf("\n");
return ;
}

CodeForces - 669D的更多相关文章

  1. Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)

    题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...

  2. CodeForces - 669D Little Artem and Dance 想法题 多余操作

    http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...

  3. CodeForces 669D Little Artem and Dance

    模拟. 每个奇数走的步长都是一样的,每个偶数走的步长也是一样的. 记$num1$表示奇数走的步数,$num2$表示偶数走的步数.每次操作更新一下$num1$,$num2$.最后输出. #pragma ...

  4. CodeForces - 669D——(思维题)

    Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced b ...

  5. codeforces 669D D. Little Artem and Dance(乱搞题)

    题目链接: D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes in ...

  6. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  9. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. C#一些常用的图片操作方法:生成文字图片 合并图片等

    生成文字图片: /// <summary> /// 生成文字图片 /// </summary> /// <param name="text">& ...

  2. WPF开发汽车采样机上位机软件

    由于项目需要,需开发同一套汽车.火车.皮带采样机的上位机软件. 看过之前的上位机软件,老版本都是DelPhi.VB开发,稍微新语言开发的是采用winform开发.要不就是使用组态软件. Delphi语 ...

  3. HTTP Error 500.22 - Internal Server Error 错误解决方案

    1. 首先进入IIS ,配置IIS 应用程序池的.Net Framework版本 2. 点击左侧应用程序池,再单机右侧设置,选择版本 3. 设置为经典模式 如若遇到以下错误: 解决方案:删除confi ...

  4. openpyxl 实现excel字母列号与数字列号之间的转换

    https://www.cnblogs.com/apple2016/p/9686433.html

  5. 作业20171130 final发布 成绩

    申诉 对成绩有疑问或不同意见的同学,请在群里[@杨贵福]. 申诉时间截止2017年12月16日 17:00. 更新 第一周和第二周成绩分别应占比20%和10%,计算时刚好反了.所以同学们的最终成绩有变 ...

  6. Linux内核分析 读书笔记 (第十八章)

    第十八章 调试 18.1 准备开始 1. 需要的只是: 一个bug 一个藏匿bug的内核版本 相关内核代码的知识和运气 2. 在跟踪bug的时候,掌握的信息越多越好. 18.2 内核中的bug 1.  ...

  7. sqlalchemy 使用pymysql连接mysql 1366错误

    一.错误情况 mysql 5.7.2 \python35\lib\site-packages\pymysql\cursors.py:166: Warning: (1366, "Incorre ...

  8. PAT 1032 挖掘机技术哪家强

    https://pintia.cn/problem-sets/994805260223102976/problems/994805289432236032 为了用事实说明挖掘机技术到底哪家强,PAT组 ...

  9. 同步或者重构Activiti Identify用户数据的多种方案比较

    http://www.kafeitu.me/activiti/2012/04/23/synchronize-or-redesign-user-and-role-for-activiti.html 如何 ...

  10. linux_查看磁盘与目录容量

    一.查看磁盘容量命令df(report file system disk space usage) 终端运行 $ df 输出结果 我的物理主机上的 /dev/sda5 是对应着主机硬盘的分区,字母 a ...