首页 > 其他分享 >2023牛客暑期多校5 I The Yakumo Family

2023牛客暑期多校5 I The Yakumo Family

时间:2023-07-31 16:34:31浏览次数:36  
标签:le Family int 多校 else Yakumo -- add oplus

题意

Ran feels boring at home and wants to propose a math problem with Yukari and Chen!

So, here's The Yakumo Family Problem:

Given an integer array a, try to calculate the value of the following equation modulo \(998244353\):

\[\sum_{1\le l_1\le r_1<l_2\le r_2<l_3\le r_3\le n}XOR(l_1, r_1)\times XOR(l_2, r_2)\times XOR(l_3, r_3) \]

\(XOR(l,r)\) means \(a_l\oplus a_{l+1}\oplus a_{l+2}\dots\oplus a_r\), and \(\oplus\) means bitwise XOR.

\(3\le n\le 2\times 10^5\), \(0\le a_i\le 10^9\)

题解

拆位统计,用前缀和统计方案数。

比较麻烦的点在于两个log不能过,所以方案数必须带上权值。写的时候必须想清楚。

时间复杂度\(O(n\log a)\)

constexpr int N=2e5+10;
int a[N];
int f[N][2], G[N];
int g[N][2][2], H[N][2];
int h[N][2];

int main(){
	int n=read<int>();
	for(int i=1; i<=n; ++i) read(a[i]);
	for(int s=0; s<=29; ++s){
		if(a[n]>>s&1){
			h[n][0]=0;
			h[n][1]=1;
		}
		else{
			h[n][0]=1;
			h[n][1]=0;
		}
		for(int i=n-1; i>=1; --i){
			if(a[i]>>s&1){
				h[i][0]=h[i+1][1];
				h[i][1]=add(1, h[i+1][0]);
			}
			else{
				h[i][0]=add(1, h[i+1][0]);
				h[i][1]=h[i+1][1];
			}
		}
		for(int i=n; i>=1; --i){
			H[i][0]=add(H[i][0], mul(h[i][0], 1<<s));
			H[i][1]=add(H[i][1], mul(h[i][1], 1<<s));
		}
	}
	for(int i=n-1; i>=1; --i){
		H[i][0]=add(H[i][0], H[i+1][0]);
		H[i][1]=add(H[i][1], H[i+1][1]);
	}
	for(int s=0; s<=29; ++s){
		for(int i=0; i<=1; ++i)for(int j=0; j<=1; ++j) g[n-1][i][j]=0;
		g[n-1][a[n-1]>>s&1][0]=H[n][0];
		g[n-1][a[n-1]>>s&1][1]=H[n][1];
		for(int i=n-2; i>=1; --i){
			if(a[i]>>s&1){
				g[i][0][0]=g[i+1][1][0];
				g[i][0][1]=g[i+1][1][1];
				g[i][1][0]=add(H[i+1][0], g[i+1][0][0]);
				g[i][1][1]=add(H[i+1][1], g[i+1][0][1]);
			}
			else{
				g[i][0][0]=add(H[i+1][0], g[i+1][0][0]);
				g[i][0][1]=add(H[i+1][1], g[i+1][0][1]);
				g[i][1][0]=g[i+1][1][0];
				g[i][1][1]=g[i+1][1][1];
			}
		}
		for(int i=n-1; i>=1; --i)
			G[i]=add(G[i], mul(g[i][1][1], 1<<s));
	}
	for(int i=n-1; i>=1; --i) G[i]=add(G[i], G[i+1]);
	int ans=0;
	for(int s=0; s<=29; ++s){
		if(a[1]>>s&1){
			f[1][0]=0;
			f[1][1]=1;
		}
		else{
			f[1][0]=1;
			f[1][1]=0;
		}
		for(int i=2; i<=n; ++i){
			if(a[i]>>s&1){
				f[i][0]=f[i-1][1];
				f[i][1]=add(1, f[i-1][0]);
			}
			else{
				f[i][0]=add(1, f[i-1][0]);
				f[i][1]=f[i-1][1];
			}
		}
		for(int i=1; i<=n-2; ++i)
			ans=add(ans, mul(mul(f[i][1], 1<<s), G[i+1]));
	}
	printf("%d\n", ans);
	return 0;
}

