欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

hdu-5063 Operation the Sequence

发布时间:2025/3/16 编程问答 38 豆豆
生活随笔 收集整理的这篇文章主要介绍了 hdu-5063 Operation the Sequence 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

题意:给你三种操作,然后询问当前第i个数的值

1、先奇后偶

2、对称交换

3、对每个数平方

题解:可以对询问的第i个位置逆推,求平方即可;

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef __int64 LL; const LL MOD = 1000000007; char a[100005][1]; int b[100005]; LL Pow(LL A,LL B){LL res = 1;while(B){if(B&1) res = res * A % MOD;A = A * A % MOD ;B /= 2;}return res; } int main(){int t,n,m;cin >> t;while(t--){cin >> n >> m;int x = (n+1)/2;for(int i = 1;i <= m;i++){scanf("%s %d",a[i],&b[i]);if(a[i][0] == 'Q'){LL p = 1;int pos = b[i];for(int j = i-1;j >= 1;j--){if(a[j][0] == 'O'){if(b[j] == 1){ // cout << " wqew " << endl;if(pos <= x)pos = pos + (pos - 1);elsepos = (pos - x) * 2;}else if(b[j] == 2){ // cout << " wqew " << endl;if(n%2){pos = 2 * x - pos;}else{pos = 2 * x - pos + 1;}}else{p = p * 2 % (MOD - 1);}}} // cout << pos << "====" << p << endl;LL x = pos;x = Pow(x,p);cout << x << endl;}}} }

总结

以上是生活随笔为你收集整理的hdu-5063 Operation the Sequence的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。