题目链接: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. 性能调优之vmstat命令

    vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.IO读写.CPU活动等进行监视.它是对系统的整体情况进行统计,不足之处是无法对某 ...

  2. python语言程序设计3

    1, 起码坚持每天  半小时吧... 2, 上面有常用的几个数据类型..整数类型和字符串类型还行,但是列表类型的话就很蛋疼了. 3, 字符串类型的显著特点是在两侧有单引号或者双引号.用单引号和双引号表 ...

  3. Html页面雪花效果的实现

    简单介绍 昨天修改了一下博客所用的模板,冬天来了,给自己的博客加点雪花,感觉更有意境. 百度找到了非常多的结果,最终还是选用了cfs.snow.js,很赞压缩之后只有1kb左右,而且不会影响页面使用, ...

  4. bootstrapTable使用场景及方式

    场景一:混合开发,适用jsp.php前端不足  纯html结构 <div> <table id="table" data-toggle="table&q ...

  5. 该如何以正确的姿势插入SVG Sprites?

    大家好,我是苏南,今天要给大家分享的是SVG sprite(也叫雪碧图),所谓雪碧图,当然就不是我们常喝的雪碧饮料(Sprites)哦,哈哈- 当下流程的移动端,手机型号太多太多,今天工作项目中突然发 ...

  6. CentOS7下单机部署RabbltMQ环境的操作记录

    一.RabbitMQ简单介绍在日常工作环境中,你是否遇到过两个(多个)系统间需要通过定时任务来同步某些数据?你是否在为异构系统的不同进程间相互调用.通讯的问题而苦恼.挣扎?如果是,那么恭喜你,消息服务 ...

  7. Jmeter-使用Ultimate Thread Group插件来设置负载场景

    前言: Jmeter插件相关请移步:https://www.jianshu.com/p/130c7fddeddf 自定义线程组:jp@gc - Ultimate Thread Group,功能强大,可 ...

  8. mac下查看和设置环境变量

    1.查看环境变量 命令    env 2.修改环境变量 命令    cd ~ && ls -a && sudo vim .bashrc 编辑输入要添加的环境变量 3.s ...

  9. 饿了么element UI<el-dialog>弹出层</el-dialog>修改默认样式不能在<style scoped>修改

    如果在非scoped下,修改el-dialog自动添加的DIV类名的style加上important,可以覆盖原来的width,但这样会让整个项目的样式都乱套. 如果在scoped下修改style.所 ...

  10. C. Vasya and Multisets

    传送门 [http://codeforces.com/contest/1051/problem/C] 题意 给你一堆数,问是否可以分为两堆使得两堆里只出现一下的数字的种类相等,可以输出任意一种分的方式 ...