CodeForces - 896A Nephren gives a riddle

时间:2022-09-13 04:28:39
A. Nephren gives a riddle
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

What are you doing at the end of the world? Are you busy? Will you save us?

CodeForces - 896A Nephren gives a riddle

Nephren is playing a game with little leprechauns.

She gives them an infinite array of strings, f0... ∞.

f0 is "What are you doing at the end of the world? Are you busy? Will you save us?".

She wants to let more people know about it, so she defines fi =  "What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?" for all i ≥ 1.

For example, f1 is

"What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.

It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.

Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output '.' (without quotes).

Can you answer her queries?

Input

The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions.

Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).

Output

One line containing q characters. The i-th character in it should be the answer for the i-th query.

Examples
input
3
1 1
1 2
1 111111111111
output
Wh.
input
5
0 69
1 194
1 139
0 47
1 66
output
abdef
input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
output
Areyoubusy     

题目链接

分析 
fi由5部分拼接而成,预处理长度,因为限制了k的范围,所以只用处理到长度1e18就好。然后根据n和k递归查找所在位子的具体字符。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn = 1e5+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
char f0[]={"What are you doing at the end of the world? Are you busy? Will you save us?"};
char t[] ={"What are you doing while sending \"\"? Are you busy? Will you send \"\"?"};
char t1[]={"What are you doing while sending \""};
char t2[]={"\"? Are you busy? Will you send \""};
char t3[]={"\"?"};
LL len[];
int l1,l2,l3,tot;
void init(){
l1=strlen(t1),l2=strlen(t2),l3=strlen(t3);
len[]=strlen(f0); int i;
for(i=;i<maxn;i++){
len[i]=+*len[i-];
if(len[i]>=1e18) break;
}
tot=i;
}
char dfs(int n,LL k){
if(n<=tot&&k>len[n]) return '.';
else{
if(n==) return f0[k-];
else{
if(k<=l1) return t1[k-];
if(n>tot || k<=l1+len[n-]) return dfs(n-,k-l1);
if(k<=l1+len[n-]+l2) return t2[k--(l1+len[n-])];
if(k<=l1+len[n-]*+l2) return dfs(n-,k-(l1+len[n-]+l2));
return t3[k--(l1+len[n-]*+l2)];
}
}
}
int main(){
// freopen("in.txt","r",stdin);
init();
int n,q;
LL k;
cin>>q;
while(q--){
cin>>n>>k;
cout<<dfs(n,k);
} return ;
}