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 ...
随机推荐
- spring--多人开发,模块化配置
需要在配置文件中配置: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="h ...
- python __name__ 和__main__的使用领悟
__name__和__main__的使用 #hello.pydef sayHello(): str="hello" print(str); if __name__ == " ...
- JS 模拟 重载
重载:方法,根据传入的参数列表不同,执行不同的任务. 比如:functiion jz(money){ //现金结账:验钞,找零 } function jz(cardId,pwd){ //刷卡结 ...
- SQL Server 幻读 的真实案例
数据库中有表[01_SubjectiveScoreInfo],要实现表中的数据只被查出一次,此表数据量较大,有三四百万数据.表结构也确实不是很合理,无法修改表结构,即使是新增一个字段也会有相当大的修改 ...
- PythonStudy——字符编码 Character Encoding
测试一下学习字符编码的问题:解决乱码问题 数据 从 硬盘 => 内存 => cpu应用程序打开文本文件的三步骤1.打开应用程序2.将数据加载到内存中3.cpu将内存中的数据直接翻译成字符显 ...
- 在IDEA中实战Git-branch
工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程Git仓库上获取项目源码 场景三:小 ...
- python pytz时区设置模块
如果你的程序要考虑时区,可以使用pytz.pytz官方文档:http://pytz.sourceforge.net/我使用的python版本:3.7.1 datetime模块中有tzinfo相关的东西 ...
- Android SurfaceView及TextureView对比
SurfaceView是什么? 它继承自类View,因此它本质上是一个View.但与普通View不同的是,它有自己的Surface.有自己的Surface,在WMS中有对应的WindowState,在 ...
- MongoDB查询优化
项目场景:Mongo在首次查询特慢,后面就好的.如果长时间不查询,下次开始的第一次又将非常慢,于是从链接当时多方面,排查最终发现还是mongo索引建的有问题. MongoDB在大批量数据查询时经常会遇 ...
- 学习MeteoInfo二次开发教程(八)
总体没什么问题. 1.创建Projection菜单,Lambert,Geographic,ShowLatLon子菜单. 2.需要添加: using MeteoInfoC.Projections; 3. ...