标签:des style http color io os ar for strong
1 3 5 O 1 O 2 Q 1 O 3 Q 1
2 4
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
typedef __int64 ll;
//typedef long long ll;
using namespace std;
const int maxn = 100005;
const int mod = 1000000007;
int n, m;
int O[maxn];
ll num[maxn];
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
char str[10];
int op, cnt = 0;
int sum = 0;
for (int i = 0; i < m; i++) {
scanf("%s%d", str, &op);
if (str[0] == 'O') {
if (op == 3)
sum++;
else O[cnt++] = op;
}
else {
for (int j = cnt-1; j >= 0; j--) {
int cur = O[j];
if (cur == 1) {
if (n & 1) {
if (op <= n/2 + 1)
op = op * 2 - 1;
else op = (op - n / 2 - 1) * 2;
}
else {
if (op <= n / 2)
op = op * 2 - 1;
else op = (op - n / 2) * 2;
}
}
else if (cur == 2)
op = n - op + 1;
}
ll ans = op;
for (int i = 0; i < sum; i++)
ans = ans * ans % mod;
printf("%I64d\n", ans);
}
}
}
return 0;
}HDU - 5036 Operation the Sequence
标签:des style http color io os ar for strong
原文地址:http://blog.csdn.net/u011345136/article/details/40023015