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 ...
随机推荐
- 记录一次有用的stackoverflow搜索
经常逛stackoverflow有一段时间了,也遇到了不少问题 问题: 1.ckeditor中在source中输入如下代码 2.再点击source按钮,查看页面显示效果,不对啊 3.然后再检查源码,发 ...
- android
简单的登录
一直都知道WEB通过登录后session拿着回答,如今,安卓不知道怎么弄的. 研究了一下,它记录.直接在代码: server结束: index.jsp <%@page import=" ...
- k8s with flanneld
三台机器 kmaster 192.168.1.201 kslave202 192.168.1.202 kslave203 192.168.1.203 安装好k8s 1. 在Node机器上安装flann ...
- GMSK调制仿真
GMSK 调制的的原理非常简单. 就是MSK调制前进行Gauss滤波. 在实现中有这样的方法,首先产生高斯系数,对称的上升陂和下降陂系数.输入一个符号,进行上采样,经过高斯滤波器,滤波器的输出做有符号 ...
- tc-SRM-626-DIV1-250
枚举alice投掷骰子得到的结果的每一种情况极其数量. 枚举bob投掷骰子得到的结果的每一种情况极其数量. 然后枚举alice投掷骰子得到的结果的数量和bob投掷骰子比alice低的数量. 然后计算结 ...
- 采用Visual Stuidio 2010 创建网站栏
采用Visual Stuidio 2010 创建网站栏 Visual Stuidio 2010 该项目模板使创建网站栏/内容类型和列表变得非常方便. 1. 管理员身份打开Visual Stuidio ...
- JAVA学习第六十二课 — TCP协议练习
通过练习掌握TCP在进行传输过程中的问题 练习1:创建一个英文大写转换server client输入字母数据,发送给服务端,服务端收到后显示到控制台,并将该数据转成大写返回client,知道clien ...
- hdu 4972 A simple dynamic programming problem(高效)
pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...
- bigdata_一篇文看懂Hadoop
本文转载:暂未找到原出处,如需署名 请联系 我们很荣幸能够见证Hadoop十年从无到有,再到称王.感动于技术的日新月异时,希望通过这篇内容深入解读Hadoop的昨天.今天和明天,憧憬下一个十年. 本文 ...
- JSP具体条款——response对象
response对象 response为响应对象client要求.输出信息到客户.他封装JSP反应生成.发送client在回应client要求. 1.重定向网页 使用response对象的sendRe ...