Operation the Sequence

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 842    Accepted Submission(s): 288

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
题意:一个数组经过一系列的变换后得到一个新数组。每次询问新数组的第 k 位的数字。
题解:从已知的位置开始反向推出当前数字最开始所在的位置。计数器用来计算数字已经累乘多少次了,用两个栈维护,反向操作即可。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL; int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
int n,q;
scanf("%d%d",&n,&q);
char s[];
int opr;
stack<int> stk;
stack<int> stk1;
int num = ;
while(q--)
{
scanf("%s%d",s,&opr);
if(s[]=='O')
{
if(opr==||opr==) stk.push(opr);
else num++;
}
else
{
LL ans;
while(!stk.empty())
{
int now = stk.top();
stk.pop();
stk1.push(now);
if(now==) opr = n-opr+;
if(now==)
{
if(n%==)
{
if(opr<=n/+) ///原来是奇数位
{
opr = *opr - ;
}
else
{
opr = (opr - (n/+))*;
}
}
else
{
if(opr<=n/)
{
opr = *opr - ;
}
else
{
opr = *(opr - n/);
}
}
}
}
while(!stk1.empty()){
stk.push(stk1.top());
stk1.pop();
}
ans = opr;
for(int i=; i<num; i++)
{
ans = ans*ans%;
}
printf("%lld\n",ans);
}
}
}
return ;
}

hdu 5063(思路题-反向操作数组)的更多相关文章

  1. hdu 4908(思路题)

    BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. hdu 4857(好题,反向拓扑排序)

    逃生 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  3. Proud Merchants HDU - 3466 (思路题--有排序的01背包)

    Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...

  4. hdu 5101(思路题)

    Select Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  5. hdu 4859(思路题)

    Goffi and Squary Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  6. hdu 5191(思路题)

    Building Blocks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  7. hdu 4956(思路题)

    Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. hdu 5400(思路题)

    Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  9. HDU 1173 思路题

    题目大意 有n个地点(坐标为实数)需要挖矿,让选择一个地点,使得在这个地方建造基地,到n个地点的距离和最短,输出基地的坐标. 题解+代码: 1 /* 2 把这个二维分开看(即把所有点投影到x轴上,再把 ...

随机推荐

  1. Error:Java home supplied via 'org.gradle.java.home' is invalid

    Finally i found my solution. In the project root i found gradle.properties configure this java home ...

  2. PowerCmd

    今天在手机上看慕课网,看到一个好玩的东西.Powercmd. 一开始的感觉是,妈的,我会cmd命令,为什么要用你的cmd? 后来,用了之后,感觉,嗯,还是Powercmd好用.功能强大. 我们来看看它 ...

  3. 批量修改Linux文件夹下所有文件大小写

    小写转大写: [zengs@SYS SOS]$ for cpplive in *; do mv $cpplive `echo $cpplive|tr [a-z] [A-Z]`; done 大写转小写: ...

  4. python - web自动化测试 - 元素操作 - 定位

    # -*- coding:utf-8 -*- ''' @project: web学习 @author: Jimmy @file: find_ele.py @ide: PyCharm Community ...

  5. 使用python 3导入MySQLdb 报No module named 'MySQLdb'异常错误

    MySQLdb只支持Python2.*,还不支持3.* 可以用PyMySQL代替安装PyMySQL后,在使用模块时使用import pymysql as MySQLdb 后续使用方式与MySQLdb  ...

  6. scheduled定时任务cron表达式知识地址

    https://www.cnblogs.com/javahr/p/8318728.html https://www.cnblogs.com/sunjie9606/archive/2012/03/15/ ...

  7. scrapy爬取图片并自定义图片名字

    1   前言 Scrapy使用ImagesPipeline类中函数get_media_requests下载到图片后,默认的图片命名为图片下载链接的哈希值,例如:它的下载链接是http://img.iv ...

  8. Android记事本09

    昨天: Activity的数据传递. 今天: 从Activity中返回数据 请求码和返回码的作用 遇到的问题: 无.

  9. SqlServer中截取小数位数

    方法一:convert(float,字段名) as 别名 select convert(float,round(10.123232,2)) 结果:10.12 select convert(float, ...

  10. PHP文件操作函数及文件指针理解

    知识点: 一.fopen(),文件打开函数,读写参数有: 1.R  : 只读,指针在文件开头 2.r+:读写,指针同上 3.W :只写,写入前会删除文件内容,然后指针回到文件开头,文件不存在则创建 4 ...