A
int main()
{
int n, m;
char s[102];
while(scanf("%d%d%s", &n, &m, s) != EOF) {
while(m--) {
int l, r;
char c1, c2;
scanf("%d%d %c %c", &l, &r, &c1, &c2);
for(int i = l; i <= r; ++i) {
if(s[i - 1] == c1) {
s[i - 1] = c2;
}
}
}
puts(s);
}
return 0;
}
B
#include<stdio.h>
const int MAXN = (int)1e5 + 5;
int k, p, cnt, t;
typedef long long ll;
int mod_pow(int a, int n) {
int res = 1;
while(n) {
if(n&1) res = 1LL * res * a % p;
a = 1LL * a * a % p;
n >>= 1;
}
return res;
}
int f(int j, int i) {
return 1LL * mod_pow(10, i) * j % p;
}
int dfs(int i, int sum, bool fg) {
if(cnt == k) return 0;
if(i == t / 2) {
++cnt;
return sum;
}
int res = 0;
if(fg) res = dfs(i - 1, sum, true);
for(int j = 1; j <= 9; ++j) {
res += dfs(i - 1, ((sum + f(j, i - 1))%p + f(j, t - i)) % p, true);
res %= p;
}
return res;
}
int work() {
int res = 0;
cnt = 0;
for(int i = 2; cnt <= k; i += 2) {
res += dfs(t = i, 0, false);
res %= p;
if(cnt == k) break;
}
return res;
}
int main()
{
while(scanf("%d%d", &k, &p) != EOF) {
int ans = work();
printf("%d\n", ans);
}
return 0;
}
C
#include<stdio.h>
#include<string.h>
typedef long long ll;
const char s0[] = "What are you doing at the end of the world? Are you busy? Will you save us?";
const char s1[] = "What are you doing while sending \"";
const char s2[] = "\"? Are you busy? Will you send \"";
const char s3[] = "\"?";
int l1, l2, l3, len, l0;
void init() {
l0 = strlen(s0);
l1 = strlen(s1);
l2 = strlen(s2);
l3 = strlen(s3);
len = l1 + l2 + l3;
}
ll a(int k) {
if(k >= 55) return 5152117973711847356;
return (1LL<<k) * (len + l0) - len;
}
ll f(int i, int k) {
switch(i) {
case 0: return 0;
case 1: return l1;
case 2: return f(i - 1, k) + a(k - 1);
case 3: return f(i - 1, k) + l2;
case 4: return f(i - 1, k) + a(k - 1);
case 5: return f(i - 1, k) + l3;
}
}
char slove(int n, ll k) {
if(n == 0 && k <= l0) return s0[k - 1];
if(n == 0 && k > l0) return '.';
if(k <= f(1, n)) return s1[k - 1];
if(k <= f(2, n)) return slove(n - 1, k - f(1, n));
if(k <= f(3, n)) return s2[k - f(2, n) - 1];
if(k <= f(4, n)) return slove(n - 1, k - f(3, n));
if(k <= f(5, n)) return s3[k - f(4, n) - 1];
return '.';
}
int main()
{
init();
int T;
while(scanf("%d", &T) != EOF) {
while(T--) {
int n;
ll k;
scanf("%d%lld", &n, &k);
printf("%c", slove(n, k));
}
}
return 0;
}