hdu 5063 Operation the Sequence(Bestcoder Round #13)
Operation the Sequence
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768
K (Java/Others)
Total Submission(s): 158 Accepted Submission(s): 74
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
注意到查询次数不超过50次。那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以
求得当前查询的值。对于一组数据复杂度约为O(50*n)。
//218ms
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=100000+1000;
int a[maxn];//奇偶排序操作
int q[maxn];//存储操作类型,1是奇偶排序。2是逆置
int c[maxn];//逆置
const int mod=1000000007;
int solve(int cur,int x)//找到在刚開始的位置
{
int ans=x;
for(int i=cur-1;i>=0;i--)
{
if(q[i]==1)
{
ans=a[ans];
}
else
{
ans=c[ans];
}
}
return ans;
}
int main()
{
int t,n,m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
int index=1;
for(int i=1; i<=n; i +=2)
a[index++]=i;
for(int i=2; i<=n; i +=2)
a[index++]=i;
for(int i=1;i<=n;i++)
c[i]=n+1-i;
char s[10];
int p;
int cur=0;
int cou=0;
for(int i=0;i<m;i++)
{
scanf("%s%d",s,&p);
if(s[0]=='O')
{
if(p==3)
cou++;
else
q[cur++]=p;
}
else
{
long long ans=solve(cur,p); for(int i=0;i<cou;i++)
{
ans=ans*ans%mod;
}
printf("%I64d\n",ans);
}
}
}
return 0;
}
hdu 5063 Operation the Sequence(Bestcoder Round #13)的更多相关文章
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
- HDU 5063 Operation the Sequence(暴力 数学)
题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...
- HDU 5063 Operation the Sequence(仔细审题)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...
- HDU 5806 - NanoApe Loves Sequence Ⅱ (BestCoder Round #86)
若 [i, j] 满足, 则 [i, j+1], [i, j+2]...[i,n]均满足 故设当前区间里个数为size, 对于每个 i ,找到刚满足 size == k 的 [i, j], ans + ...
- HDU 5805 - NanoApe Loves Sequence (BestCoder Round #86)
先找相邻差值的最大,第二大,第三大 删去端点会减少一个值, 删去其余点会减少两个值,新增一个值,所以新增和现存的最大的值比较一下取最大即可 #include <iostream> #inc ...
- hdu 5063 Operation the Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5063 思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值. #include ...
- hdu 5640 King's Cake(BestCoder Round #75)
King's Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDOJ 5063 Operation the Sequence
注意到查询次数不超过50次,那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n). Operation the Sequen ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
随机推荐
- [RxJS] Toggle A Stream On And Off With RxJS
This lesson covers how to toggle an observable on and off from another observable by showing how to ...
- vue 使用总结
1.Vuejs组件 vuejs构建组件使用 Vue.component('componentName',{ /*component*/ }): 这里注意一点,组件要先注册再使用,也就是说: Vue.c ...
- 一张图搞懂 Javascript 中的原型链、prototype、__proto__的关系 转载加自己的总结
1. JavaScript内置对象 所谓的内置对象 指的是:JavaScript本身就自己有的对象 可以直接拿来就用.例如Array String 等等.JavaScript一共有12内置对象 ...
- oracle之replace结合substr的使用
select * from( SELECT TMM.ORDER_ID, TMM.IMPORT_ID, TMM.TMALL_ORDER_ID, TMM.MEMBER_NAME, TMM.ALIPAY_U ...
- 九个Console命令,让 JS 调试更简单
一.显示信息的命令 <!DOCTYPE html> <html> <head> <title>常用console命令</title> < ...
- sql server数据库将excel表中的数据导入数据表
一般有两种方法可以实现,一种是直接写sql语句,另外一种是利用sqlserver的管理工具实现.这里介绍的是后面一种方法. 步骤: 一.准备数据 1.将excel表另存为文本格式,注意文本格式需为ta ...
- contenteditable 属性
定义和用法 contenteditable 属性规定是否可编辑元素的内容. 语法 <element contenteditable="value"> 属性值 值 描述 ...
- IE8下载按钮失效
<input id="Button1" class="btn-lg-gary" type="button" onclick=" ...
- SQLServer 2008 R2 发布订阅配置指南
原以为配置SQLServer 2008 R2的发布订阅很简单,实际配置后才发现过程中有问题地方一直都没搞明白,最后经过几天的查找问题和实践,终于搞定了.现将过程记录如下. SQLServer 2008 ...
- C/C++中的空类及抽象类大小
代码: #include <iostream> using namespace std; struct A{ }; struct B{ int i; }; class C:B{ ; }; ...