Codeforces Round #449 (Div. 2)
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.
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 string s after performing m operations described above.
3 1
ioi
1 1 i n
noi
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
gaaak
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.
A手速过题,从l到r的是什么进行替换,但是这个题数据量要很多的时候怎么办呢,区间更新?
#include<bits/stdc++.h> using namespace std; int main() { int n,m; cin>>n>>m; string s; cin>>s; int l,r; char c1,c2; while(m--) { cin>>l>>r>>c1>>c2; for(int i=l-1;i<r;i++) if(s[i]==c1) s[i]=c2; } cout<<s; return 0; }
#include<stdio.h> typedef long long ll; ll la(int x) { ll t=x,b=0; while(x) { t*=10; b=b*10+x%10; x=x/10; } return t+b; } int main() { int k,p; scanf("%d%d",&k,&p); ll ans=0; while(k--) ans=(ans+la(k+1))%p; printf("%lld",ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[100005]; string s1="What are you doing at the end of the world? Are you busy? Will you save us?"; string s21="What are you doing while sending \"",s22 = "\"? Are you busy? Will you send \"",s23 = "\"?"; char la(int x, ll n) { if(n>a[x])return '.'; if(!x)return s1[n - 1]; if(n<=s21.size())return s21[n-1]; n-=s21.size(); if(n<=a[x-1])return la(x-1,n); n-=a[x-1]; if(n<=s22.size())return s22[n-1]; n-=s22.size(); if(n<=a[x-1])return la(x-1,n); n-=a[x-1]; return s23[n-1]; } int main() { a[0]=s1.size(); for (int i=1; i<=100000; i++) { a[i]=2ll*a[i-1]+s21.size()+s22.size()+s23.size(); if(a[i]>2e18)a[i]=2e18; } int q; cin>>q; while (q--) { ll n,l; cin>>n>>l; cout<<la(n,l); } return 0; }
本文来自博客园,作者:暴力都不会的蒟蒻,转载请注明原文链接:https://www.cnblogs.com/BobHuang/p/7989546.html