0
点赞
收藏
分享

微信扫一扫

【BestCoder】 HDOJ Operation the Sequence


简单模拟。。。。


#include <iostream>
#include <queue> 
#include <stack> 
#include <map> 
#include <set> 
#include <bitset> 
#include <cstdio> 
#include <algorithm> 
#include <cstring> 
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 200000
#define maxm 300006
#define eps 1e-10
#define mod 1000000007
#define INF 1e9
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid 
#define rson o<<1 | 1, mid+1, R 
typedef long long LL;
typedef unsigned long long ULL;
//typedef int LL;
using namespace std;

struct node
{
    int k, x;
}p[maxn];
int q[maxn];
int n, m, cnt;
char ss[10];

void read(void)
{
    cnt = 0;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; i++) {
        scanf("%s", ss);
        if(ss[0] == 'O') p[i].k = 1;
        else p[i].k = 2;
        scanf("%d", &p[i].x);
        if(ss[0] == 'Q') q[cnt++] = i;
    }
}

int fun1(int now)
{
    int t = (n+1) / 2;
    if(now > t) return (now - t) * 2;
    else return now * 2 - 1;
}

int fun2(int x)
{
    return n - x + 1;
}

LL powmod(int now, int tt)
{
    LL a = now, b = tt, res = 1;
    while(b) {
        if(b % 2) res = (res * a) % mod;
        a = (a * a) % mod;
        b /= 2;
    }
    return res;
}
void work(void)
{
    for(int i = 0; i < cnt; i++) {
        int t = q[i], tt = 0, now = p[q[i]].x;
        for(int j = t-1; j >= 1; j--) {
            if(p[j].k == 2) continue;
            if(p[j].x == 3) tt++;
            //printf("init = %d o = %d\n", now, p[j].x);
            if(p[j].x == 1) now = fun1(now);
            if(p[j].x == 2) now = fun2(now);
            //printf("now = %d\n", now);
        }
        LL ans = now;
        for(int i = 1; i <= tt; i++) ans = (ans * ans) % mod;
        //LL ans = powmod(now, tt);
        printf("%I64d\n", ans);
    }
}

int main(void)
{
    int _;
    while(scanf("%d", &_)!=EOF) {
        while(_--) {
            read();
            work();
        }
    }
    return 0;
}




举报

相关推荐

0 条评论