首页 > 其他分享 >Anu Has a Function

Anu Has a Function

时间:2024-04-04 11:03:02浏览次数:24  
标签:Function suf int a1 Anu maxn 集合 按位

题目链接

Codeforces Round 618 (Div. 1)

A. Anu Has a Function


思路:

我们把每个二进制位上的 1 1 1 看作是集合的不同的元素,二进制的位运算(按位与,按位或,按位异或)其实可以看作是集合上的与或异或。

这个题 两个集合先或,再完全减去其中一个集合的元素,这正好就相当于两个集合的差集。不妨设 S ( a ) S(a) S(a) 表示 a a a 含有的所有二进制 1 1 1 的集合。而 f ( f ( … f ( f ( a 1 , a 2 ) , a 3 ) , … a n − 1 ) , a n ) f(f(\dots f(f(a_1, a_2), a_3), \dots a_{n-1}), a_n) f(f(…f(f(a1​,a2​),a3​),…an−1​),an​) 这个东西看似复杂,其实就是第一个集合不断减去后面的集合,即 S ( a 1 ) − S ( a 2 ) − S ( a 3 ) − ⋯ − S ( a n ) S(a_1)-S(a_2)-S(a_3)-\dots-S(a_n) S(a1​)−S(a2​)−S(a3​)−⋯−S(an​)。

所以 a 1 a_1 a1​ 为 1 1 1 且 a 2 ∼ n a_{2\sim n} a2∼n​ 为 0 0 0 的二进制位最后才能是 1 1 1,其他位置都会被置为 0 0 0。我们只要枚举这个 “ a 1 a_1 a1​”,然后快速算出其余的数的或的和,就有办法算出结果是多少。算其余的数的或的和可以用前后缀和来预处理。

code:

#include <iostream>
#include <cstdio>
using namespace std;
const int maxn=1e5+5;

int n,a[maxn];
int pre[maxn],suf[maxn];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]|a[i];
	for(int i=n;i>=1;i--)suf[i]=suf[i+1]|a[i];
	
	int idx,ans=-1;
	for(int i=1,x;i<=n;i++){
		x=(((1<<30)-1)^(pre[i-1]|suf[i+1]))&a[i];
		if(x>ans){
			ans=x;
			idx=i;
		}
	}
	cout<<a[idx]<<" ";
	for(int i=1;i<=n;i++)
		if(i!=idx)
			cout<<a[i]<<" ";
	return 0;
}

标签:Function,suf,int,a1,Anu,maxn,集合,按位
From: https://blog.csdn.net/qq_45809243/article/details/137360908

相关文章

  • Lombok常用注解详解: val, @Cleanup, @RequiredArgsConstructor
    From: https://blog.csdn.net/hy6533/article/details/131030094从零开始SpringBoot35:Lombok图源:简书(jianshu.com)Lombok是一个java项目,旨在帮助开发者减少一些“模板代码”。其具体方式是在Java代码生成字节码(class文件)时,根据你添加的相关Lombok注解或类来“自动”添加......
  • Javascript 变量类型 Object 和 Function 讲解
    在JavaScript中,Object 和 Function 是两种非常重要的类型,但它们之间也有一些关键的区别和联系。Object类型在JavaScript中,几乎所有的事物都是对象,包括原始值(如数字和字符串)的包装对象、数组、函数,以及使用字面量语法或构造函数创建的对象实例。对象是一个复合值,它可以包......
  • 【Azure Function & Application Insights】在Azure Function的日志中,发现DrainMode m
    问题描述ApplicaitonInsights收集了AzureFunction的日志,定期发现有”DrainModemodeenabledTraces“。DrainMode是什么意思呢? 问题解答排出模式(Drainmode) 属于FunctionApp 缩放机制中的一部分,当后台检测到FunctionApp请求量不再需要当前的instance时会停止对......
  • vue xxx.find is not a function;
    错误:1.后端获取数据集合,存到 vuex store 中和本地 window.localStorage;2.因为要解决刷新丢失问题在routeconfig中路由拦截重新 拿到本地数据window.localStorage 保存到store中;3.界面刷新报错:vuexxx.findisnotafunction分析:1.xxx类型确实不是数组;......
  • 【Azure Function & Application Insights】调用Function上传和下载文件,有时候遇见大
    问题描述在FunctionApp中配置了无代码模式的ApplicationInsights,但有时候发现,超过1MB的文件上传/下载操作成功。但是在ApplicationInsights中,却没有发现请求日志?这是一种什么情况呢? 问题解答ApplicationInsights 是具有采样功能的,当传入执行的速率超过指定的阈值时,Appl......
  • 当你遇到layer.alert is not a function怎么办
    下面我们来解决layer.alertisnotafunction的方法之一,下面来看一个GIS的例子,在登录之后,地图是加载出来的,当你点击区域定位是出现layer.alertisnotafunction。而我们的代码是没有bug,但是它还是报错。那是因为我们的url的地图出问题了,这是因为切图后的数据没有我们要的数......
  • std::function
    std::functional 是C++标准库中的一个模板类,它是对可调用对象的一种通用包装器。std::functional 允许你将任何可调用对象(包括函数、函数对象、lambda表达式、以及其他 std::functional 对象)当作一个统一的对象来处理。它通常与C++的算法库、容器库以及某些需要可调用对......
  • vuex.esm.js:135 Uncaught Error: [vuex] getters should be function but “getters.
    报错vuex.esm.js:135UncaughtError:[vuex]gettersshouldbefunctionbut"getters.mode"inmodule"userModule"is"dark".atassert(vuex.esm.js:135:1)原因:在使用vuex的moulds时index.js中已创建了一个vue实例newVuex.Store,在模块文件中又再创建了一个,导致报......
  • 【平台开发】MTK6833——add harware command queue function in lk
    CQE实现主要步骤(参考协议)Hostsystem结构commandqueue任务结构:2.TheoryofOperation(操作理论)init(初始化)初始化,enableCQ配置CQCFGTaskDescriptorsize配置CQTDLBA(CommandQueuingTaskDescriptorListBaseAddress)和CQTDLBAU(CommandQueuingTaskDe......
  • How to use the smb function of Babyfile App (connect Mac computer)
    1.Mac computer "SystemSettings"->"General"->"Sharing" reachthepagebelow(ordirectlysearchfor"FileSharing"onthesystemsettingspagetoreachthepage).Thenclickthebuttonshownin①2.Then......