HDU - 5036 Operation the Sequence
Problem Description
Then give you m operators, you should process all the operators in order. Each operator is one of four types:
Type1: O 1 call fun1();
Type2: O 2 call fun2();
Type3: O 3 call fun3();
Type4: Q i query current value of a[i], this operator will have at most 50.
Global Variables: a[1…n],b[1…n];
fun1() {
index=1;
for(i=1; i<=n; i +=2)
b[index++]=a[i];
for(i=2; i<=n; i +=2)
b[index++]=a[i];
for(i=1; i<=n; ++i)
a[i]=b[i];
}
fun2() {
L = 1;R = n;
while(L<R) {
Swap(a[L], a[R]);
++L;--R;
}
}
fun3() {
for(i=1; i<=n; ++i)
a[i]=a[i]*a[i];
}
indicating the number of test cases.
The first line of each test case contains two integer n(0<n≤100000), m(0<m≤100000).
Then m lines follow, each line represent an operator above.
1
3 5
O 1
O 2
Q 1
O 3
Q 1
2
4
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
typedef __int64 ll;
//typedef long long ll;
using namespace std;
const int maxn = 100005;
const int mod = 1000000007; int n, m;
int O[maxn];
ll num[maxn]; int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
char str[10];
int op, cnt = 0;
int sum = 0;
for (int i = 0; i < m; i++) {
scanf("%s%d", str, &op);
if (str[0] == 'O') {
if (op == 3)
sum++;
else O[cnt++] = op;
}
else {
for (int j = cnt-1; j >= 0; j--) {
int cur = O[j];
if (cur == 1) {
if (n & 1) {
if (op <= n/2 + 1)
op = op * 2 - 1;
else op = (op - n / 2 - 1) * 2;
}
else {
if (op <= n / 2)
op = op * 2 - 1;
else op = (op - n / 2) * 2;
}
}
else if (cur == 2)
op = n - op + 1;
}
ll ans = op;
for (int i = 0; i < sum; i++)
ans = ans * ans % mod;
printf("%I64d\n", ans);
}
}
}
return 0;
}
HDU - 5036 Operation the Sequence的更多相关文章
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
Operation the Sequence Time Limi ...
- HDU 5063 Operation the Sequence(仔细审题)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...
- hdu 5063 Operation the Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5063 思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值. #include ...
- HDU 5063 Operation the Sequence(暴力 数学)
题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- HDOJ 5063 Operation the Sequence
注意到查询次数不超过50次,那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n). Operation the Sequen ...
- hdu 4893 Wow! Such Sequence!(线段树)
题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...
随机推荐
- Struts2第一个工程helloStruts极其基本配置
前面已经准备好了Struts-2.3.15,现在就可以直接搭建Struts2的工程了.前面http://blog.csdn.net/huangchnegdada/article/details/917 ...
- SE 2014年5月22日
一. 用自己的理解描述 tunnel接口状态 up和down的情况都有哪些 Tunnel接口的状态UP:隧道的目标有可达路由. Tunnel接口的状态Down:隧道的目标路由不可达. 如图配置实验 ...
- 强势围观,CSDN代码引用bug
看我写的一篇blog http://blog.csdn.net/laijieyao/article/details/41014355,在代码上引用了微软雅黑的字体,结果代码显示出来把我给惊呆了 竟然 ...
- Unity3D开发一个2D横版射击游戏
教程基于http://pixelnest.io/tutorials/2d-game-unity/ , 这个例子感觉还是比较经典的, 网上转载的也比较多. 刚好最近也在学习U3D, 做的过程中自己又修改 ...
- Oracle JDBC版本区别(转)
oracle\product\11.2.0\dbhome_1\jdbc\lib ojdbc5.jar ojdbc5dms.jar ojdbc5dms_g.jar ojdbc5_g.jar ojdbc6 ...
- 基于MVC3下拉列表联动(JQuery)
上次项目中遇到一个需要多个下拉列表联动的操作,今天有空将实现方式整理以便以后参考. 要达到的效果是,点击一个下拉框,则另一个下拉框的值发生对应变化.如:选择中国,则另个一下拉框里显示中国各个省份. 传 ...
- lambda left join .DefaultIfEmpty
我们知道lambda表达式在Linq to sql 和 Entity framework 中使用join函数可以实现inner join,那么怎么才能在lambda表达式中实现left join呢?秘 ...
- 线段树(单点更新and成段更新)
线段树需要的空间. 区间为1-->n 假设是一棵完全二叉树,且树高为i. 完全二叉树性质:第i层最多有2^(i-1)个结点. 那么 2^(i-1) = n; i = log2(n) + ...
- 漂亮的表格样式(使用CSS样式表控制表格样式)
根据WEB2.0风格,设计了几个表格样式,我希望你喜欢. WEB2.0推广使用div开放式布局.但并不是完全放弃使用形式,在数据表现形式而言是一个不错的选择. 本节将介绍如何使用现在CSS样式表来控制 ...
- InputStreamReader 和 OutputStreamWriter类使用方法简单介绍,及演示。
InputStreamReader 和 OutputStreamWriter类使用方法简单介绍. 一.InputStreamReader类 InputStreamReader 将字节流转换为字符流.是 ...