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);
                            else
                                pos = (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;
            }
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值