【瞎搞】 HDU 5063 Operation the Sequence

询问操作至多有50个

遇到询问再回去找到原来位置的值

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <time.h>;
#define cler(arr, val)    memset(arr, val, sizeof(arr))
#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define IN   freopen ("in.txt" , "r" , stdin);
#define OUT  freopen ("out.txt" , "w" , stdout);
typedef long long  LL;
const int MAXN = 100000+5;
const int MAXM = 100000;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
char s[MAXN][3];
LL d[MAXN];
int t,n,m;
void solve(int x,int k)
{
    int aa=0;
    int h=(n+1)/2;
    for(int i=k-1; i>=0; i--)
    {
        if(s[i][0]!='Q')
        {
            if(d[i]==1)
            {
                if(x<=h)
                    x=2*x-1;
                else x=2*(x-h);
            }
            else if(d[i]==2)
                x=n-x+1;
            else aa++;
        }
    }
    LL ans=(LL)x;
    for(int i=0;i<aa;i++)
        ans=ans*ans%mod;
    printf("%I64d\n",ans);
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif

    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        for(int i=0; i<m; i++)
        {
            scanf("%s%d",s[i],&d[i]);
            if(s[i][0]=='Q')
                solve(d[i],i);
        }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值