标签:
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 842 Accepted Submission(s): 288
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <vector> #include <algorithm> using namespace std; typedef long long LL; int main() { int tcase; scanf("%d",&tcase); while(tcase--) { int n,q; scanf("%d%d",&n,&q); char s[5]; int opr; stack<int> stk; stack<int> stk1; int num = 1; while(q--) { scanf("%s%d",s,&opr); if(s[0]==‘O‘) { if(opr==1||opr==2) stk.push(opr); else num++; } else { LL ans; while(!stk.empty()) { int now = stk.top(); stk.pop(); stk1.push(now); if(now==2) opr = n-opr+1; if(now==1) { if(n%2==1) { if(opr<=n/2+1) ///原来是奇数位 { opr = 2*opr - 1; } else { opr = (opr - (n/2+1))*2; } } else { if(opr<=n/2) { opr = 2*opr - 1; } else { opr = 2*(opr - n/2); } } } } while(!stk1.empty()){ stk.push(stk1.top()); stk1.pop(); } ans = opr; for(int i=1; i<num; i++) { ans = ans*ans%1000000007; } printf("%lld\n",ans); } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5656833.html