比赛链接:

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. LeetCode682 棒球比赛

    题目描述: 你现在是棒球比赛记录员.给定一个字符串列表,每个字符串可以是以下四种类型之一:1.整数(一轮的得分):直接表示您在本轮中获得的积分数.2. "+"(一轮的得分):表示本 ...

  2. 那些最全面的Windows10安装pytorch踩过的坑以及如何应用

    那些最全面的Windows10安装pytorch踩过的坑以及如何应用 一.pytorch简介 2017年1月,由Facebook人工智能研究院(FAIR)基于Torch推出了PyTorch.它是一个基 ...

  3. 【ASM】asm中添加 diskgroup

    环境:rhel5 Oracle10g rac 背景:在esxi中添加了一个20g的共享磁盘准备存放归档日志用 一.准备环境 1.添加共享磁盘并且格式化 #fdisk -l查看磁盘已经添加完成 #fdi ...

  4. SSTI

    最牛bypass:https://blog.csdn.net/solitudi/article/details/107752717 SSTI的奇怪绕过姿势:https://blog.csdn.net/ ...

  5. 深入解析vue响应式原理

    摘要:本文主要通过结合vue官方文档及源码,对vue响应式原理进行深入分析. 1.定义 作为vue最独特的特性,响应式可以说是vue的灵魂了,表面上看就是数据发生变化后,对应的界面会重新渲染,那么响应 ...

  6. Poj-P3468题解【线段树】

    本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: http://poj.org/problem?id=3468 题目描述: 给N个数A1, A2 ...

  7. Vue案例之todoLIst实现

    使用Vue实现todolist案例,如有不对敬请大佬多多指教 功能: 1.增加功能:在新增版块里面的输入框内输入数据,点击后面的"添加"按钮,将输入的数据添加到列表中,默认是未完成 ...

  8. inode占满导致No space left on device inode快速解决方法

    暂未发现其他比我这个更快的方法. 因为其他方法会展示那个非常卡的目录,导致效率极低.而我这个方法不会去展示那个目录. 查找占用的目录 find / -type d -size +1M -maxdept ...

  9. 【分享】每个 Web 开发者在 2021 年必须拥有 15 个 VSCode 扩展

    为什么VSCode如此受欢迎 Visual Studio Code在开发人员中迅速流行起来,它是最流行的开发环境,可定制性是其流行的原因之一. 因此,如果你正在使用VSCode,这里有一个扩展列表,你 ...

  10. rbd-db数据迁移至外部数据库

    部署外部数据库 安装Docker export VERSION=19.03 && curl -fsSL http://rainbond-pkg.oss-cn-shanghai.aliy ...