HDOJ 5063 Operation the Sequence
注意到查询次数不超过50次,那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n)。
Operation the Sequence
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 463 Accepted Submission(s): 187
Then give you m operators, you should process all the operators in order. Each operator is one of four types:
Type1: O 1 call fun1();
Type2: O 2 call fun2();
Type3: O 3 call fun3();
Type4: Q i query current value of a[i], this operator will have at most 50.
Global Variables: a[1…n],b[1…n];
fun1() {
index=1;
for(i=1; i<=n; i +=2)
b[index++]=a[i];
for(i=2; i<=n; i +=2)
b[index++]=a[i];
for(i=1; i<=n; ++i)
a[i]=b[i];
}
fun2() {
L = 1;R = n;
while(L<R) {
Swap(a[L], a[R]);
++L;--R;
}
}
fun3() {
for(i=1; i<=n; ++i)
a[i]=a[i]*a[i];
}
indicating the number of test cases.
The first line of each test case contains two integer n(0<n≤100000), m(0<m≤100000).
Then m lines follow, each line represent an operator above.
1
3 5
O 1
O 2
Q 1
O 3
Q 1
2
4
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std; typedef long long int LL; const LL MOD=1000000007LL; int n,m;
char op[10];
int p[110000],np; LL quickpow(LL p,LL x)
{
LL ret=1;
LL e=p;
while(x)
{
if(x%2LL) ret=(ret*e)%MOD;
e=(e*e)%MOD;
x/=2LL;
}
return ret%MOD;
} LL query(int x)
{
LL c=1;
int pos=x;
int half=(n+1)/2;
for(int i=np-1;i>=0;i--)
{
if(p[i]==3) c=(c+c)%(MOD-1);
else if(p[i]==2) pos=n-pos+1;
else if(p[i]==1)
{
if(pos<=half) pos=2*(pos-1)+1;
else pos=(pos-half)*2;
}
}
return quickpow((LL)pos,c);
} int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
np=0;
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
{
int x;
scanf("%s%d",op,&x);
if(op[0]=='O') p[np++]=x;
else if(op[0]=='Q') printf("%I64d\n",query(x));
}
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
HDOJ 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 ...
- 【HDOJ】5063 Operation the Sequence
#include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...
- HDU 5063 Operation the Sequence(仔细审题)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...
- hdu 5063 Operation the Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5063 思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值. #include ...
- HDU 5063 Operation the Sequence(暴力 数学)
题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...
- 思维题 HDOJ 5288 OO’s Sequence
题目传送门 /* 定义两个数组,l[i]和r[i]表示第i个数左侧右侧接近它且值是a[i]因子的位置, 第i个数被选择后贡献的值是(r[i]-i)*(i-l[i]),每个数都枚举它的因子,更新l[i] ...
- HDOJ 5288 OO’s Sequence 水
预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- hdoj 5288 OO’s Sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 //*************头文件区************* #include<ios ...
随机推荐
- java设计模式:观察者模式
package Observer; public class Test { /** * client测试类别 * 观察者模式一般由四部分组成: * 1摘要观察员(教科书被称为一般"Subje ...
- Windows台cocos2d-x 3.2下载一个新的项目,创造的过程
首先,左右cocos2d-x于windows下一个Android建筑环境, 引用一个网友这个博客<cocos2d-x 3.0rc开发指南:Windows下Android环境搭建>. 这里简 ...
- atitit.提升稳定性---hibernate 添加重试retry 机制解决数据库连接关闭
atitit.提升稳定性---hibernate 添加重试retry 机制解决数据库连接关闭 1. 流程总结 retry(5times).invoke(xxx).test().rest().$() t ...
- JavaScript之函数作用域
有过类似C语言编程经验的同学应该都知道“块级作用域(block scope)”:花括号内的每一段代码都具有各自的作用域,而且在声明它们的代码段之外是不可见的.而在JavaScript中是没有块级作用域 ...
- SharePoint 2010 升级到2013时间 为了确保用户可以连接,但无法改变升级数据
SharePoint 2010 升级到2013时间 为了确保用户可以连接,但无法改变升级数据 我总结的步骤 红色请注意它们的含义. 步骤1:连接到SQL DBS 上的SharePoint 2010数据 ...
- jsp 行动标签
jsp行动标签 签.它影响JSP执行时的功能. 1.include动作标签 <jsp:include page="文件名称字"/> 或 <jsp:include ...
- PHP-5.5.10+Apache httpd-2.4.9在Windows系统下配置实战
原文 PHP-5.5.10+Apache httpd-2.4.9在Windows系统下配置实战 环境配置: 程序准备: PHP windows版本下载地址: http://windows.php. ...
- Linux centos 主机名颜色设置 和 别名设置
方便和乐趣写今天.至于为什么主机名颜色设置 和 别名设置放在一起写.这是因为他们的设置是在一个文件中..bashrc. .bashrc放在cd /root 这个文件夹下! 这个文件主要保存个人的一些个 ...
- quick-cocos2d-x游戏开发【6】——制作您自己的自定义效果button菜单
前面提到的主菜单使用,还是很easy的,但我们在商业产品.经常看到button他们人很好,照片不仅就好了,和动画也很不错.Candy Crash都玩过吧,他们看到,button.真的像果冻,效果确实非 ...
- 架构设计之设计模式 (一) 适配器(Adapter)---提高复用性
简介 简介是为了描述一下该模式是干嘛用的,为了让不了解该模式的人看了之后也有一些新的认识. 本文章分为两部分,第一部分主要介绍适配器模式:第二部分介绍该模式与相近模式的异同. 下午一直在讨论设计模式, ...