自己开了场镜像玩。

前三题大水题。D有点意思。E完全不会。F被题意杀了……然而还是不会。

不过看过(且看懂)了官方题解,所以这里是六题题解齐全的。


A

水题。给原序列排序,如果此时合法则直接输出,否则说明所有数相同,一定无解。

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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=,f=;
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int n,a[maxn],s1,s2;
int main(){
n=read();
FOR(i,,*n) a[i]=read();
sort(a+,a+*n+);
FOR(i,,n) s1+=a[i];
FOR(i,n+,*n) s2+=a[i];
if(s1==s2) printf("-1\n");
else FOR(i,,*n) printf("%d ",a[i]);
}

B

水题。

首先,如果所有数的奇偶性都相同,那我们什么都不能做。

否则,如果两个数奇偶性不同,可以直接交换;如果两个数奇偶性相同,可以用一个奇偶性不同的作为中介交换。那么实际上就是任意两个数都能交换,排个序即可。

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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=,f=;
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int n,a[maxn];
bool hhh[];
int main(){
n=read();
FOR(i,,n) a[i]=read(),hhh[a[i]&]=true;
if(hhh[] && hhh[]) sort(a+,a+n+);
FOR(i,,n) printf("%d ",a[i]);
}

C

水题。

首先质数位置的值互不相同。一一编号即可。

对于合数(设为 $x$),可以任取它的一个质因子(设为 $p$),令 $a_x=a_p$。此时序列最大值不变,而两个互质的数的位置的值不可能相同。

我取的是最小质因子。

时间复杂度 $O(n)$。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=,f=;
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int n,ans[maxn],pr[maxn],mn[maxn],pl,cnt;
bool vis[maxn];
int main(){
n=read();
FOR(i,,n){
if(!vis[i]) pr[++pl]=i,ans[i]=++cnt;
FOR(j,,pl){
if(i*pr[j]>n) break;
vis[i*pr[j]]=true;
mn[i*pr[j]]=pr[j];
if(i%pr[j]==) break;
}
}
FOR(i,,n) if(mn[i]) ans[i]=ans[mn[i]];
FOR(i,,n) printf("%d ",ans[i]);
}

D

有一点点小难度,但还是很水。

首先考虑这个序列的前缀异或和 $S$。那么对于任意的 $i$,有 $S_i\ne x$;对于任意的 $i,j$($i\ne j$),有 $S_i\oplus x\ne S_j$。

看第二条限制,发现如果选了 $a$,那么不能选 $a\oplus x$;如果选了 $a\oplus x$,那么不能选 $a$。对其它数没有影响。

所以可以在 $a,a\oplus x$ 中任选一个作为前缀异或和。

最后用选出来的前缀异或和算出原序列。此时答案一定是最优。

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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
char ch=getchar();ll x=,f=;
while(ch<'' || ch>'') f|=ch=='-',ch=getchar();
while(ch>='' && ch<='') x=x*+ch-'',ch=getchar();
return f?-x:x;
}
int n,x,lim,ans[maxn],al;
bool vis[maxn];
int main(){
n=read();x=read();
lim=<<n;
FOR(i,,lim-){
if(vis[i^x] || i==x) continue;
vis[i]=true;
ans[++al]=i;
}
printf("%d\n",al);
FOR(i,,al) printf("%d ",ans[i]^ans[i-]);
}

E

太难了……难度 2500……

为此专门另开了篇博客:传送门


F

一开始以为不会给树的形态,一直在想……

这里给出轻重链剖分(俗称树剖)的做法。

首先一开始肯定要查询 $1$ 到 $x$ 的距离。这个就是 $x$ 的深度 $dep_x$。(定义 $1$ 的深度为 $0$)

现在假设我们已经确定 $x$ 在 $u$ 的子树中。一开始 $u=1$。

我们沿着 $u$ 的重儿子一直跳,跳到叶子结点 $v$。(实际上不用真跳,可以实现成 $O(1)$)

接下来,再考虑 $y=lca(x,v)$。(从官方题解盗张图)

首先,询问一次 $dis(x,v)$。由于 $dis(x,v)=dep_x+dep_v-2dep_y$,而 $dis(x,v)$ 已知,$dep_x$ 已知,$dep_v$ 已知,可以算出 $dep_y$。那么 $y$ 也已知。

如果 $dep_x=dep_y$ 那么 $x=y$。 否则我们再询问 $y$ 到 $x$ 路径上的第二个点 $www$(没名字了),然后接下来就可以在 $u=www$ 的子树中寻找答案了。

对于最后一次查找,只用 $1$ 次询问,其它要 $2$ 次询问。预处理 $dep_x$ 要 $1$ 次询问。由于 $sz[www]\le sz[y]/2\le sz[u]$,所以每次 $u$ 的大小都会缩小一半。

那么总共要 $2\log n$ 次询问。时间复杂度 $O(n)$。

代码咕着,会来补的。

Codeforces Round 563 (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 #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

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

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

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

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

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

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

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

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

随机推荐

  1. POJ 1306 暴力求组合数

    Combinations Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11049   Accepted: 5013 Des ...

  2. RocketMQ 使用情况梳理

    个人梳理有限:欢迎大家 丰富此文档 2018年 12 月 RocketMQ 版本  不适用于 新版关系请勿参考目前规划原则:          topic 创建基于业务  消费者基于模块 多对多关系 ...

  3. 循环节 + 矩阵快速幂 - HDU 4291 A Short problem

    A Short problem Problem's Link Mean: 给定一个n,求:g(g(g(n))) % 1000000007 其中:g(n) = 3g(n - 1) + g(n - 2), ...

  4. parallels desktop 的新建虚拟机的步骤

    新建虚拟机的图   点击窗口-----控制中心--再点击控制中心的+号      

  5. dedecms5.7执行PHP代码的用法

    dedecms5.7执行PHP代码的用法 {dede:php} echo 'test'; {/dede:php}

  6. virtualbox通过Nat模式上网,宿主机与宿主机互通

    本地搭建virtualbox,开始用的nat转发模式,这样的话宿主机没法访问虚拟机里面的服务.比如nginx网站.这样很不方便 . 在网上找了好久,终于找到了方案.那就是再添加一块虚拟网卡. 在虚拟机 ...

  7. maven 学习---Maven中央存储库

    当你建立一个 Maven 的项目,Maven 会检查你的 pom.xml 文件,以确定哪些依赖下载. 首先,Maven 将从本地资源库获得 Maven 的本地资源库依赖资源, 如果没有找到,然后把它会 ...

  8. GNU autotools 安装和使用

    1. 下载 http://www.gnu.org/software/software.html 2. 安装 m4-1.4.11.tar.gz autoconf-2.63.tar.gz automake ...

  9. NSQ端口关系以及注意事项

    0.相关参考文章: 官网:https://nsq.io/ <golang实战-nsq集群入门与坑> <nsq系统架构> <NSQ消息队列> 1.启动命令 ①nsql ...

  10. 【IDE_IntelliJ IDEA】在Intellij IDEA中使用Debug

    转载博客:在Intellij IDEA中使用Debug