题解 Codeforces Round #569 (Div. 2)

rank:1306/11165 rate: +43 1424 → 1467

Codeforces Round #569 (Div. 2)

A. Alex and a Rhombus

热身题。解决这道题需要的知识:读懂题面

#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; int n,cnt; inline int read();
inline ll readll(); int main(){
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
#endif n=read(); if(n==1){
cout<<1<<endl;
return 0;
} for(int i=-(n-1);i<=(n-1);++i){
for(int j=-(n-1);j<=(n-1);++j){
if(abs(i)+abs(j)<=(n-1)) cnt++;
}
} cout<<cnt<<endl; return 0;
} inline int read(){
char tmp=getchar(); int sum=0; bool flag=false;
while(tmp<'0'||tmp>'9'){
if(tmp=='-') flag=true;
tmp=getchar();
}
while(tmp>='0'&&tmp<='9'){
sum=(sum<<1)+(sum<<3)+tmp-'0';
tmp=getchar();
}
return flag?-sum:sum;
} inline ll readll(){
char tmp=getchar(); ll sum=0; bool flag=false;
while(tmp<'0'||tmp>'9'){
if(tmp=='-') flag=true;
tmp=getchar();
}
while(tmp>='0'&&tmp<='9'){
sum=(sum<<1)+(sum<<3)+tmp-'0';
tmp=getchar();
}
return flag?-sum:sum;
}

B. Nick and Array

刚开始以为是什么牛批的数位dp,后来才发现是贪心。考场的时候自己尝试贪心了一下,但被system check hack掉了

再总结一下思路:首先为了绝对值最大,把所有的正数转换为整数;然后为了避免得到负数,倘若有奇数个负数,就将最大的那个取反

#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; const int MAX=1e5+5,INF=0x3f3f3f3f; int n,minn,neg,pos;
int num[MAX]; inline int read();
inline ll readll(); int main(){
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
#endif n=read();
for(int i=1;i<=n;++i) num[i]=read();
for(int i=1;i<=n;++i) {if(num[i]>=0) num[i]=-num[i]-1; if(num[i]<0) neg++;}
for(int i=1;i<=n;++i) {if(abs(num[i])>minn) minn=abs(num[i]),pos=i;} if(neg%2==1) num[pos]=-num[pos]-1; for(int i=1;i<=n;++i) printf("%d ",num[i]); return 0;
} inline int read(){
char tmp=getchar(); int sum=0; bool flag=false;
while(tmp<'0'||tmp>'9'){
if(tmp=='-') flag=true;
tmp=getchar();
}
while(tmp>='0'&&tmp<='9'){
sum=(sum<<1)+(sum<<3)+tmp-'0';
tmp=getchar();
}
return flag?-sum:sum;
} inline ll readll(){
char tmp=getchar(); ll sum=0; bool flag=false;
while(tmp<'0'||tmp>'9'){
if(tmp=='-') flag=true;
tmp=getchar();
}
while(tmp>='0'&&tmp<='9'){
sum=(sum<<1)+(sum<<3)+tmp-'0';
tmp=getchar();
}
return flag?-sum:sum;
}

C. Valeriy and Deque

有点忘了题面了..不过难度不大,好像是关于循环的。

#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; const int MAX=1e5+5,INF=0x3f3f3f3f; int n,q,tar,pos;
int a[MAX],line[MAX],rec[MAX][2]; deque <int> ord; inline int read();
inline ll readll(); int main(){
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
#endif n=read(); q=read();
for(int i=1;i<=n;++i){
a[i]=read();
if(a[i]>tar) tar=a[i],pos=i;
} for(int i=1;i<=n;++i) ord.push_back(a[i]);
for(int i=1;i<=pos-1;++i){
int a=ord.front(); ord.pop_front();
int b=ord.front(); ord.pop_front();
if(a>b){
ord.push_front(a); ord.push_back(b);
rec[i][0]=a; rec[i][1]=b;
}
else{
ord.push_front(b); ord.push_back(a);
rec[i][0]=a; rec[i][1]=b;
}
}
ord.pop_front();
for(int i=1;i<n;++i){
line[i]=ord.front(); ord.pop_front();
} for(int k=1;k<=q;++k){
ll q=readll();
if(q<pos){
printf("%d %d\n",rec[q][0],rec[q][1]);
}
else{
q-=(pos-1);
q%=(n-1);
printf("%d %d\n",tar,line[q?q:n-1]);
}
} return 0;
} inline int read(){
char tmp=getchar(); int sum=0; bool flag=false;
while(tmp<'0'||tmp>'9'){
if(tmp=='-') flag=true;
tmp=getchar();
}
while(tmp>='0'&&tmp<='9'){
sum=(sum<<1)+(sum<<3)+tmp-'0';
tmp=getchar();
}
return flag?-sum:sum;
} inline ll readll(){
char tmp=getchar(); ll sum=0; bool flag=false;
while(tmp<'0'||tmp>'9'){
if(tmp=='-') flag=true;
tmp=getchar();
}
while(tmp>='0'&&tmp<='9'){
sum=(sum<<1)+(sum<<3)+tmp-'0';
tmp=getchar();
}
return flag?-sum:sum;
}

