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. ExtractNewFolderPath

    unit Unit1; interface uses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,  Syst ...

  2. [Reactive Programming] Async requests and responses in RxJS

    We will learn how to perform network requests to a backend using RxJS Observables. A example of basi ...

  3. 一个备份MySQL数据库的简单Shell脚本(转)

    Shell脚本是我们写不同类型命令的一种脚本,这些命令在这一个文件中就可以执行.我们也可以逐一敲入命令手动执行.如果我们要使用shell脚本就必须在一开始把这些命令写到一个文本文件中,以后就可以随意反 ...

  4. Java语言基础(五)

    Java语言基础(五) 一.浮点数 浮点数就是小数,其标准是IEEE 754,用指数和尾数表示 例如30000=3*10000=3*10^4  其中4是指数,3是尾数 Java中,浮点数有float ...

  5. Java基础知识强化08:将字符串倒序输出(包括空格)的几种方法

    1.最容易想到的估计就是利用String类的toCharArray(),再倒序输出数组的方法了: package himi.hebao05; public class TestDemo02 { pub ...

  6. CUDA与VS2013安装

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  7. 关于pv的那些事!!

    遗留问题:whid=1969的日志记录是什么意思? 网站站点信息未分配的时候,会用1969去代替站点信息. PV:页面浏览量(page view),用户每次打开或刷新一次网页即被计算一次. 关于pv的 ...

  8. HTML5 WebAudioAPI简介(一)

    一.常用对象 1.AudioContext对象 AudioContext是一个专门用于音频处理的接口,并且原理是讲AudioContext创建出来的各种节点(AudioNode)相互连接,音频数据流经 ...

  9. Adb工具常用操作(一)

    一.启动或关闭server 1.3  Android SDK中的常用命令行工具 在<Android SDK安装目录>\tools目录中带了很多命令行工具.虽然一般的开发人员并不需要完全掌握 ...

  10. vim字符串替换

    vi/vim 中可以使用 :s 命令来替换字符串.以前只会使用一种格式来全文替换,今天发现该命令有很多种写法(vi 真是强大啊,还有很多需要学习),记录几种在此,方便以后查询. :s/vivian/s ...