【瞎搞】 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;
}



posted @ 2014-10-12 19:35  kewowlo  阅读(102)  评论(0编辑  收藏  举报