首页 > 其他分享 >[CF251D] Two Sets

[CF251D] Two Sets

时间:2023-10-25 22:44:18浏览次数:38  
标签:const int Two long Sets CF251D include define

Two Sets
因为和最大,从高位向低位考虑,称 n 个元素的异或和为 SUM,若 SUM 这一位为0,则两堆都分配1一定更优,否则为了第一堆尽量小我们把偶数个1分给第一堆,高斯消元即可,因为是01矩阵用 bitset 优化一下。
其实因为我们是动态列出等式所以处理过程与线性基类似。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<bitset>
using namespace std;
#define db double
#define ll long long
#define ull unsigned long long
#define ld long double
#define b1t bitset
const int Mod=998244353;
const int MAXN=1e5+5;
const int UP=62;
void read(int &x){
	x=0;int f=1;char s=getchar();
	while(s<'0'||s>'9'){
		if(s=='-') f=-1;s=getchar();
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);s=getchar();
	}
	x*=f;
}
int n,wz[UP],res[MAXN],cnt;
ll a[MAXN],sum;
b1t<MAXN> b[UP];
int main(){
	scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%lld",&a[i]),sum^=a[i];
	for(int op=0;op<2;op++){
		for(int i=62;i>=0;i--){
			if(((sum>>i)&1)==op){
				cnt++;b[cnt][n+1]=op^1;
				for(int j=1;j<=n;j++){
					if((a[j]>>i)&1) b[cnt][j]=1;
				}
				for(int j=1;j<cnt;j++){
					if(b[cnt][wz[j]]) b[cnt]^=b[j];
				}
				for(int j=1;j<=n;j++){
					if(b[cnt][j]){
						wz[cnt]=j;break;
					}
				}
				if(!wz[cnt]){
					cnt--;continue;
				}
				for(int j=1;j<cnt;j++){
					if(b[j][wz[cnt]]) b[j]^=b[cnt];
				}
			}
		}
	}
	for(int i=1;i<=cnt;i++) res[wz[i]]=b[i][n+1];
	for(int i=1;i<=n;i++) printf("%d ",2-res[i]);
	return 0;
}

标签:const,int,Two,long,Sets,CF251D,include,define
From: https://www.cnblogs.com/StranGePants/p/17788303.html

相关文章

  • Leecode 1. 两数之和 Two Sum
    给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。你可以按任意顺序返回答案。示例1:输入:nums=[2,7,11......
  • How To Use Traceroute and MTR to Diagnose Network Issues
    copyfrom: https://www.digitalocean.com/community/tutorials/how-to-use-traceroute-and-mtr-to-diagnose-network-issuesIntroductionAnimportantpartofadministeringserversismonitoringnetworkconnectivity.Thereareafewtoolsthataresimpletouse,......
  • GraphPrompt: Unifying Pre-Training and Downstream Tasks for Graph Neural Network
    目录概符号说明GraphPrompt代码LiuZ.,YuX.,FangY.andZhangX.GraphPrompt:Unifyingpre-traininganddownstreamtasksforgraphneuralnetworks.WWW,2023.概统一的图预训练模型+Prompt微调.符号说明\(G=(V,E)\),图;\(\mathbf{X}\in\mathbb{R}^{|......
  • 2023ACMMM_Mutual Information-driven Triple Interaction Network for Efficient Ima
    一.Motivation之前网络存在的缺点:1.使用的有限的频域信息 2. 不充足的信息交互:(1)第一阶段的输出直接作为第二阶段的输入,忽略了中间特征从早期到后期的传播(2)在编码器解码器结构同尺度之间进行特征融合,忽略了阶段内和跨阶段的跨尺度信息交换3. 严重的特征......
  • GPT-GNN: Generative Pre-Training of Graph Neural Networks
    目录概符号说明GPT-GNN代码HuZ.,DongY.,WangK.,ChangK.andSunY.GPT-GNN:Generativepre-trainingofgraphneuralnetworks.KDD,2020.概比较早的一篇图预训练模型.符号说明\(G=(\mathcal{V},\mathcal{E},\mathcal{X})\),某个图,其中\(\mathcal{X}\)......
  • 2023ICLR_SFNet: Selective frequency network for image restoration
    1.在运行SFNet代码时,前后代码保持不变,运行两次结果发生变化,把下面这段代码注掉就可以保持前后两次运行结果一致,不确定是否是nn.BatchNorm2d计算均值和方差导致classdynamic_filter(nn.Module):def__init__(self,inchannels,mode,kernel_size=3,stride=1,group=8)......
  • Matching Network算法概述
    什么是MatchingNetwork1.论文地址:MatchingNetworksforOneShotLearning2.简介:基于MetricLearning部分思想,使用外部记忆来增强网络,提高网络的学习能力。3.创新点借鉴了注意力和外部记忆方面的经验来搭建网络基于meta-learning用task来训练,而不是metric-learning输入......
  • Linux (7) NetworkManager重置resolve.conf
    《WindowsAzurePlatform系列文章目录》 在默认情况下,AzureLinuxVM会安装waagent,而waagent会依赖于NetworkManager服务。当我们修改了resolve.conf的时候,如果重启NetworkManager或者重启了LinuxVM,NetworkManager会重置resolve.conf。 目前有两个......
  • Networkx 常用
    networkstatisticsprint('*'*30)print('networkstatistics')print(nx.info(G))print(nx.is_connected(G))components=nx.connected_components(G)print('numofconnected_components:',nx.number_connected_components(G))tri......
  • 【论文阅读】DeepAR Probabilistic forecasting with autoregressive recurrent netwo
    原始题目:DeepAR:Probabilisticforecastingwithautoregressiverecurrentnetworks中文翻译:DeepAR:自回归递归网络的概率预测发表时间:2020年07月平台:InternationalJournalofForecasting文章链接:https://www.sciencedirect.com/science/article/pii/S0169207019301888......