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

只有50个询问,50个操作逆推回去即可,注意mul每次要*2%(modo
- 1)因为是指数!

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL; int n,m;
const double pi = acos ( -1.0 ) ;
const LL modo = 1000000007;
int op[100005],op_n;
LL ans[55];
int ans_n;
LL quick_pow(LL a,int b)
{
LL c = 1;
while(b){
if(b&1)
c = (c*a)%modo;
b>>=1;
a = (a*a)%modo;
}
return c;
}
LL gao(LL x)
{
int mul = 1;
for(int i = op_n - 1;i >= 0;--i){
if(op[i] == 1){
// 1,3,5->1,2,3
// 2,4,6->4,5,6 // 1,3,5,7->1,2,3,4
// 2,4,6->5,6,7
if(x <= (n+1)/2)
x = x*2 - 1;
else
x = (x - (n+1)/2)<<1;
}
else if(op[i] == 2){
x = n + 1 - x;
}
else{
mul = (mul*2)%(modo-1);
}
}
return quick_pow(x,mul);
}
void work()
{
op_n = ans_n = 0;
LL x;
char q[2];
while(m--){
scanf("%s%I64d",q,&x);
if(q[0] == 'O'){
op[op_n++] = (int)x;
}else{
ans[ans_n++] = gao(x);
}
}
for(int i = 0;i < ans_n;++i)
printf("%I64d\n",ans[i]);
return;
}
int main () {
int T;
RD(T);
while(T--){
RD2(n,m);
work();
}
return 0 ;
}

hdu 5063 操作逆推+mul每次要*2%(modo - 1)的更多相关文章

  1. HDU 5844 LCM Walk(数学逆推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意: 现在有坐标(x,y),设它们的最小公倍数为k,接下来可以移动到(x+k,y)或者(x,y+k).现 ...

  2. hdu 3853 LOOPS (概率dp 逆推求期望)

    题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Tota ...

  3. HDU 1176-免费馅饼(DP_逆推)

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  4. HDU 5063 Operation the Sequence(仔细审题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...

  5. HDU 5063 Operation the Sequence(暴力)

    HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...

  6. HDU 5063 Operation the Sequence(暴力 数学)

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

  7. Codeforces Round #499 (Div. 2) C.FLY 数学推导_逆推

    本题应该是可以使用实数二分的,不过笔者一直未调出来,而且发现了一种更为优美的解法,那就是逆推. 首先,不难猜到在最优解中当飞船回到 111 号节点时油量一定为 000, 这就意味着减少的油量等于减少之 ...

  8. Natas11 Writeup(常见编码、异或逆推、修改cookie)

    Natas11: 页面提示cookie被异或加密保护,查看源码,发现了一个预定义参数和三个函数. //预定义参数,猜测将showpassword设置为yes即可得到密码. $defaultdata = ...

  9. UVA116Unidirectional TSP(DP+逆推)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18206 题意:M*N的数阵,从左边一列到右边一列走过的数的和的最小.并输出路 ...

随机推荐

  1. hadoop+zookeeper(ha架构搭建)

    http://blog.csdn.net/baidu_25820069/article/details/52225293 [条件所限,待验证]

  2. 分类模型评估之ROC-AUC曲线和PRC曲线

    http://blog.csdn.net/pipisorry/article/details/51788927 在样本分布及其不均匀的情况下,建议用PRC...可以看下这个精确率.召回率.F1 值.R ...

  3. 如何设置maven的local repository目录

    step1:默认会放在~/.m2/repository目录下 (“~”代表用户的目录,比如windows下一般都是C:\Documents and Settings\[你的用户名]\.由于“Docum ...

  4. 115. Distinct Subsequences (String; DP)

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  5. Java中Generics的使用

    1.Java的Generics与C++的Template由于Java的Generics设计在C++的Template之后,因此Java的Generics设计吸取Template的很多经验和教训.首先, ...

  6. python笔记之str常用方法

    #Auther Bob#--*--conding:utf-8 --*--# s1 = 'aBcdE1d'# ============================================== ...

  7. Spring框架的IOC之注解方式的快速入门

    1. 步骤一:导入注解开发所有需要的jar包 * 引入IOC容器必须的6个jar包 * 多引入一个:Spring框架的AOP的jar包,spring-aop的jar包 2. 步骤二:创建对应的包结构, ...

  8. Parallel.Foreach的基础知识

    微软的并行运算平台(Microsoft’s Parallel Computing Platform (PCP))提供了这样一个工具,让软件开发人员可以有效的使用多核提供的性能. Visual Stud ...

  9. [z]Windows 下基于 Eclipse 的可视化远程 Linux C/C++ 开发环境搭建

    http://blog.csdn.net/lostaway/article/details/8086056 1.简介 Windows 下远程 Linux 开发工具,比较著名的就是 WinGDB 和 M ...

  10. 品味性能之道<六>:图形化SQL分析工具

         在上一章里,重点分享了命令行SQL分析工具的使用方法.在本章将重点分享PL/SQL的SQL分析工具. 一.如何打开PL/SQL执行计划      开启PL/SQL这工具,推荐如下方法: 点击 ...