D. Tolik and His Uncle

刚读这道题的时候意为是某种神级搜索题。嗯?矢量?不可重复?状压?广搜?..总之考场一顿思索没有结果。题解:规律题 去您的规律..

感觉官方题解解释的就很清晰,附上地址

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int MAX=1e6+5; int n,m; inline int read(); int main(){
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
#endif n=read(); m=read(); for(int j=1;j<=m/2;++j){
for(int i=1;i<=n;++i){
printf("%d %d\n%d %d\n",i,j,n-i+1,m-j+1);
}
}
if(m%2==1){
int l=1,r=n,tar=m/2+1;
while(l<=r){
if(l<=r) printf("%d %d\n",l,tar),l++;
if(l<=r) printf("%d %d\n",r,tar),r--;
}
} return 0;
} inline int read(){
char tmp=getchar(); int sum=0; bool flag=false;
while(tmp<'0'||tmp>'9'){
if(tmp=='-') flag=true;
tmp=getchar();
}
while(tmp>='0'&&tmp<='9'){
sum=(sum<<1)+(sum<<3)+tmp-'0';
tmp=getchar();
}
return sum;
}

E. Serge and Dining Room

线段树的玄学题。到现在为止虽然通过了,但个人感觉对正解理解非常不透彻,还是说这道题就是这么的迷?

贪心的发现:同学的顺序没有卵用。在保证钱的种类数和个数一定时,答案是唯一的

考虑一下“菜i可不可以被购买”和“价格大于等于i的菜个数减去钱大于等于i的同学数”之间的关系

菜i可以被购买

那么一定满足价格大于等于i的菜个数大于钱大于等于i的同学数

菜i不可以被购买

那么一定不满足价格大于等于i的菜个数大于钱大于等于i的同学数 吗..?

非也。

!这就是一个菜不可以被购买,但是却满足差大于等于1的情况。那该怎么办..

考量一下,发现这种情况出现的必要条件就是右侧存在答案更优的菜。也就是说类似于二分答案的单调性。

维护权值线段树,遇到菜则价格处+1,遇到同学则价格处-1

