站外题,代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fst ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fir first
#define sec second
const int N=1e6+5;
const int INF=0x3f3f3f3f3f3f3f3f;
int ans=0;
void in(int a[],int n){
while(n--){
cin >> *a;
a++;
}
}
int n,m,t;
string a,b;
int fp(int x,int y){
if(y==0)return 1;
if(y==1)return x;
if(x>1e15)return INF;
int res=fp(x,y/2);
if(res>1e8)return INF;
if(y&1){
int res2=res*res;
if(res2>(1e15+x-1)/x)return INF;
res2*=x;
if(res2>1e15)return INF;
return res2;
}else{
int res2=res*res;
if(res2>1e15)return INF;
return res2;
}
}
signed main(){
// freopen("string.in","r",stdin);
// freopen("string.out","w",stdout);
cin >> n >> m >> t;
cin >> a >> b;
while(t--){
int x;
cin >> x;
int res=935;
bool ab=0;
int num=x;
for(;res;res--){
int pla=fp(2,res);
if(pla==INF || (pla/2*n+pla/2*m)/2>=num){
//do nothing
}else{
ab^=1;
num-=(pla/2*n+pla/2*m)/2;
}
}
if(ab==1){
cout << b[num-1];
}else{
cout << a[num-1];
}
cout << endl;
}
return 0;
}