http://acm.hdu.edu.cn/showproblem.php?pid=5063

思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值。

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int mod=; int n,m;
char str[];
int a[]; ll pow_mod(ll a,ll p,ll n)
{
if(p==) return ;
ll ans=pow_mod(a,p/,n);
ans=ans*ans%n;
if(p%==) ans=ans*a%n;
return ans;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
scanf("%d%d",&n,&m);
getchar();
char op;
int cnt=;
int pos=;
int mid=(n+)/;
int x;
for(int i=; i<=m; i++)
{
scanf("%c",&op);
if(op=='O')
{
scanf("%d",&x);
a[i]=x;
}
else if(op=='Q')
{
scanf("%d",&x);
pos=x;
int c=;
for(int j=i-; j>=; j--)
{
if(a[j]==)
{
if(pos<=mid)
pos=pos*-;
else
pos=(pos-mid)*;
}
else if(a[j]==)
{
pos=n-pos+;
}
else if(a[j]==)
{
c=(c+c)%(mod-);
}
}
printf("%d\n",pow_mod(pos,c,mod));
}
getchar();
}
}
return ;
}

hdu 5063 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(暴力 数学)

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

  5. HDOJ 5063 Operation the Sequence

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

  6. 【HDOJ】5063 Operation the Sequence

    #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...

  7. HDU - 5036 Operation the Sequence

    Problem Description You have an array consisting of n integers: a1=1,a2=2,a3=3,-,an=n. Then give you ...

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

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

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

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

随机推荐

  1. Hadoop平台提供离线数据和Storm平台提供实时数据流

    1.准备工作 2.一个Storm集群的基本组件 3.Topologies 4.Stream 5.数据模型(Data Model) 6.一个简单的Topology 7.流分组策略(Stream grou ...

  2. [置顶] Java Web开发教程来袭

    Java Web,是用Java技术来解决相关web互联网领域的技术总和.web包括:web服务器和web客户端两部分.Java在客户端的应用有java applet不过现在使用的很少,Java在服务器 ...

  3. [转] Mac 下 PostgreSQL 的安装与使用

    在 mac 下,可以利用 homebrew 直接安装 PostgreSQL: 1 brew install postgresql -v 稍等片刻,PostgreSQL 就安装完成.接下来就是初始数据库 ...

  4. Android自定义Notification并没有那么简单

    背景 最近需要实现一个自定义Notification的功能.网上找了找代码,解决方案就是通过RemoteViews来实现.但是在实现过程中遇到不少问题,网上也没有很好的文章描述这些问题,所以在这里做个 ...

  5. Python获取Origin官网视频

    程序说明:最近学习origin,看到官网有入门视频(http://www.originlab.com/index.aspx?go=SUPPORT/VideoTutorials),看着挺多的,就用pyt ...

  6. Node.js + Express + Mongodb 开发搭建个人网站(一)

    一.Node + Express环境搭建 0.去Node官网下载安装node,如果安装了 npm 和 node的话 那么就 安装 全局的 express,-g全局安装 npm install expr ...

  7. $(this).next()与$(this).children()

    $(this).next() 当前元素同级的下个元素,而非子元素 $(this).children() 是当前元素的下一级元素的集合,就是子元素的集合,而不管子元素的后代元素 所以这两个没有什么可比性 ...

  8. 转载:修改xshell中文乱码的问题(管用)

    执行echo $LANG命令输出的是当前的编码方式,执行locale命令得到系统中所有可用的编码方式.要让Xshell不显示乱码,则要将编码方式改为UTF-8. 在Xshell中[file]-> ...

  9. 让ie6/7/8兼容css3的圆角阴影等特殊效果的方法 PIE1.0.0及placeholder在这些IE下生效的方法

    PIE地址:http://css3pie.com/ 使用方法1: #login,#AnnouncementBox {  border:3px solid #fff;  -webkit-border-r ...

  10. ASP.NET Excel数据导出数据库

    /// <summary> /// 根據gridview導出excel /// </summary> /// <param name="ctl"> ...