【Codeforces Round #449 (Div. 2)】

A. Scarborough Fair

  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 ≤ nc1, 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

题解:

  模拟。

 1 #include<iostream>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<cstdio>
 5 long long n,m,l,r;
 6 char s[1005],c1,c2;
 7 using namespace std;
 8 long long main(){
 9     scanf("%d%d\n",&n,&m);
10     scanf("%s\n",s+1);
11     for(long long i=1;i<=m;i++){
12         cin>>l>>r>>c1>>c2;
13         for(long long j=l;j<=r;j++){
14             if(s[j]==c1)
15                 s[j]=c2;
16         }
17     }
18     for(long long i=1;i<=n;i++){
19         printf("%c",s[i]);
20     }
21     return 0;
22 }

 

 

B. Chtholly's request

— 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

题解:

  可以发现第124个数为124421。规律就是这样。

  预处理下10^n,然后枚举构造出第k个数,加入答案即可。

 1 #include<iostream>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<cstdio>
 5 using namespace std;
 6 long long ans,n,p;
 7 long long t[100005],s[100005];
 8 int main(){
 9     t[0]=1;
10     scanf("%lld%lld",&n,&p);
11     for(long long i=1;i<=10;i++)
12         t[i]=t[i-1]*10;
13     for(long long i=1;i<=n;i++){
14         long long m=i;s[0]=0;
15         while(m){
16             s[++s[0]]=m%10;
17             m/=10;
18         }
19         ans+=i*t[s[0]]%p;
20         ans%=p;
21         for(long long j=1;j<=s[0];j++)
22             ans=(ans+s[j]*t[s[0]-j]%p)%p;
23     }
24     printf("%lld",ans);
25 }

 

posted @ 2017-12-03 00:20  LittleOrange  阅读(264)  评论(0编辑  收藏  举报