hdu 5063 Operation the Sequence
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的更多相关文章
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
Operation the Sequence Time Limi ...
- HDU 5063 Operation the Sequence(仔细审题)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...
- HDU 5063 Operation the Sequence(暴力 数学)
题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...
- HDOJ 5063 Operation the Sequence
注意到查询次数不超过50次,那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n). Operation the Sequen ...
- 【HDOJ】5063 Operation the Sequence
#include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...
- 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 ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
随机推荐
- APP安全环节缺失,手游运营商怎样应对APP破解困境
2013年手游行业的规模与收入均实现了大幅增长,发展势头强劲.然而,在手游快速发展的同一时候,因为监管.审核等方面存在着漏洞,手机游戏软件被破解后注入恶意代码.盗取用户財产.窃取用户设备信息的现象屡见 ...
- [转][JAVA]定时任务之-Quartz使用篇
[BAT][JAVA]定时任务之-Quartz使用篇 定时任务之-Quartz使用篇 Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与 ...
- [RxJS] Stream Processing With RxJS vs Array Higher-Order Functions
Higher order Array functions such as filter, map and reduce are great for functional programming, bu ...
- Linux 性能分析工具 nmon for Linux
http://blog.csdn.net/defonds/article/details/41725929 http://blog.csdn.net/fansy1990/article/details ...
- OOP—ECMAScript实现详解
我们将从最基本的数据类型来分析,首先要了解的是ECMAScript用原始值( primitive values) 和对象 ( objects) 来区分实体, 因此有些文章里说的“在JavaScript ...
- 惠普 hpssacli 工具使用
查看raid卡信息(包括控制器状态.Cache状态.电池状态) # hpssacli ctrl all show status 查看raid详细信息 # hpssacli ctrl slot=0 sh ...
- SQL Server中的死锁
简介 死锁的本质是一种僵持状态,是多个主体对于资源的争用而导致的.理解死锁首先需要对死锁所涉及的相关观念有一个理解. 一些基础知识 要理解SQL Server中的死锁,更好的方式是通过类比从更大的面理 ...
- $(document).ready(function(){});不执行
这里可能会有以下几种原因,请你挨个排查: 1.jqury的文件一定要引入1.js文件的引用路径不正确,特别是使用了命名空间,容易造成路径错误,使用绝对路径看是否成功 2.某一些函数使用错误,举个例子, ...
- 分享整理的sql脚本
1. 表空间使用率 SQL> select a.tablespace_name, 2 round(a.total_size) "total_size M" ...
- oracle使用LEFT JOIN关联产生的问题在查询结果中使用CASE WHEN 无法判断
oracle使用LEFT JOIN关联产生的问题在查询结果中使用CASE WHEN 无法判断 查询方式一: SELECT CASE WHEN (SELECT CAST(SUM(CASE ) THEN ...