Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 842 Accepted Submission(s): 288
Type1: O 1 call fun1();
Type2: O 2 call fun2();
Type3: O 3 call fun3();
Type4: Q i query current value of a[i], this operator will have at most 50.
Global Variables: a[1…n],b[1…n];
fun1() {
index=1;
for(i=1; i<=n; i +=2)
b[index++]=a[i];
for(i=2; i<=n; i +=2)
b[index++]=a[i];
for(i=1; i<=n; ++i)
a[i]=b[i];
}
fun2() {
L = 1;R = n;
while(L<R) {
Swap(a[L], a[R]);
++L;--R;
}
}
fun3() {
for(i=1; i<=n; ++i)
a[i]=a[i]*a[i];
}
The first line of each test case contains two integer n(0<n≤100000), m(0<m≤100000).
Then m lines follow, each line represent an operator above.
#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; }