D. 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 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

题意:1~n编号的女孩与1~n编号的男孩配对围圈跳舞
两种操作
1 x 若x为正值 所有的男孩顺时针移动x个位置 继续与女孩跳舞 若为负值 则逆时针移动
2 奇偶位置男孩交换位置(这里的奇偶位置是 根据初始的参考位置)
q个操作后 输出与1~n编号的女孩跳舞的男孩的编号序列
题解:
        模拟发现 奇数或偶数 位置的移动量都是相同的;
        只需要模拟出1,2位置的移动量jj,ou; 注意取%
        遍历得出所有序列;
我gou 码
  #include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define ll __int64
#define pi acos(-1.0)
#define mod 1
#define maxn 10000
using namespace std;
int n,qq;
int ans[];
int mo(int qqq)
{return (qqq+*n)%n;}
int main()
{
int jj,ou,ke,k,gg;
scanf("%d %d",&n,&qq);
jj=;ou=;
for(int i=;i<=qq;i++)
{
scanf("%d",&k);
if(k==)
{
scanf("%d",&gg);
jj+=gg;
jj=mo(jj);
ou+=gg;
ou=mo(ou);
}
else
{
if((jj+n)%)
{
jj--;
jj=mo(jj);
ou++;
ou=mo(ou);
}
else
{
jj++;
jj=mo(jj);
ou--;
ou=mo(ou);
}
} }
for(int i=;i<=n;i++)
{
if(i%){
ke=i+jj;
ke=mo(ke);
ans[ke]=i;
}
else{
ke=i+ou;
ke=mo(ke);
ans[ke]=i;
}
}
for(int i=;i<n;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[]);
return ;
}

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D的更多相关文章

  1. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance

    题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...

  2. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学

    C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...

  3. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组

    E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...

  4. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟

    D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...

  5. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟

    C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...

  6. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题

    B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...

  7. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题

    A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...

  8. Codeforces Round #348(VK Cup 2016 - Round 2)

    A - Little Artem and Presents (div2) 1 2 1 2这样加就可以了 #include <bits/stdc++.h> typedef long long ...

  9. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C

    C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input s ...

随机推荐

  1. 网站如何防止sql注入攻击的解决办法

    首先我们来了解下什么是SQL注入,SQL注入简单来讲就是将一些非法参数插入到网站数据库中去,执行一些sql命令,比如查询数据库的账号密码,数据库的版本,数据库服务器的IP等等的一些操作,sql注入是目 ...

  2. Redis缓存数据库的安装与配置(1)

    1.安装 tarxf redis-3.2.5.tar.gz cd redis-3.2.5 make mkdir -p /usr/local/redis/bin src目录下这些文件作用如下 redis ...

  3. anaconda 安装opencv win10

    直接在命令窗口里面运行:pip install opencv-python即可.

  4. .NET CORE LOG

    .NET CORE LOG 合格的应用程序不仅要求运行的高效和计算的准确,稳定及可靠性也要得到满足,同事,系统的可维护性也相当重要.谈及到可维护性,就必须涉及到系统运行状态的监控和异常的快速定位与跟踪 ...

  5. 数据库 MySQL part2

    表记录的操作 增 1.插入一条记录 语法:insert [into] tab_name (field1,filed2,.......) values (value1,value2,.......); ...

  6. Linux 下 PHP 扩展Soap 编译安装

    1.进入 PHP 的软件包 pdo 扩展目录中(注:不是 PHP 安装目录) [root@tester /]# /home/tdweb/php-5.4.34/ext/soap 执行 phpize 命令 ...

  7. 获得通讯录并拨打电话 Android

    由于通讯录在手机里是以数据库贮存的 所以我们可以通过getContentResolver来获得通讯录 ,这个方法返回一个游标的数据类型,通过moveToNext()方法来获取所有的手机号码信息, 当然 ...

  8. ardupilot_gazebo仿真(四)

    ardupilot_gazebo仿真(四) 标签(空格分隔): 未分类 Multi-MAV simulation 参考官网给出的multi-vehicle-simulation的方法 在每次打开sim ...

  9. svm+voting

    # encoding:utf-8 import getopt from sklearn.preprocessing import MinMaxScaler import os,time from mu ...

  10. MyEclipse主题设置

    1. 打开网页: http://eclipsecolorthemes.org/ 选择自己喜欢的主题,并下载(下载epf文件) 我下载的是 Vibrant Ink 2. 下载完成后,打开myeclips ...