Codeforces Round #569 (Div. 2)
题解 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)的更多相关文章
- 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 ...
- Codeforces Round #569 (Div. 2) C. Valeriy and Deque
链接: https://codeforces.com/contest/1180/problem/C 题意: Recently, on the course of algorithms and data ...
- Codeforces Round #569 (Div. 2) B. Nick and Array
链接: https://codeforces.com/contest/1180/problem/B 题意: Nick had received an awesome array of integers ...
- 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 ...
- Codeforces Round #569 Div. 1
A:n-1次操作后最大值会被放到第一个,于是暴力模拟前n-1次,之后显然是循环的. #include<bits/stdc++.h> using namespace std; #define ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- jsp中使用Servlet查询SQLSERVER数据库中的表的信息,并且打印在屏幕上
jsp中使用Servlet查询SQLSERVER数据库中的表的信息,并且打印在屏幕上 1.JavaBean的使用 package com.zheng; public class BookBean { ...
- 8.uvloop
uvloop是asyncio的事件循环的替代方案,性能高于默认asyncio的事件循环的效率,相当于提升两倍,效率可以比肩Go pip3 install uvloop import asyncio ...
- 7.pyagem-游戏背景
背景交替滚动 游戏启动后,背景图像不断的向下移动 在视觉上产生角色不断向上移动的错觉 游戏背景不断变化,游戏主角的位置报错不变 实现方案 创建两张背景图 第一张完全和屏幕重合,第二章在屏幕的正上方 ...
- 6.jmespath表达式
jmespath是json的查询语言 可以从json文档中提取和转换元素,类似于jsonpath的另外一个库 字典取值 # 一层嵌套取值 {a:1,b:2,c:3} ""&qu ...
- Microsoft Office for Mac最新版本安装教程,亲测可用!!!
办公必备的Office工具,它为需要使用 Office 工具的用户和企业设计,让他们可以利用功能强大的 Outlook 来处理电子邮件.日历和通讯录事宜.你所熟知和信赖的 Office 经过更新后,可 ...
- adb 安装与使用
什么是adb adb 是有个通用命令行工具 他允许您与模拟器实例或者链接的Android设备进行通信,他可为各种设备操作提供便利,比如安装和调试应用 启动adb 服务在命令行中输入adb start- ...
- 基于 .NET 7 的 QUIC 实现 Echo 服务
前言 随着今年6月份的 HTTP/3 协议的正式发布,它背后的网络传输协议 QUIC,凭借其高效的传输效率和多路并发的能力,也大概率会取代我们熟悉的使用了几十年的 TCP,成为互联网的下一代标准传输协 ...
- Day03.1:初学者安装IDEA后需要知道的小技巧
初学者安装IDEA后需要知道的小技巧 1.输入psvm直接生成 main方法 2.输入sout可以直接生成输出语句 3.代码放大设置 4.注释颜色更改 5.代码字体大小通过Ctrl+鼠标滑轮控制的设置 ...
- JavaScript 实现地图搜索功能
需求:输入框输入地址点击查询,查询结果在地图定位到查询位置,显示查询位置的经纬度 <html xmlns="http://www.w3.org/1999/xhtml"> ...
- layui的button失效、layui绑定失效
内容呢,就一句话. 因为不会报错,所以这个坑,找了半天......淦 button失效直接提交刷新可能是没加lay-submit 属性. <button class="layui-bt ...