Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D
来源:互联网 发布:矩阵半张量积等式的解 编辑:程序博客网 时间:2024/04/28 18:32
D. Little Artem and Dance
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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:
Value x and some direction are announced, and all boys move x positions in the corresponding direction.
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
#include <stdio.h>using namespace std;const int N=1e6+10;int foo[N];int main() { int n,q; scanf("%d%d",&n,&q); int ffx,ddo; int s1=1,s2=2; while(q--){ scanf("%d",&ffx); if(ffx==1){ scanf("%d",&ddo); s1=((s1+ddo+n)%n==0?n:(s1+ddo+n)%n); s2=((s2+ddo+n)%n==0?n:(s2+ddo+n)%n); } else{ if(s1%2) s1++; else s1--; if(s2%2) s2++; else s2--; } } for(int i=1;i<=n;i++){ if(i%2){ int u=s1%n; if(u==0) u=n; foo[u]=i; s1+=2; } else{ int u=s2%n; if(u==0) u=n; foo[u]=i; s2+=2; } } for(int i=1;i<=n;i++) printf("%d ",foo[i]);puts(""); return 0;}
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A B C D 模拟
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A B C D 构造
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- VK Cup 2016 - Round 1 (Div. 2 Edition) C D
- Codeforces VK Cup 2016 - Round 1 (Div. 2 Edition)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C 离散化+树状数组+map D 数学
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B.Problems for Round
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) easy(上)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) ABCD
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
- 【解题报告】Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition)-A. Little Artem and Presents(模拟)
- Lesson 39 Am I all right?
- Jackson详细介绍
- SpringMVC 拦截器
- 后序遍历求解二叉树的高度
- 欢迎使用CSDN-Markdown编辑器写博客
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D
- 图像拉普拉斯金字塔融合(Laplacian Pyramid Blending)
- goto anything
- Spring Security 自定义登陆页面报HTTP Status 403
- mongodb lock 出毛病时解决方法
- 一个ExtJs实例
- 管理后台的登录功能-重新思考
- jQuery-样式(jQuery的属性与样式)
- 排序篇(1)--冒泡排序