标签:le,Family,int,多校,else,Yakumo,--,add,oplus
From: https://www.cnblogs.com/autoint/p/17593746.html

相关文章

  • 2023年多校联训NOIP层测试1
    咕~2023年多校联训NOIP层测试1T1luoguP6882[COCI2016-2017#3]Imena50ptsT26ptsT3luoguP7535[COCI2016-2017#4]Kas15ptsT410pts......
  • 2023牛客暑期多校训练营4
    A.BoboStringConstruction题意:给出一个01字符串t,要求构造一个长为n的01字符串s,使得新的字符串t+s+t不会有超过两个子串tSolution答案要么全0串要么全1串带进去看看成不成立就行了voidsolve(){ intn;cin>>n; strings0(n,'0'); strings1(n,'1'); stringt;cin>>t; ......
  • 牛客多校第三场-D-Ama no Jaku
    D-AmanoJaku_2023牛客暑期多校训练营3做法:2-sat先贴个代码,晚点补上思路#include<bits/stdc++.h>usingnamespacestd;#defineendl"\n"typedeflonglongll;constintN=2e3+5;chara[N][N];std::vector<int>edge[N];//bel数组记录某个点在哪个连通块里面int......
  • 2023暑假杭电多校做题记录
    杭电0101原本以为单组询问要O(log)做,想了很久不会。发现数据范围是3000,于是直接暴力枚举相遇的点,excrt解两个同余方程即可,通过预处理可以做到\(O(nm+mlog)\)然后确实有加强版的题目CF500G大概可以转化成区间余数最小的问题,但是没研究明白,sad杭电0208线段树维护矩阵板题,比......
  • 牛客暑假多校 2023 第四场
    目录写在前面ALFJH写在最后写在前面比赛地址:https://ac.nowcoder.com/acm/contest/57358。那时,天下人的口音,言语,都是一样。他们往东边迁移的时候,在示拿地遇见一片平原,就住在那里。他们彼此商量说,来吧,我们要作砖,把砖烧透了。他们就拿砖当石头,又拿石漆当灰泥。他们说,来吧,我......
  • 【题解】[2023牛客多校] Qu'est-ce Que C'est?
    题目传送门:[2023牛客多校]Qu'est-ceQueC'est?题意给定\(n,m\)构造\(a_{1},a_{2},...,a_{n}\),其中\(a_{i}\in[-m,m]\)之间取值。需要保证序列任意连续子段和都非负。\(0\leqn,m\leq5000\)分析记录合法序列的最小后缀。通过最小后缀来判断下一个数的取值范围。......
  • 暑假牛客多校第四场 2023-7-28
    未补完L.WearetheLights算法:反向构造做法:  我们用c_on,r_on,c_off,r_off分别表示倒着推的行灯打开的集合、列灯打开的集合、列灯关闭的集合、行灯关闭的集合。倒着推时,我们先考虑on的情况。为了偷懒,我们就只考虑行的情况,因为列的情况实际上是一样的。  打开......
  • HDU 暑假多校 2023 第四场
    目录写在前面731773237314732173227318写在最后写在前面补题地址:https://acm.hdu.edu.cn/listproblem.php?vol=64,题号7312~7323。我是飞舞。小子们哪,你们要自守,远避偶像。Dearchildren,keepyourselvesfromidols.——约翰一书以下按照个人向难度排序。7317签到,特......
  • HDU 暑假多校 2023 第三场
    目录写在前面731073047311写在最后写在前面补题地址:https://acm.hdu.edu.cn/listproblem.php?vol=64,题号7300~7311。坐牢场。老东西怎么还在圈里混啊(恼以下按个人向难度排序,标题为题库中题号。7310模拟这个过程。缩放至\(Z\%\)即将原来的某个像素覆盖的范围\((x-1,y-1......
  • 杭电多校2023 第三场
    1005直接dp即可#include<bits/stdc++.h>usingnamespacestd;intdp[5005][5005];intN;inta[5005];constintMOD=1e9+7;intmain(){intT;cin>>T;while(T--){intN;memset(dp,0,sizeof(dp));dp[1][1]=......