Codeforces Round #449 (Div. 2)
https://codeforces.com/contest/897
A
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double>pdd;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; string s;
int n,m; int main(){
std::ios::sync_with_stdio(false);
cin>>n>>m;
cin>>s;
int l,r;
char c1,c2;
while(m--){
cin>>l>>r>>c1>>c2;
l--,r--;
for(int i=l;i<=r;i++){
if(s[i]==c1)
s[i]=c2;
}
}
cout<<s<<endl; }
B
通过模拟可以发现,回文数11,22,33.....99,1001,1111...它们的前半部分是有规律的,1,2.3....9,10,11....
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double>pdd;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; ll a[]; int main(){
std::ios::sync_with_stdio(false);
ll n,p;
ll ans=;
cin>>n>>p;
for(ll i=;i<=n;i++){
int co=;
ll tmp=i;
while(tmp){
a[++co]=tmp%;
tmp/=;
}
tmp=i;
for(int j=;j<=co;j++){
tmp=(tmp*+a[j])%p;
}
ans=(ans+tmp)%p;
}
cout<<ans<<endl;
}
C
题意:给你第0个字符串和第1个字符串,求第n个字符串中的第k个字符是什么
思路:预处理长度+递归
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; char s0[] = "What are you doing at the end of the world? Are you busy? Will you save us?";
char s1[] = "What are you doing while sending \"\"? Are you busy? Will you send \"\"?";
int a = , b = , c = ;
long long len[maxn]; char solve(int n, long long k) {
if (n < && k > len[n]) return '.';
if (!n) return s0[k-];
if (k <= b) return s1[k-];
if (k <= b+len[n-]) return solve(n-, k-b);
if (k <= c+len[n-]) return s1[k-len[n-]-];
if (k >= len[n]-) return s1[k-len[n]+c+];
return solve(n-, k-len[n-]-c);
} long long k;
int q, n; int main(){
std::ios::sync_with_stdio(false);
memset(len, 0x3f3f3f3f, sizeof(len));
len[]=;
for (int i = ; i < ; i++) len[i] = * len[i-] + ;
cin>>q;
while(q--){
cin>>n>>k;
cout<<solve(n,k);
}
}
D
交互题
题意: 有n张纸,给你m个不超过c的数,你每次可以把所获得的数写在一张纸上或者替换掉某一张纸上写的数,当纸上都写了数字并且成非降序排列,就结束程序
思路:判断给的数x是否大于c/2,是的话就从大到小遍历数组,否则从小到大遍历数组
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=;
const double oula=0.57721566490153286060651209;
using namespace std; int a[]; int main(){
std::ios::sync_with_stdio(false);
int n,m,c;
cin>>n>>m>>c;
int x;
while(m--){
cin>>x;
if(x<=(c+)/){
for(int i=;i<=n;i++){
if(a[i]>x||!a[i]){
a[i]=x;
cout<<i<<endl;
break;
}
}
}
else{
for(int i=n;i;i--){
if(a[i]<x||!a[i]){
a[i]=x;
cout<<i<<endl;
break;
}
}
}
}
}
E
题意:给定长度为n的序列,有4种操作:
1.[l,r]都加x
2.[l,r]都赋值为x
3.求第k大的数
4.求[l,r]的数的x次方模y的和
数据随机
思路:因为数据随机,所以直接上ODT
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define IT set<node>::iterator
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int> pli;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
const double oula=0.57721566490153286060651209;
using namespace std; struct node{
int l,r;
mutable ll val;
node(int L,int R=-,ll V=):l(L),r(R),val(V){}
bool operator<(const node& t)const {
return l<t.l;
}
};
set<node>se; ll ksm(ll a,ll b,ll mod){
ll ans=;
a%=mod;
while(b){
if(b&){
ans=(ans*a)%mod;
}
b>>=;
a=(a*a)%mod;
}
return ans;
} IT split(int pos){
IT it=se.lower_bound(node(pos));
if(it!=se.end()&&it->l==pos) return it;
it--;
int L=it->l,R=it->r;
ll V=it->val;
se.erase(it);
se.insert(node(L,pos-,V));
return se.insert(node(pos,R,V)).first;
} void assign(int l,int r,ll v){
IT itr=split(r+),itl=split(l);
se.erase(itl,itr);///左闭右开
se.insert(node(l,r,v));
} void add(int l,int r,ll v){
IT itr=split(r+);
for(IT itl=split(l);itl!=itr;itl++){
itl->val+=v;
}
} ll Rank(int l,int r,int v){
IT itr=split(r+);
vector<pli>tmp;
for(IT itl=split(l);itl!=itr;itl++){
tmp.pb({itl->val,itl->r-itl->l+});
}
sort(tmp.begin(),tmp.end());
for(int i=;i<tmp.size();i++){
v-=tmp[i].second;
if(v<=){
return tmp[i].first;
}
}
} ll query(int l,int r,ll x,ll y){
IT itr=split(r+);
ll ans=;
for(IT itl=split(l);itl!=itr;itl++){
ans=(ans+((ksm(itl->val,x,y)*(itl->r-itl->l+))%y))%y;
}
return ans;
} ll n,m,seed,vmax; ll rnd(){
ll ans=seed;
seed=(seed*+)%MOD;
return ans;
} int main(){
std::ios::sync_with_stdio(false); cin>>n>>m>>seed>>vmax;
ll x,y;
for(int i=;i<=n;i++){
x=(rnd()%vmax)+;
se.insert(node(i,i,x));
}
int opt,L,R;
for(int i=;i<=m;i++){
opt=(rnd()%)+;
L=(rnd()%n)+;
R=(rnd()%n)+;
if(L>R) swap(L,R);
if(opt==){
x=(rnd()%(R-L+))+;
}
else{
x=(rnd()%vmax)+;
}
if(opt==){
y=(rnd()%vmax)+;
}
if(opt==){
add(L,R,x);
}
else if(opt==){
assign(L,R,x);
}
else if(opt==){
cout<<Rank(L,R,x)<<endl;
}
else{
cout<<query(L,R,x,y)<<endl;
}
}
}