【HDOJ】5063 Operation the Sequence

时间:2022-09-15 01:42:44
 #include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 100005
#define MOD 1000000007
int que[MAXN], front = , rear = ;
int n; void query(int index) {
int r = rear;
int square = ;
int half = (n+)>>; while (r-- > front) {
if (que[r] == ) {
++square;
} else if (que[r] == ) {
index = n+-index;
} else {
if (index > half) {
index = (index - half)*;
} else {
index = *index - ;
}
}
}
__int64 ret = index%MOD;
for (int i=; i<square; ++i) {
ret = ret*ret%MOD;
}
printf("%I64d\n", ret);
} int main() {
int t, m;
int x;
char cmd[]; scanf("%d", &t);
while (t--) {
rear = ;
scanf("%d%d", &n, &m);
while (m--) {
scanf("%s %d", cmd, &x);
if (cmd[] == 'Q') {
query(x);
} else {
que[rear++] = x;
}
}
}
return ;
}