Codeforces Round #851 (Div. 2) 题解

A. One and Two

取 \(\log_2\),变成加号,前缀和枚举 \(s[i]=\dfrac{s[n]}{2}\)。

B. Sum of Two Numbers

对于每一位,如果是偶数则平均分,如果是奇数则分给当前数字和小的数多 \(1\)。

C. Matching Numbers

随便推个构造即可,给个参考。

void solve(){
int n;
cin>>n;
if(n%2==0){
cout<<"NO"<<endl;
return;
}
cout<<"YES"<<endl;
n*=2;
cout<<"1 "<<n<<endl;
for(int i=2,tmp=n-2;i<=(n+2)/4;i++,tmp-=2)
cout<<i<<" "<<tmp<<endl;
for(int i=(n+2)/4+1,tmp=n-1;i<=n/2;i++,tmp-=2)
cout<<i<<" "<<tmp<<endl;
return;
}

D. Moving Dots

考虑所求对于一个状态,必然是两个点“双向奔赴”的时候才有贡献。枚举这相邻的两个点 \(x,y\),然后发现 \([x-len,y+len-1]\) 这一范围内其他数取不了。使用 lower_bound 随便求就好了。

时间复杂度 \(O(n^2\log n)\)。

E. Sum Over Zero

转移为前缀和,写出 \(dp\) 状态为:

\[f_i=\max(f_{i-1},\max_{j<i,s_j\leq s_i} f_{j-1}+(i-j))
\]

考虑把 \(f_{j-1}-j\) 试做一个整体,那么相当于维护这玩意最小值。

树状数组即可。

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define MP make_pair
inline ll read(){
ll re=0;char ch=getchar();
while(ch>'9'||ch<'0') ch=getchar();
while(ch>='0'&&ch<='9') re=10*re+ch-'0',ch=getchar();
return re;
}
int n;
namespace sugt{
int mx[200005];
void build(){
for(int i=1;i<=n;i++) mx[i]=-1e9;
}
int lowbit(int x){
return x&(-x);
}
void ins(int x,int y){
while(x<=n){
mx[x]=max(mx[x],y);
x+=lowbit(x);
}
return;
}
int query(int x){
int res=-1e9;
while(x){
res=max(res,mx[x]);
x-=lowbit(x);
}
return res;
}
}
ll s[200005],t[200005];
int f[200005];
map<ll,int> M;int tot=0;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>s[i];
s[i]+=s[i-1];
t[i]=s[i];
}
sort(t,t+n+1);
for(int i=0;i<=n;i++)
if(!M[t[i]]) M[t[i]]=++tot;
for(int i=0;i<=n;i++)
s[i]=M[s[i]];
sugt::build();
sugt::ins(s[0],0);
for(int i=1;i<=n;i++){
f[i]=max(f[i-1],sugt::query(s[i])+i);
sugt::ins(s[i],f[i-1]-i);
}
cout<<f[n];
return 0;
}

F. XOR, Tree, and Queries

引理: 假设 \(w(u,v)\) 为 \(u,v\) 路径上所有边权异或,则 \(w(u,v)=w(1,u)\ \text{xor}\ w(1,v)\)。

本题相当于给 \(w(1,u)\) 赋权。\(w(1,u)\) 有贡献当且仅当 \(d(u)\) 为奇数。

对于每个 \((u,v,w)\) 连边,每个连通块选代表点,代表点确定整个块确定。

拆位枚举即可。

Codeforces Round #851 (Div. 2) 题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  5. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  6. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  7. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  8. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  9. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

  10. Codeforces Round #271 (Div. 2)题解【ABCDEF】

    Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...

随机推荐

  1. ActiveReports报表行号

    =RunningValue(Fields!字段名称.Value, CountDistinct, "矩表分组名称") RunningValue(Fields!区域.Value, Co ...

  2. yum 安装失败解决思路$releasever(curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error")

    问题 公司使用刀片机的系统版本是CentOS 7.9.2009(Core),本人在重新安装虚拟机时,也使用对应的系统版本,在安装软件时,yum无法正常使用,一开始觉得,centos的release版本 ...

  3. Flask Echarts 实现历史图形查询

    Flask前后端数据动态交互涉及用户界面与服务器之间的灵活数据传递.用户界面使用ECharts图形库实时渲染数据.它提供了丰富多彩.交互性强的图表和地图,能够在网页上直观.生动地展示数据.EChart ...

  4. 5.1 Windows驱动开发:判断驱动加载状态

    在驱动开发中我们有时需要得到驱动自身是否被加载成功的状态,这个功能看似没啥用实际上在某些特殊场景中还是需要的,如下代码实现了判断当前驱动是否加载成功,如果加载成功, 则输出该驱动的详细路径信息. 该功 ...

  5. Dash 2.15版本新特性介绍

    本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/dash-master 大家好我是费老师,Dash不久前发布了其2.15.0版本,新增了一些实用的特性 ...

  6. .NET 云原生架构师训练营(模块二 基础巩固 HTTP管道与中间件)--学习笔记

    2.3.2 Web API -- HTTP管道与中间件 管道 中间件 ASP.NET Core 中间件:https://docs.microsoft.com/zh-cn/aspnet/core/fun ...

  7. 从零开始的react入门教程(六),一篇文章理解react组件生命周期

    壹 ❀ 引 学习任何一门框架,无论是vue.react亦或是angular,我们除了需要熟练掌握框架语法外,了解框架自身的生命周期也是至关重要的.一方面生命周期在面试中多多少少总是会提及,其次了解框架 ...

  8. JS 页面离开事件 页面关闭事件,实现登录成功返回上个页面

    壹 ❀ 引 登录成功后跳转到上一个页面是很常见的需求,比如在天猫添加购物车时网站会效验用户登录情况,若未登录则跳转登录,登录成功返回到先前的商品页. 这个功能实现并不困难,但因为我的奇思妙想让我先后了 ...

  9. Keil MDK STM32系列(十) Ubuntu下的PlatformIO开发环境

    Keil MDK STM32系列 Keil MDK STM32系列(一) 基于标准外设库SPL的STM32F103开发 Keil MDK STM32系列(二) 基于标准外设库SPL的STM32F401 ...

  10. Centos7安装php7.4

    添加 EPEL and REMI 仓库 yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarc ...