比赛链接:

Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)

D.Present

题意:

给定大小为$n$的a数组,求下面式子的结果:

$$ (a_1 + a_2) \oplus (a_1 + a_3) \oplus \ldots \oplus (a_1 + a_n) \\ \oplus (a_2 + a_3) \oplus \ldots \oplus (a_2 + a_n) \\ \ldots \\ \oplus (a_{n-1} + a_n) \\$$

分析:

这题看了题解补的

分别求结果的第$k$(以0开始计数)位是否为1

显然,我们不需要关心每个数第$k$位以上是什么,那么对数组取模$2^{k+1}$

两个数的和的第$k$位为1时,才对答案的第$k$位有贡献,那么和的第$k$位为1需要属于$[2^k; 2^{k+1})$或者$[2^{k+1} + 2^k; 2^{k+2} - 2]$,求出这样的和的对数,如果对数为奇数,那么答案的第$k$位为1,否则为0

求对数可以用二分查找来求

AC代码:

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size()) typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII; const ll mod=1e5+7;
const int maxn=4e5+7;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} int ans,a[maxn],b[maxn],n;
int pow2[30]; int cal(int k){
ll res=0;
rep(i,1,n)b[i]=a[i]%(1<<(k+1));
sort(b+1,b+1+n);
rep(i,1,n){
int x=b[i];
// cout<<"x="<<x<<endl;
if(x*2>=pow2[k]&&x*2<=pow2[k+1]-1)res--;
else if(x*2>=pow2[k]+pow2[k+1])res--;
res+=upper_bound(b+1,b+1+n,pow2[k+1]-1-x)-lower_bound(b+1,b+1+n,pow2[k]-x);
res+=upper_bound(b+1,b+1+n,1e9)-lower_bound(b+1,b+1+n,pow2[k]+pow2[k+1]-x);
}
// cout<<"res="<<res<<endl;
return res/2%2;
} int main() {
// cout<<(1<<24)<<endl;
rep(i,0,29)pow2[i]=(1<<i);
scanf("%d",&n);
rep(i,1,n)scanf("%d",&a[i]);
rep(i,0,25)if(cal(i))ans+=(1<<i);
printf("%d\n",ans); return 0;
}

E.Instant Noodles

题意:

在一个$2n$个节点,$m$条边的二分图中,右边部分每个节点有一个权值

构建一个左边节点的子集$S$,所有和这些子集有边的右边节点构成点集$N(S)$,$N(S)$的所有节点权值和为$F(S)$

求所有$F(S)$的最大公约数

分析:

首先是结论,给右边点分类,如果两个点的边集相同,那么他们属于一类

边集相同的意思是,他们所连接的左边节点的数量和类型一模一样

属于相同类的节点权值相加,然后再取所有类的最大公约数,就是最后的答案了

证明:如果两个点属于一类,那么只要有其中一个点出现,另一个点肯定出现,这是显然的

所以,如果这些类的权值依次为$a,b,c$的话,$F(S)$只能取$a,b,c,a+b,a+c,b+c,a+b+c$,这些数的$gcd$是等于$gcd(a,b,c)$的

哈希的话,居然可以用vector直接哈希,这个我完全没想到

注意:vector需要排好序

long long 哈希:

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size()) typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII; const ll mod=1e5+7;
const int maxn=5e5+7; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} int g=1331,n,m;
map<ll,ll>ma;
ll powg[maxn];
VI ve[maxn];
ll c[maxn]; int main() {
powg[0]=1;
rep(i,1,maxn-1)powg[i]=powg[i-1]*g;
int T;
scanf("%d",&T);
while(T--){ scanf("%d %d",&n,&m);
rep(i,1,n)scanf("%lld",&c[i]);
rep(i,1,m){
int a,b;
scanf("%d %d",&a,&b);
ve[b].pb(a);
}
rep(i,1,n){
ll res=0;
for(auto j:ve[i])
res+=powg[j];
if(SZ(ve[i]))ma[res]+=c[i];
}
ll ans=0;
for(auto i:ma)
ans=__gcd(i.se,ans);
printf("%lld\n",ans);
ma.clear();
rep(i,1,n)ve[i].clear();
}
return 0;
}

  

