Codeforces Round #449 (Div. 2)(ABC)

A. Scarborough Fair
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Are you going to Scarborough Fair?

Parsley, sage, rosemary and thyme.

Remember me to one who lives there.

He once was the true love of mine.

Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.

Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.

Although the girl wants to help, Willem insists on doing it by himself.

Grick gave Willem a string of length n.

Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.

Grick wants to know the final string after all the m operations.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100).

The second line contains a string s of length n, consisting of lowercase English letters.

Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.

Output

Output string s after performing m operations described above.

Examples
Input
3 1
ioi
1 1 i n
Output
noi
Input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
Output
gaaak
Note

For the second example:

After the first operation, the string is wxxak.

After the second operation, the string is waaak.

After the third operation, the string is gaaak.

 

题意就是给你一个字符串,

区间更新代替。

数据不大,可以直接暴力。

 1 #include <iostream>
 2 #include <cstring>
 3 
 4 using namespace std;
 5 int n,m;
 6 string s;
 7 int main(){
 8     cin>>n>>m>>s;
 9     int left,right,c1,c2;
10     while(m--){
11         char c1,c2;
12         cin>>left>>right>>c1>>c2;
13         for(int i=left-1;i<=right-1;i++)
14             if(s[i]==c1)
15                 s[i]=c2;
16     }
17     cout<<s<<endl;
18     return 0;
19 }

 

B. Chtholly's request
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
— Thanks a lot for today.

— I experienced so many great things.

— You gave me memories like dreams... But I have to leave now...

— One last request, can you...

— Help me solve a Codeforces problem?

— ......

— What?

Chtholly has been thinking about a problem for days:

If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.

Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.

Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!

Input

The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

Output

Output single integer — answer to the problem.

Examples
Input
2 100
Output
33
Input
5 30
Output
15
Note

In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.

In the second example, .

关键在于找到累加的数,我自己是用字符串翻转然后转化成数来解决的。

比如:

1  11   5  55  9  99

2  22   6  66  10  1001

3  33   7  77  11  1111

4  44   8  88  12  1221 .......

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <cmath>
 6 #define ll long long int
 7 using namespace std;
 8 ll n,m;
 9 string ting(ll x){
10     string s;
11     while(x){
12         char c=x%10+'0';
13         x/=10;
14         s+=c;
15     }
16     return s;
17 }
18 ll init(string s){
19     ll x=0;
20     for(int i=0;i<s.length();i++){
21         x=x*10+(s[i]-'0');
22     }
23     return x;
24 }
25 ll Pow(ll x){
26     ll an=1;
27     while(x--){
28         an=(an*10);
29     }
30     return an;
31 }
32 int main(){
33     std::ios::sync_with_stdio(false);
34     cin>>n>>m;
35     ll sum=0;
36     for(int i=1;i<=n;i++){
37         ll x=i;
38         string s=ting(x);
39         ll slen=s.length();
40         ll an=Pow(slen);
41         ll bn=(init(s));
42         sum+=(i*an+bn)%m;
43     }
44      cout<<sum%m<<endl;
45     return 0;
46 }

 

C. 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?

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
Note

For the first two examples, refer to f0 and f1 given in the legend.

比赛的时候没做出来,这题就是递归,但是跟以前的递归又不一样,

一开始找的时候,我在准备打表,结果吓死人,10^5根本打不出来。

才发现原来到了53就超了10^18.

千万注意不要暴力,会wa的很惨的,还有一个就是注意当x超过了53的时候,在第三个if的判断,

我在哪里哇了两次。(哭死)

 1 #include <bits/stdc++.h>
 2 #define ll long long int
 3 #define maxx 1e18
 4 using namespace std;
 5 ll k[101000];
 6 int cnt;
 7 string s1=" What are you doing at the end of the world? Are you busy? Will you save us?";
 8 string s2=" What are you doing while sending ""? Are you busy? Will you send ""?";
 9 
10 char gg(ll x,ll y){
11     if (x==0)
12         return s1[y];
13     if (y<=34)
14         return s2[y];
15     if (y<=34+k[x-1]||x>cnt)
16         return gg(x-1,y-34);
17     if (y<=34+k[x-1]+32)
18         return s2[y-k[x-1]];
19     if (y<=34+2*k[x-1]+32)
20         return gg(x-1,y-34-k[x-1]-32);
21     return s2[y-k[x-1]-k[x-1]];
22 }
23 
24 int main(){
25     std::ios::sync_with_stdio(false);
26     cin.tie(0);cout.tie(0);
27     k[0]=75;
28     int i;
29     for(i=1;i<100;i++){
30         k[i]=k[i-1]*2+68;
31         if(k[i]>maxx)
32             break;
33     }
34     cnt=i;
35     ll n,m,p;
36     cin>>n;
37     while(n--){
38         cin>>m>>p;
39         if(p>k[m]&&m<=cnt){
40             cout<<".";
41         }else{
42             cout<<gg(m,p);
43         }
44     }
45     cout<<endl;
46     return 0;
47 }

 

原文地址:https://www.cnblogs.com/zllwxm123/p/8001025.html