Problem Description
You have an array consisting of n integers: a1=1,a2=2,a3=3,…,an=n.
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];

}
 
Input
The first line in the input file is an integer T(1≤T≤20),
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.
 
Output
For each test case, output the query values, the values may be so large, you just output the values mod 1000000007(1e9+7).
 
Sample Input
1
3 5
O 1
O 2
Q 1
O 3
Q 1
 
Sample Output
2
4
 
Source
 
题意:O1操作是将奇数位置的下标放到前面。偶数放到后面,O2是将序列翻转,O3是序列平方,求每次Q下标的数是多少
思路:注意到查询次数不超过50次。那么能够从查询位置逆回去操作。就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n)。
#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的更多相关文章

  1. HDU 5063 Operation the Sequence(暴力)

    HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...

  2. hdu 5063 Operation the Sequence(Bestcoder Round #13)

    Operation the Sequence                                                                     Time Limi ...

  3. HDU 5063 Operation the Sequence(仔细审题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...

  4. hdu 5063 Operation the Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=5063 思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值. #include ...

  5. HDU 5063 Operation the Sequence(暴力 数学)

    题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...

  6. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  7. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  8. HDOJ 5063 Operation the Sequence

    注意到查询次数不超过50次,那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n). Operation the Sequen ...

  9. 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区间上的所以数变成 ...

随机推荐

  1. hdu 5015 233 Matrix(构造矩阵)

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...

  2. 每天一个JavaScript实例-递归实现反转数组字符串

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  3. zoj3201(树形dp)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3201 题意:给一棵树, n结点<=1000, 和K < ...

  4. 收藏的一段关于java大数运算的代码

    收藏的一段关于java大数运算的代码: package study_02.number; import java.math.BigDecimal; import java.math.BigIntege ...

  5. 4句代码读取Excel到DataSet(非Excel组件)

    Toxy是继NPOI之后主推的还有一个项目,主要目的是为了解决文档的抽取问题.其支持的格式包括全部docx.xlsx.xls.csv.vcard等. 以下是一个简单但非常实用的样例 ParserCon ...

  6. linuxserver启动过程

    随着Linux的应用日益广泛.特别是在网络应用方面,有大量的网络server使用Linux操作系统.因为Linux的桌面应用和Windows相比另一 定的差距.所以在企业应用中往往是Linux和Win ...

  7. iosclient暑期“动画屋“活动项目总结

        入职实习的这个公司,第一天就分配了任务.从零開始写一个网页.之前尽管了解一些前端知识.但从头开写还是遇到了非常多问题,互联网公司讲求效率,有deadline还是比較有紧迫感的,与在实验室放羊状 ...

  8. Eclipse 快捷键整理

    Alt+/:代码提示Ctrl+/:注释/取消注释Ctrl+D:删除光标所在行Ctrl+K:将光标停留在变量上,按Ctrl+K键可以查找到下一个同样的变量Shift+Ctrl+K:和Ctrl+K查找的方 ...

  9. Libevent API

    evtimer_new evtimer_new(base, callback, NULL) 用来做定时器,即当达到一定时间后调用回调函数callback.用evtimer_add激活定时器.比如: m ...

  10. 赤裸裸的splay平衡树

    HYSBZ1588 http://www.lydsy.com/JudgeOnline/problem.php?id=1588 给我们n天的营业额, 要求出每天的最小波动值,然后加起来.  当天最小波动 ...