Codeforces Round #449 (Div. 2)
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)的更多相关文章
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 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 ...
- 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 ...
- Codeforces Round #449 (Div. 2) D. Ithea Plays With Chtholly
题目链接 交互题. 题意:给你三个数n,m,k.让你完成至多m次互动,每次给你一个q,让你从n个位置选一个位置放这个数,覆盖已经放过的数.让你再m次使得n个位置的数不递减,达到直接退出. 解法:暴力, ...
- Codeforces Round #449 Div. 1
B:注意到nc/2<=m,于是以c/2为界决定数放在左边还是右边,保证序列满足性质的前提下替换掉一个数使得其更靠近边界即可. #include<iostream> #include& ...
- 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: ...
- Codeforces Round #449 (Div. 1)C - Willem, Chtholly and Seniorious
ODT(主要特征就是推平一段区间) 其实就是用set来维护三元组,因为数据随机所以可以证明复杂度不超过O(NlogN),其他的都是暴力维护 主要操作是split,把区间分成两个,用lowerbound ...
- 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 ...
- 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 ...
随机推荐
- 什么是pytorch(2Autograd:自动求导)(翻译)
Autograd: 自动求导 pyTorch里神经网络能够训练就是靠autograd包.我们来看下这个包,然后我们使用它来训练我们的第一个神经网络. autograd 包提供了对张量的所有运算自动求导 ...
- Python生成器(generator)和迭代器(Iterator)
列表生成式 a = [i+1 for i in range(10)] print(a) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 这就是列表生成式 生成器(generator) ...
- zabbix之 自动发现磁盘io util 监控
一.iostat Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个.iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之 ...
- pre-commit 钩子,代码质量检查:在 vue-cli 3.x 版本中,已经使用尤大改写的yorkie,yorkie实际是fork husky,然后做了一些定制化的改动,使得钩子能从package.json的 "gitHooks"属性中读取
pre-commit 钩子,代码质量检查:在 vue-cli 3.x 版本中,已经使用尤大改写的yorkie,yorkie实际是fork husky,然后做了一些定制化的改动,使得钩子能从packag ...
- 第三章 C#程序结构[3.2 选择结构的应用(Windows窗体应用程序)(四)]
[案例]设计一个顾客选购商品的系统.其中,顾客身份有两类,一类是VIP,另一类是普通会员:商品种类有3种.分别是上衣.裤子和鞋子.其中,VIP享受8折优惠和商店赠送的礼品,而普通会员都不享受.单击[确 ...
- 单因素方差分析的SAS实现
实验内容:某城市从4个排污口取水,进行某种处理后检测大肠杆菌数量,单位面积内菌落数如下表所示,请分析各个排污口的大肠杆菌数量是否有差别. 排污口 1 2 3 4 大肠杆菌数量 9,12,7,5 20, ...
- linux 磁盘 扩展分区
- note 0 Python介绍及Python IDE环境安装 Spyder with Anaconda
高级语言分类 编译型语言(C/C++等) 解释型语言(BASIC.Python等) Python 诞生于1989年,创始人为吉多 范罗苏姆(Guido van Rossum) Python 语言特点 ...
- 理解Linux系统负荷load average
理解Linux系统负荷 一.查看系统负荷 如果你的电脑很慢,你或许想查看一下,它的工作量是否太大了. 在Linux系统中,我们一般使用uptime命令查看(w命令和top命令也行).(另外,它们在 ...
- vim常用操作和使用技巧
vi是linux与unix下的常用文本编辑器,其运行稳定,使用方便,本文将分两部分对其常用操作技巧和配置进行阐述,其中参考了网上的一些文章,对作者表示感谢 PART1 操作技巧 说明: 以下的例子中 ...