我们用线段树维护一下每一个节点的后缀和,并为每一个区间维护一个max。不断经可能向右取max大于等于1的菜,即有可能成为答案。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ST segment_tree:: const int MAX=4000005,TOP=1000000; namespace segment_tree{
int pre[MAX],sum[MAX],lazy[MAX],maxx[MAX]; void build(int p,int l,int r){
if(l==r) {sum[p]=maxx[p]=pre[l]; return;}
int mid=(l+r)>>1;
build(p<<1,l,mid); build(p<<1|1,mid+1,r);
sum[p]=sum[p<<1]+sum[p<<1|1];
maxx[p]=max(maxx[p<<1],maxx[p<<1|1]);
} void add(int p,int l,int r,int del){
sum[p]+=(r-l+1)*del;
lazy[p]+=del;
maxx[p]+=del;
} void pushdown(int p,int l,int r){
int mid=(l+r)>>1;
add(p<<1,l,mid,lazy[p]);
add(p<<1|1,mid+1,r,lazy[p]);
lazy[p]=0;
} void modify(int p,int l,int r,int L,int R,int del){
if(L<=l&&r<=R) return add(p,l,r,del);
int mid=(l+r)>>1;
pushdown(p,l,r);
if(L<=mid) modify(p<<1,l,mid,L,R,del);
if(mid+1<=R) modify(p<<1|1,mid+1,r,L,R,del);
sum[p]=sum[p<<1]+sum[p<<1|1];
maxx[p]=max(maxx[p<<1],maxx[p<<1|1]);
} int qsum_sum(int p,int l,int r,int L,int R){
if(L<=l&&r<=R) return sum[p];
pushdown(p,l,r);
int mid=(l+r)>>1,ans=0;
if(L<=mid) ans+=qsum_sum(p<<1,l,mid,L,R);
if(mid+1<=R) ans+=qsum_sum(p<<1|1,mid+1,r,L,R);
return ans;
} int query(int p,int l,int r){
if(l==r) return l;
pushdown(p,l,r);
int mid=(l+r)>>1;
if(maxx[p<<1|1]>=1) return query(p<<1|1,mid+1,r);
else if(maxx[p<<1]>=1) return query(p<<1,l,mid);
else return -1;
}
} int n,m,q;
int a[TOP],b[TOP]; inline int read(); int main(){
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
#endif n=read(); m=read();
for(int i=1;i<=n;++i) a[i]=read(),ST pre[a[i]]++;
for(int i=1;i<=m;++i) b[i]=read(),ST pre[b[i]]--;
for(int i=TOP;i>=1;--i) ST pre[i]=ST pre[i]+ST pre[i+1];
ST build(1,1,TOP); q=read();
for(int i=1;i<=q;++i){
int type,pos,x; type=read(); pos=read(); x=read();
switch(type){
case 1:
ST modify(1,1,TOP,1,a[pos],-1);
ST modify(1,1,TOP,1,x,1);
a[pos]=x;
printf("%d\n",ST query(1,1,TOP));
break;
case 2:
ST modify(1,1,TOP,1,b[pos],1);
ST modify(1,1,TOP,1,x,-1);
b[pos]=x;
printf("%d\n",ST query(1,1,TOP));
break;
}
} return 0;
} inline int read(){
char tmp=getchar(); int sum=0; bool flag=false;
while(tmp<'0'||tmp>'9'){
if(tmp=='-') flag=true;
tmp=getchar();
}
while(tmp>='0'&&tmp<='9'){
sum=(sum<<1)+(sum<<3)+tmp-'0';
tmp=getchar();
}
return flag?-sum:sum;
}

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

  1. Codeforces Round #569 (Div. 2)A. Alex and a Rhombus

    A. Alex and a Rhombus 题目链接:http://codeforces.com/contest/1180/problem/A 题目: While playing with geome ...

  2. Codeforces Round #569 (Div. 2) C. Valeriy and Deque

    链接: https://codeforces.com/contest/1180/problem/C 题意: Recently, on the course of algorithms and data ...

  3. Codeforces Round #569 (Div. 2) B. Nick and Array

    链接: https://codeforces.com/contest/1180/problem/B 题意: Nick had received an awesome array of integers ...

  4. Codeforces Round #569 (Div. 2) 题解A - Alex and a Rhombus+B - Nick and Array+C - Valeriy and Dequ+D - Tolik and His Uncle

    A. Alex and a Rhombus time limit per test1 second memory limit per test256 megabytes inputstandard i ...

  5. Codeforces Round #569 Div. 1

    A:n-1次操作后最大值会被放到第一个,于是暴力模拟前n-1次,之后显然是循环的. #include<bits/stdc++.h> using namespace std; #define ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  10. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. 4.pytest结合allure-pytest插件生成allure测试报告

    之前我们使用的测试报告插件是pytest-html 这次使用的插件是allure-pytest,更加美观强大 安装插件 pip3 install allure-pytest 安装allure(Mac) ...

  2. Dapr实现.Net Grpc服务之间的发布和订阅,并采用WebApi类似的事件订阅方式

    大家好,我是失业在家,正在找工作的博主Jerry,找工作之余,总结和整理以前的项目经验,动手写了个洋葱架构(整洁架构)示例解决方案 OnionArch.其目的是为了更好的实现基于DDD(领域驱动分析) ...

  3. Python 多重继承时metaclass conflict问题解决与原理探究

    背景 最近有一个需求需要自定义一个多继承abc.ABC与django.contrib.admin.ModelAdmin两个父类的抽象子类,方便不同模块复用大部分代码,同时强制必须实现所有抽象方法,没想 ...

  4. SLAM中的内外点

    内外点之分最简单的说法就是是否符合当前位姿的判断:如果根据当前位姿,之前帧二维特征点所恢复出的地图点重投影到当前帧与实际的二维特征点匹配不上了,那么认为这个是质量差的点是outlier,抛弃掉,如果能 ...

  5. vue-axios更改操作

    <template> <div class="nav"> <label for="">新部门</label>&l ...

  6. Linux--网络基础(概念+协议的了解+OSI七层模型,TCP/IP五层协议,网络数据传输流程)

    网络的发展 网络的发展有下面几个阶段: 独立模式:计算机最开始是以单机模式被广泛使用的.每一台计算机都是独立的,之间不能够进行数据共享与通信 网络互联: 计算机之间可以链接在一起,完成数据共享,计算机 ...

  7. Uniapp And Taro一些小测评

    前情 最近公司准备新开发一个小程序项目,对于使用哪一款小程序框架有一些犹豫,我有过2年左右的uniapp项目开发经验,Taro在刚刚出来的时候有尝试过,经常莫名报错需要重启,在内心是有些偏向uniap ...

  8. .Net SemaphoreSlim

    看Elsa-core源代码中看到的,Elsa-core中所有保存数据的方法似乎使用同一个Save方法.如下图: 那么为什么要使用这玩意,我还是头一次见这玩意???? 好吧,我承认我自己菜.我自个儿也该 ...

  9. Go语言核心36讲10

    我们在上次讨论了数组和切片,当我们提到数组的时候,往往会想起链表.那么Go语言的链表是什么样的呢? Go语言的链表实现在标准库的container/list代码包中.这个代码包中有两个公开的程序实体- ...

  10. i春秋Blog

    打开是个普普通通的hello world 然后有注册有登录 不多说我们直接注册登录试试 登录后有个POST选项,可以上传东西,先试试上传文字 没什么重要的回显 再上传一个文档试试 爆出提示:这里使用的 ...