Codeforces Round #449 (Div. 2)
Codeforces Round #449 (Div. 2)
https://codeforces.com/contest/897
A
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1005 9 #define eps 1e-8 10 #define pi acos(-1.0) 11 #define rep(k,i,j) for(int k=i;k<j;k++) 12 typedef long long ll; 13 typedef pair<int,int> pii; 14 typedef pair<double,double>pdd; 15 typedef pair<int,char> pic; 16 typedef pair<pair<int,string>,pii> ppp; 17 typedef unsigned long long ull; 18 const long long MOD=998244353; 19 const double oula=0.57721566490153286060651209; 20 using namespace std; 21 22 string s; 23 int n,m; 24 25 int main(){ 26 std::ios::sync_with_stdio(false); 27 cin>>n>>m; 28 cin>>s; 29 int l,r; 30 char c1,c2; 31 while(m--){ 32 cin>>l>>r>>c1>>c2; 33 l--,r--; 34 for(int i=l;i<=r;i++){ 35 if(s[i]==c1) 36 s[i]=c2; 37 } 38 } 39 cout<<s<<endl; 40 41 }
B
通过模拟可以发现,回文数11,22,33.....99,1001,1111...它们的前半部分是有规律的,1,2.3....9,10,11....
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 1005 9 #define eps 1e-8 10 #define pi acos(-1.0) 11 #define rep(k,i,j) for(int k=i;k<j;k++) 12 typedef long long ll; 13 typedef pair<int,int> pii; 14 typedef pair<double,double>pdd; 15 typedef pair<int,char> pic; 16 typedef pair<pair<int,string>,pii> ppp; 17 typedef unsigned long long ull; 18 const long long MOD=998244353; 19 const double oula=0.57721566490153286060651209; 20 using namespace std; 21 22 ll a[105]; 23 24 int main(){ 25 std::ios::sync_with_stdio(false); 26 ll n,p; 27 ll ans=0; 28 cin>>n>>p; 29 for(ll i=1;i<=n;i++){ 30 int co=0; 31 ll tmp=i; 32 while(tmp){ 33 a[++co]=tmp%10; 34 tmp/=10; 35 } 36 tmp=i; 37 for(int j=1;j<=co;j++){ 38 tmp=(tmp*10+a[j])%p; 39 } 40 ans=(ans+tmp)%p; 41 } 42 cout<<ans<<endl; 43 }
C
题意:给你第0个字符串和第1个字符串,求第n个字符串中的第k个字符是什么
思路:预处理长度+递归
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 100005 9 #define eps 1e-8 10 #define pi acos(-1.0) 11 #define rep(k,i,j) for(int k=i;k<j;k++) 12 typedef long long ll; 13 typedef pair<int,int> pii; 14 typedef pair<ll,ll>pll; 15 typedef pair<int,char> pic; 16 typedef pair<pair<int,string>,pii> ppp; 17 typedef unsigned long long ull; 18 const long long MOD=998244353; 19 const double oula=0.57721566490153286060651209; 20 using namespace std; 21 22 23 char s0[] = "What are you doing at the end of the world? Are you busy? Will you save us?"; 24 char s1[] = "What are you doing while sending \"\"? Are you busy? Will you send \"\"?"; 25 int a = 75, b = 34, c = 66; 26 long long len[maxn]; 27 28 char solve(int n, long long k) { 29 if (n < 53 && k > len[n]) return '.'; 30 if (!n) return s0[k-1]; 31 if (k <= b) return s1[k-1]; 32 if (k <= b+len[n-1]) return solve(n-1, k-b); 33 if (k <= c+len[n-1]) return s1[k-len[n-1]-1]; 34 if (k >= len[n]-1) return s1[k-len[n]+c+1]; 35 return solve(n-1, k-len[n-1]-c); 36 } 37 38 long long k; 39 int q, n; 40 41 int main(){ 42 std::ios::sync_with_stdio(false); 43 memset(len, 0x3f3f3f3f, sizeof(len)); 44 len[0]=75; 45 for (int i = 1; i < 53; i++) len[i] = 2 * len[i-1] + 68; 46 cin>>q; 47 while(q--){ 48 cin>>n>>k; 49 cout<<solve(n,k); 50 } 51 }
D
交互题
题意: 有n张纸,给你m个不超过c的数,你每次可以把所获得的数写在一张纸上或者替换掉某一张纸上写的数,当纸上都写了数字并且成非降序排列,就结束程序
思路:判断给的数x是否大于c/2,是的话就从大到小遍历数组,否则从小到大遍历数组
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 100005 9 #define eps 1e-8 10 #define pi acos(-1.0) 11 #define rep(k,i,j) for(int k=i;k<j;k++) 12 typedef long long ll; 13 typedef pair<int,int> pii; 14 typedef pair<ll,ll>pll; 15 typedef pair<int,char> pic; 16 typedef pair<pair<int,string>,pii> ppp; 17 typedef unsigned long long ull; 18 const long long MOD=998244353; 19 const double oula=0.57721566490153286060651209; 20 using namespace std; 21 22 int a[1005]; 23 24 int main(){ 25 std::ios::sync_with_stdio(false); 26 int n,m,c; 27 cin>>n>>m>>c; 28 int x; 29 while(m--){ 30 cin>>x; 31 if(x<=(c+1)/2){ 32 for(int i=1;i<=n;i++){ 33 if(a[i]>x||!a[i]){ 34 a[i]=x; 35 cout<<i<<endl; 36 break; 37 } 38 } 39 } 40 else{ 41 for(int i=n;i;i--){ 42 if(a[i]<x||!a[i]){ 43 a[i]=x; 44 cout<<i<<endl; 45 break; 46 } 47 } 48 } 49 } 50 }
E
题意:给定长度为n的序列,有4种操作:
1.[l,r]都加x
2.[l,r]都赋值为x
3.求第k大的数
4.求[l,r]的数的x次方模y的和
数据随机
思路:因为数据随机,所以直接上ODT
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define IT set<node>::iterator 6 #define sqr(x) ((x)*(x)) 7 #define pb push_back 8 #define eb emplace_back 9 #define maxn 100005 10 #define eps 1e-8 11 #define pi acos(-1.0) 12 #define rep(k,i,j) for(int k=i;k<j;k++) 13 typedef long long ll; 14 typedef pair<int,int> pii; 15 typedef pair<ll,ll>pll; 16 typedef pair<ll,int> pli; 17 typedef pair<pair<int,string>,pii> ppp; 18 typedef unsigned long long ull; 19 const long long MOD=1e9+7; 20 const double oula=0.57721566490153286060651209; 21 using namespace std; 22 23 struct node{ 24 int l,r; 25 mutable ll val; 26 node(int L,int R=-1,ll V=0):l(L),r(R),val(V){} 27 bool operator<(const node& t)const { 28 return l<t.l; 29 } 30 }; 31 set<node>se; 32 33 ll ksm(ll a,ll b,ll mod){ 34 ll ans=1; 35 a%=mod; 36 while(b){ 37 if(b&1){ 38 ans=(ans*a)%mod; 39 } 40 b>>=1; 41 a=(a*a)%mod; 42 } 43 return ans; 44 } 45 46 IT split(int pos){ 47 IT it=se.lower_bound(node(pos)); 48 if(it!=se.end()&&it->l==pos) return it; 49 it--; 50 int L=it->l,R=it->r; 51 ll V=it->val; 52 se.erase(it); 53 se.insert(node(L,pos-1,V)); 54 return se.insert(node(pos,R,V)).first; 55 } 56 57 void assign(int l,int r,ll v){ 58 IT itr=split(r+1),itl=split(l); 59 se.erase(itl,itr);///左闭右开 60 se.insert(node(l,r,v)); 61 } 62 63 void add(int l,int r,ll v){ 64 IT itr=split(r+1); 65 for(IT itl=split(l);itl!=itr;itl++){ 66 itl->val+=v; 67 } 68 } 69 70 ll Rank(int l,int r,int v){ 71 IT itr=split(r+1); 72 vector<pli>tmp; 73 for(IT itl=split(l);itl!=itr;itl++){ 74 tmp.pb({itl->val,itl->r-itl->l+1}); 75 } 76 sort(tmp.begin(),tmp.end()); 77 for(int i=0;i<tmp.size();i++){ 78 v-=tmp[i].second; 79 if(v<=0){ 80 return tmp[i].first; 81 } 82 } 83 } 84 85 ll query(int l,int r,ll x,ll y){ 86 IT itr=split(r+1); 87 ll ans=0; 88 for(IT itl=split(l);itl!=itr;itl++){ 89 ans=(ans+((ksm(itl->val,x,y)*(itl->r-itl->l+1))%y))%y; 90 } 91 return ans; 92 } 93 94 ll n,m,seed,vmax; 95 96 ll rnd(){ 97 ll ans=seed; 98 seed=(seed*7+13)%MOD; 99 return ans; 100 } 101 102 103 int main(){ 104 std::ios::sync_with_stdio(false); 105 106 cin>>n>>m>>seed>>vmax; 107 ll x,y; 108 for(int i=1;i<=n;i++){ 109 x=(rnd()%vmax)+1; 110 se.insert(node(i,i,x)); 111 } 112 int opt,L,R; 113 for(int i=1;i<=m;i++){ 114 opt=(rnd()%4)+1; 115 L=(rnd()%n)+1; 116 R=(rnd()%n)+1; 117 if(L>R) swap(L,R); 118 if(opt==3){ 119 x=(rnd()%(R-L+1))+1; 120 } 121 else{ 122 x=(rnd()%vmax)+1; 123 } 124 if(opt==4){ 125 y=(rnd()%vmax)+1; 126 } 127 if(opt==1){ 128 add(L,R,x); 129 } 130 else if(opt==2){ 131 assign(L,R,x); 132 } 133 else if(opt==3){ 134 cout<<Rank(L,R,x)<<endl; 135 } 136 else{ 137 cout<<query(L,R,x,y)<<endl; 138 } 139 } 140 }
posted on 2019-03-23 16:05 Fighting_sh 阅读(169) 评论(0) 编辑 收藏 举报