题目链接:hdu 5063 Operation the Sequence
题目大意:4种操作,见题目。
解题思路:因为询问只有50次,所以每次碰到询问的时候,就去模拟一下,查哪个位置,就倒着推回去。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int maxn = 1e5+5;
int N, M, T, P[maxn];
int pow_mod(ll x, int n) {
ll ret = 1;
while (n) {
if (n&1)
ret = ret * x % mod;
x = x * x % mod;
n >>= 1;
}
return ret;
}
int query(int n, int pos) {
int c = 1;
for (int i = n - 1; i; i--) {
if (P[i] == 1) {
if (pos <= T)
pos = pos * 2 - 1;
else
pos = (pos - T) * 2;
} else if (P[i] == 2)
pos = N - pos + 1;
else if (P[i] == 3)
c = (c + c) % (mod - 1);
}
return pow_mod(pos, c);
}
int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
int x;
char op[5];
memset(P, 0, sizeof(P));
scanf("%d%d", &N, &M);
T = (N + 1) / 2;
for (int i = 1; i <= M; i++) {
scanf("%s%d", op, &x);
if (op[0] == 'Q')
printf("%d\n", query(i, x));
else
P[i] = x;
}
}
return 0;
}
分享到:
相关推荐
HDU-1711 Number Sequence(KMP算法)For each test case, you should output one line wh
【hdu5306】Gorgeous Sequence 线段树区间最值操作-附件资源
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
杭电ACMhdu1163
HDU1059的代码
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
n)⊕n, where ``⊕’’ denotes the bitwise XOR operation. Please write a program to find the smallest positive integer n that (f(n,m)?n)⊕n=k, or determine it is impossible. Input The first line of ...
hdu2101AC代码
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
next[i]的含义是在str[i]之前的字符串str[0...i]中,必须以str[i-1]结尾的后缀子串(不能包含str[0])与必须以str[0]开头的前
搜索 dfs 解题代码 hdu1241
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
ACM HDU题目分类,我自己总结的大概只有十来个吧
hdu 1166线段树代码
HDU最全ac代码
自己做的HDU ACM已经AC的题目