Skip to content

Commit

Permalink
add knowledge
Browse files Browse the repository at this point in the history
  • Loading branch information
devilran6 committed Oct 5, 2023
1 parent f47fb63 commit 8a34f1a
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 20 deletions.
7 changes: 7 additions & 0 deletions docs/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#F59F83",
"titleBar.activeBackground": "#F8BAA6",
"titleBar.activeForeground": "#310F04"
}
}
46 changes: 27 additions & 19 deletions docs/ACM/CF/edu_155.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
---
title: CFedu_155
description: (ABCDEF)
categories:
- CF
highlight_shrink: false
abbrlink: d7783771
date: 2023-09-24 00:00:00
mathjax: true
copyright_author: devilran
copyright_author_href:
copyright_url:
copyright_info:
---

{% note info flat %}Code Reference:jiangly {% endnote %}

{% note success flat %}赛时过了ABC。 D题是经典题,循环里没有清零导致赛后才a{% endnote %}
# CFedu_155

[比赛链接](https://codeforces.com/contest/1879)

!!! warning "Code Reference"
Reference:jiangly

!!! abstract
赛时过了ABC。 D题是经典题,循环里没有清零导致赛后才a


## A. Rigged!

**题目:**

举重 每个人有一个可以举起来的重量值s和次数e

问使得第一个人赢,比赛的重量设置为多少?不行输出 -1
s

**思路:**

最优:按照第一个人的重量即可,看能否成立

**code**

```cpp
#include <bits/stdc++.h>

Expand Down Expand Up @@ -81,6 +76,8 @@ int main()
```
## B. Chips on the Board

**题目:**

现在有一个 n * n 的方格, 我需要从中选取一些方格,使得对于每一个方格,它所在的行或者列都至少有一个方格被选了

每一行或者每一列都有一个代价,选一个方格将加上这一行的代价和这一列的代价值
Expand All @@ -95,6 +92,8 @@ int main()

选两个中更小的

**code**

```cpp
#include <bits/stdc++.h>

Expand Down Expand Up @@ -159,6 +158,8 @@ int main()

## C. Make it Alternating

**题目:**

有一个01串,需要经过多次删除操作,使得最后相邻的都不一样

求操作次数,以及操作方案数(每次删除两个不同位置的数算做不同方案)
Expand All @@ -169,6 +170,8 @@ int main()

操作方案:要删的数,直接是阶乘,因为顺序随便。保留的数,是每段的长度,选出来一个。这些乘起来就好

**code**

```cpp
#include <bits/stdc++.h>

Expand Down Expand Up @@ -234,6 +237,8 @@ int main()

## D. Sum of XOR Functions

**题目:**

给你一个长度为 $n$ 的数组 $a$ ,由非负整数组成。

您必须计算 $\sum_{l=1}^{n} \sum_{r=l}^{n} f(l, r) \cdot (r - l + 1)$ 的值,其中 $f(l, r)$ 是 $a_l \oplus a_{l+1} \oplus \dots \oplus a_{r-1} \oplus a_r$(字符 $\oplus$ 表示位向 XOR)。
Expand All @@ -258,6 +263,8 @@ int main()

计算的是 a+1~b 这一段 长度是 b-a

**code**

```cpp
#include <bits/stdc++.h>

Expand All @@ -279,6 +286,7 @@ LL s1[30][2], s2[30][2];
// s1[j][!x] 存储了到目前为止,第 j 位为 !x(即与 x 相反)的前缀异或和的个数
// s2[j][!x] 存储了到目前为止,第 j 位为 !x 的前缀异或和的下标之和


int main()
{
ios::sync_with_stdio(false);
Expand Down
87 changes: 87 additions & 0 deletions docs/ACM/Knowledge/Math/其他/xor.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,91 @@ int main()

return 0;
}
```


## CF1879D Sum of XOR Functions

[题目链接](https://codeforces.com/contest/1879/problem/D)

**题目:**

给你一个长度为 $n$ 的数组 $a$ ,由非负整数组成。

您必须计算 $\sum_{l=1}^{n} \sum_{r=l}^{n} f(l, r) \cdot (r - l + 1)$ 的值,其中 $f(l, r)$ 是 $a_l \oplus a_{l+1} \oplus \dots \oplus a_{r-1} \oplus a_r$(字符 $\oplus$ 表示位向 XOR)。

由于答案可能非常大,因此请打印它的模数 $998244353$。

**思路:**

经典题

`拆位`

之后存下来

!x(即与 x 相反)的前缀异或和的个数

!x 的前缀异或和的下标之和

因为只有是 !x 这样 这一段 的异或是 x ^ !x = 1 才有贡献

同时注意 因为是前缀异或和 所以 s[a] ^ s[b] 的时候

计算的是 a+1~b 这一段 长度是 b-a

**code**

```cpp
#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define x first
#define y second
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 0x3f3f3f3f;
const LL mod = 998244353;

LL s1[30][2], s2[30][2];
// s1[j][!x] 存储了到目前为止,第 j 位为 !x(即与 x 相反)的前缀异或和的个数
// s2[j][!x] 存储了到目前为止,第 j 位为 !x 的前缀异或和的下标之和


int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);

int n;
cin >> n;

vector<int> s(n + 1);
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
s[i + 1] = s[i] ^ a;
}

LL ans = 0;
for (int i = 0; i <= n; i++)
for (int j = 0; j < 30; j++)
{
int x = (s[i] >> j) & 1;
ans = (ans + (i * s1[j][!x] - s2[j][!x]) % mod * (1 << j) % mod) % mod;
s1[j][x] = (s1[j][x] + 1) % mod;
s2[j][x] = (s2[j][x] + i) % mod;
}

cout << ans << endl;

return 0;
}
```
8 changes: 7 additions & 1 deletion docs/about/devilran.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ https://wdxtub.com/

https://blog.tonycrane.cc/

https://note.tonycrane.cc/
https://note.tonycrane.cc/

论文网站

https://arxiv.org/

https://paperswithcode.com/

0 comments on commit 8a34f1a

Please sign in to comment.