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;
}
}
}

Codeforces Round #449 (Div. 2)的更多相关文章

  1. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】

    B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)

    A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #449 (Div. 2) D. Ithea Plays With Chtholly

    题目链接 交互题. 题意:给你三个数n,m,k.让你完成至多m次互动,每次给你一个q,让你从n个位置选一个位置放这个数,覆盖已经放过的数.让你再m次使得n个位置的数不递减,达到直接退出. 解法:暴力, ...

  5. Codeforces Round #449 Div. 1

    B:注意到nc/2<=m,于是以c/2为界决定数放在左边还是右边,保证序列满足性质的前提下替换掉一个数使得其更靠近边界即可. #include<iostream> #include& ...

  6. Codeforces Round #449 (Div. 1) Willem, Chtholly and Seniorious (ODT维护)

    题意 给你一个长为 \(n\) 的序列 \(a_i\) 需要支持四个操作. \(1~l~r~x:\) 把 \(i \in [l, r]\) 的 \(a_i\) 加 \(x\) . \(2~l~r~x: ...

  7. Codeforces Round #449 (Div. 1)C - Willem, Chtholly and Seniorious

    ODT(主要特征就是推平一段区间) 其实就是用set来维护三元组,因为数据随机所以可以证明复杂度不超过O(NlogN),其他的都是暴力维护 主要操作是split,把区间分成两个,用lowerbound ...

  8. Codeforces Round #449 (Div. 2) C. DFS

    C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  9. Codeforces Round #449 (Div. 2) A. Scarborough Fair【多次区间修改字符串】

    A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. springMVC---业务处理流程图和最简单的springMvc搭建截图说明

    一.springMVC业务处理流程图: 二.如何搭建springMvc框架 1.建立web工程 2.引入jar包 3.创建web.xml文件 4.创建springMvc-servlet.xml文件 5 ...

  2. python 0,1行列问题

    shape[0]-- 行 A.min(0) --A的按列最小值,生成一个行向量 >>> a = np.random.rand(3,3) >>> a array([[ ...

  3. IDEA一定要改的八条配置

    引言 坦白说,我很少写这种操作类型的文章.因为这种文章没啥新意,大家操作步骤肯定是一样的.然而,我答应了我的同事小阳,给她出一篇!毕竟人家打算从Eclipse转IDEA了,于是以示鼓励,写一篇给她! ...

  4. zombodb 数据类型映射

    zombodb 与es 数据类型的映射处理 通用数据类型映射 Postgres 类型 Elasticsearch JSON 映射定义 bytea {"type": "bi ...

  5. Spring Boot/Spring Cloud

    104.什么是 spring boot?         在Spring框架这个大家族中,产生了很多衍生框架,比如 Spring.SpringMvc框架等,Spring的核心内容在于控制反转(IOC) ...

  6. Java面试题 corejava(二)

    65.JAVA 语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try 块中可以抛出异常吗?[基础] 答:Java 通过面向对象的方法进行 ...

  7. windows与linux换行规则

    在计算机还没有出现之前,有一种叫做电传打字机(Teletype Model 33)的玩意,每秒钟可以打10个字符.但是它有一个问题,就是打完一行换行的时候,要用去0.2秒,正好可以打两个字符.要是在这 ...

  8. django 获取用户提交的数据 文件 表单

    templates: <div> <form action="/detail" method="post" enctype="mul ...

  9. FluentData -Micro ORM with a fluent API that makes it simple to query a database 【MYSQL】

    官方地址:http://fluentdata.codeplex.com/documentation MYSQL: MySQL through the MySQL Connector .NET driv ...

  10. DotNetBar创建的Ribbon、标签式多文档界面

    1.创建一个form作为主窗体,继承自:DevComponents.DotNetBar.RibbonForm 设置属性:IsMdiContainer为true 2.创建一个form,作为子窗体,也继承 ...