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. laravel5.5授权系统

    目录 1. Gates 1.1 一个简单的使用Gates的例子 1.2 编写Gates 1.3 授权动作 2. policy策略 2.1 还是先看个例子 2.2 编写策略 2.3 授权策略 2.3.1 ...

  2. Android学习记录(10)—Android之图片颜色处理

    你想做到跟美图秀秀一样可以处理自己的照片,美化自己的照片吗?其实你也可以自己做一个这样的软件,废话不多说了,直接上图,上代码了! 效果图如下: 没处理前: 处理之后: MainActivity.jav ...

  3. 架构师速成6.7-设计开发思路-uml 分类: 架构师速成 2015-07-29 18:25 157人阅读 评论(0) 收藏

    uml是什么东西?统一建模语言,一门语言,是用来进行软件设计的一门语言. 其实一门语言的诞生并不伟大,让大多数人都使用才足够伟大.uml就是一门伟大的语言,因为目前软件设计的唯一语言就是它. UML其 ...

  4. PhpStorm 格式化中花括号缩进方式

    格式化前: function func() { return ; } 格式化后: function func() { return ; } 在PhpStorm中的配置:File -> Setti ...

  5. win 7 查看端口被占用

    开始---->运行---->cmd,或者是window+R组合键,调出命令窗口     输入命令:netstat -ano,列出所有端口的情况.在列表中我们观察被占用的端口,比如是4915 ...

  6. (转\整)UE4游戏优化 多人大地型游戏的优化(四)内存的优化

    施主分享随缘,评论随心,@author:白袍小道,当苦无妨 小道暗语: 1.因为小道这里博客目录没自己整,暂时就用随笔目录结构,所以二级目录那啥就忽略了.标题格式大致都是(原or转) 二级目录 (标题 ...

  7. [python] 网络数据采集 操作清单 BeautifulSoup、Selenium、Tesseract、CSV等

    Python网络数据采集操作清单 BeautifulSoup.Selenium.Tesseract.CSV等 Python网络数据采集操作清单 BeautifulSoup.Selenium.Tesse ...

  8. 深入理解css之absolute

    在慕课网上看到的张鑫旭大神的视频,做的笔记,以便日后翻看. 绝对定位与float 1.绝对定位和float有一样的特性,都有包裹性,和破坏性. 2.absolute和relative 如果不把他们俩放 ...

  9. 在Struts2 Action中快速简便的访问Request、Session等变量

    前言——正常情况下如何在Action中获取到这些变量 全部方法(共四种)可以参考:http://blog.csdn.net/itmyhome1990/article/details/7019476 这 ...

  10. canvas 基础

    1.<canvas>元素 <canvas id="tutorial" width="150" height="150"&g ...