hdu 5063 Operation the Sequence
2015-02-07 16:00
549 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5063
思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值。
View Code
思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值。
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define ll long long using namespace std; const int mod=1000000007; int n,m; char str[1000]; int a[100010]; ll pow_mod(ll a,ll p,ll n) { if(p==0) return 1; ll ans=pow_mod(a,p/2,n); ans=ans*ans%n; if(p%2==1) ans=ans*a%n; return ans; } int main() { int t; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); getchar(); char op; int cnt=0; int pos=0; int mid=(n+1)/2; int x; for(int i=1; i<=m; i++) { scanf("%c",&op); if(op=='O') { scanf("%d",&x); a[i]=x; } else if(op=='Q') { scanf("%d",&x); pos=x; int c=1; for(int j=i-1; j>=1; j--) { if(a[j]==1) { if(pos<=mid) pos=pos*2-1; else pos=(pos-mid)*2; } else if(a[j]==2) { pos=n-pos+1; } else if(a[j]==3) { c=(c+c)%(mod-1); } } printf("%d\n",pow_mod(pos,c,mod)); } getchar(); } } return 0; }
View Code
相关文章推荐
- 【瞎搞】 HDU 5063 Operation the Sequence
- hdu 5063 Operation the Sequence(思路)
- Operation the Sequence(HDU 5063)
- HDU 5063 Operation the Sequence(暴力)
- hdu 5063——Operation the Sequence
- hdu 5063 Operation the Sequence (数学公式逆推)
- 【瞎搞】 HDU 5063 Operation the Sequence
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
- hdu 5063 Operation the Sequence
- HDU 5063 Operation the Sequence(暴力)
- Hdu 5063 Operation the Sequence
- 【CUGBACM15级BC第13场 B】hdu 5063 Operation the Sequence
- hdu 5063 Operation the Sequence(模拟)
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
- Hdu 5063 Operation the Sequence
- HDU 5063 Operation the Sequence(暴力 数学)
- HDU 5063 Operation the Sequence
- HDU 5063 - Operation the Sequence (置换)
- HDU 5063 Operation the Sequence(暴力)
- HDU - 5036 Operation the Sequence