vector哈希:

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size()) typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII; const ll mod=1e5+7;
const int maxn=5e5+7; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll c[maxn];
int n,m;
map<VI,ll>ma;
VI ve[maxn]; int main() {
int T;
scanf("%d",&T);
while(T--){ scanf("%d %d",&n,&m);
rep(i,1,n)scanf("%lld",&c[i]);
rep(i,1,m){
int a,b;
scanf("%d %d",&a,&b);
ve[b].pb(a);
}
rep(i,1,n){ if(SZ(ve[i])){
sort(ve[i].begin(),ve[i].end());
ma[ve[i]]+=c[i];
}
}
ll ans=0;
for(auto i:ma){
ans=gcd(i.se,ans);
// cout<<i.se<<endl;
}
printf("%lld\n",ans);
ma.clear();
rep(i,1,n)ve[i].clear();
}
return 0;
}

  

总结:

Codeforces Round #626 Div2 D,E的更多相关文章

  1. Codeforces Round #626 Div2 D. Present(位掩码,二分)

    题目链接:https://codeforces.com/contest/1323/problem/D 题意:给了大小为4e5的数组a,其中1<=ai<=1e7.求所有点对和的异或和,即: ...

  2. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  3. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  4. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  5. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  6. Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)

    A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream& ...

  7. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  8. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  9. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

随机推荐

  1. 任意文件下载漏洞的接口URL构造分析与讨论

    文件下载接口的URL构造分析与讨论 某学院的文件下载接口 http://www.****.edu.cn/item/filedown.asp?id=76749&Ext=rar&fname ...

  2. SpringBoot启动报端口已被占用--解决

    问题 启动SpringBoot项目后发现启动失败,控制台输出以下内容 Description: The Tomcat connector configured to listen on port 81 ...

  3. spring ioc踏出第一步

    spring IOC(容器) AOP(面向切面编程) IOC容器:他的功能就是可以整合像 Structs2 .Hibernate.Mybatis: IOC:控制反转:所谓的控制就是控制资源的获取方法, ...

  4. HAProxy + keepalived 高可用集群代理

    HAProxy + keepalived # 1 安装keepalived: yum install keepalived -y # 2 修改KEEPalived配置文件: vim /etc/keep ...

  5. Linux 文件查看相关的一些命令

    文件压缩解压命令 # 解压 xxx.xz 并删除 xz -d test.tar.xz # 打包成 xxx.tar , 语法: tar -cvf 最后包名.tar ./要打包文件 ./要打包的文件 ta ...

  6. drop table 命令不回收以前的相关访问权限

    drop table 命令不回收以前的相关访问权限,也就是说假如我现在把表删除了,然后再创建一个同名的表时,会自动赋予权限的.

  7. 【VNC】vnc远程连接的时候无法显示图像已解决

    介绍一个 VNC连接工具:iis7服务器管理工具 IIs7服务器管理工具可以批量连接并管理VNC服务器 作为服务器集成管理器,它最优秀的功能就是批量管理windows与linux系统服务器.vps.能 ...

  8. LeetCode108.有序数组转二叉搜索树

    题目 1 class Solution { 2 public: 3 TreeNode* sortedArrayToBST(vector<int>& nums) { 4 if(num ...

  9. 单片机—Arduino UNO-R3—学习笔记002

    led控制 本篇主要介绍Arduino数字引脚及相关函数,通过数字I/O输出控制板载LED灯亮灭状态(数字引脚13). 数字信号是以0.1表示的电平不连续变化的信号,也就是以二进制的形式表示的信号. ...

  10. vue路由切换和用location切换url的区别

    最近的业务涉及到了axios的拦截器,要在request.js里面要根据状态码来跳转页面,这时候我就面对了几种跳转选择: 1.使用location.href='/url'来跳转,简单方便,但是刷新了页 ...