HDU 5063 Operation the Sequence

题目链接

把操作存下来。因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置。输出就可以

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long ll;
const int N = 100005;
const ll MOD = 1000000007; int t, n, m, c;
ll a[N];
int op[N], on;
char str[3]; ll pow_mod(ll x, ll k) {
ll ans = 1;
while (k) {
if (k&1) ans = ans * x % MOD;
x = x * x % MOD;
k >>= 1;
}
return ans;
} ll solve(int c) {
ll mul = 1;
for (int i = on - 1; i >= 0; i--) {
if (op[i] == 1) {
if (c > (n + 1) / 2) c = (c - (n + 1) / 2) * 2;
else c = (c - 1) * 2 + 1;
} else if (op[i] == 2) c = n - c + 1;
else mul = mul * 2 % (MOD - 1);
}
return pow_mod(a[c], mul);
} int main() {
scanf("%d", &t);
while (t--) {
on = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) a[i] = i;
while (m--) {
scanf("%s%d", str, &c);
if (str[0] == 'O') op[on++] = c;
else printf("%lld\n", solve(c));
}
}
return 0;
}

HDU 5063 Operation the Sequence(暴力)的更多相关文章

  1. hdu 5063 Operation the Sequence(Bestcoder Round #13)

    Operation the Sequence                                                                     Time Limi ...

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

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

  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

    http://acm.hdu.edu.cn/showproblem.php?pid=5063 思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值. #include ...

  5. HDOJ 5063 Operation the Sequence

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

  6. HDU 5273 Dylans loves sequence 暴力递推

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  7. 【HDOJ】5063 Operation the Sequence

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

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

  9. HDU 6274 Master of Sequence (暴力+下整除)

    题意 两个1e5的数组a,b,定义\(S(t)=\left \lfloor \frac{t-b_i}{a_i} \right \rfloor\),有三个操作 1 x y:将\(a[x]\)变为\(y\ ...

随机推荐

  1. Android插件化原理解析——Hook机制之动态代理

    转自 http://weishu.me/2016/01/28/understand-plugin-framework-proxy-hook/ 使用代理机制进行API Hook进而达到方法增强是框架的常 ...

  2. HTML+CSS+JS总结

    ==================HTML(超文本标记语言)========== <!DOCTYPE> 声明位于文档中的最前面的位置,处于 <html> 标签之前.此标签可告 ...

  3. POJ 1523 Tarjan求割点

    SPF Description Consider the two networks shown below. Assuming that data moves around these network ...

  4. 网络开发之使用Web Service和使用WCF服务

    判断是否有可用网络连接可以通过NetworkInterface类中的GetIsNetworkAvailable来实现: bool networkIsAvailable = networkInterfa ...

  5. 【HTTP】长连接和短连接

    1. HTTP协议与TCP/IP协议的关系 HTTP的长连接和短连接本质上是TCP长连接和短连接.HTTP属于应用层协议,在传输层使用TCP协议,在网络层使用IP协议.IP协议主要解决网络路由和寻址问 ...

  6. [转]JAVA回调机制(CallBack)详解

    看见一篇博客比较通俗的解释了回调机制,转载一下,感谢原文作者Bro__超,原文地址:http://www.cnblogs.com/heshuchao/p/5376298.html 序言 最近学习jav ...

  7. for 循环练习题(2)

    一张纸的厚度是0.0001米,将纸对折,对折多少次厚度超过珠峰高度8848米 var x=0.0001; for(var a=1;true;a++){ x=x*2; if (x>8848) { ...

  8. WinDbg使用

    1.抓dump文件 程序崩溃(crash)的时候, 为了以后能够调试分析问题, 可以使用WinDBG要把当时程序内存空间数据都保存下来,生成的文件称为dump 文件. 步骤: 1) 打开WinDBG并 ...

  9. 【技术累积】【点】【java】【19】访问权限

    java中的四种访问权限 范围如下表 权限 类内 同包 不同包子类 不同包非子类 Public ✔️ ✔️ ✔️ ✔️ 默认(Default) ✔️ ✔️ ️ Protected ✔️ ✔️ ✔️ P ...

  10. Mac下php连接mysql数据库失败解决办法

    通过phpmyadmin连接mysql成功,但是通过php连接数据库失败,执行如下php语句 ? 1 @mysql_connect("localhost","root&q ...