From 8a34f1a4789eca46d52f35767a15cbef5e587a1f Mon Sep 17 00:00:00 2001 From: devilran6 <3470826156@qq.com> Date: Fri, 6 Oct 2023 02:11:24 +0800 Subject: [PATCH] add knowledge --- docs/.vscode/settings.json | 7 ++ docs/ACM/CF/edu_155.md | 46 ++++++---- .../Math/\345\205\266\344\273\226/xor.md" | 87 +++++++++++++++++++ docs/about/devilran.md | 8 +- 4 files changed, 128 insertions(+), 20 deletions(-) create mode 100644 docs/.vscode/settings.json diff --git a/docs/.vscode/settings.json b/docs/.vscode/settings.json new file mode 100644 index 0000000..5c3ecd1 --- /dev/null +++ b/docs/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "workbench.colorCustomizations": { + "activityBar.background": "#F59F83", + "titleBar.activeBackground": "#F8BAA6", + "titleBar.activeForeground": "#310F04" + } +} \ No newline at end of file diff --git a/docs/ACM/CF/edu_155.md b/docs/ACM/CF/edu_155.md index 3d4870c..e2636ac 100644 --- a/docs/ACM/CF/edu_155.md +++ b/docs/ACM/CF/edu_155.md @@ -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 @@ -81,6 +76,8 @@ int main() ``` ## B. Chips on the Board +**题目:** + 现在有一个 n * n 的方格, 我需要从中选取一些方格,使得对于每一个方格,它所在的行或者列都至少有一个方格被选了 每一行或者每一列都有一个代价,选一个方格将加上这一行的代价和这一列的代价值 @@ -95,6 +92,8 @@ int main() 选两个中更小的 +**code** + ```cpp #include @@ -159,6 +158,8 @@ int main() ## C. Make it Alternating +**题目:** + 有一个01串,需要经过多次删除操作,使得最后相邻的都不一样 求操作次数,以及操作方案数(每次删除两个不同位置的数算做不同方案) @@ -169,6 +170,8 @@ int main() 操作方案:要删的数,直接是阶乘,因为顺序随便。保留的数,是每段的长度,选出来一个。这些乘起来就好 +**code** + ```cpp #include @@ -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)。 @@ -258,6 +263,8 @@ int main() 计算的是 a+1~b 这一段 长度是 b-a +**code** + ```cpp #include @@ -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); diff --git "a/docs/ACM/Knowledge/Math/\345\205\266\344\273\226/xor.md" "b/docs/ACM/Knowledge/Math/\345\205\266\344\273\226/xor.md" index 59596c3..a84eadc 100644 --- "a/docs/ACM/Knowledge/Math/\345\205\266\344\273\226/xor.md" +++ "b/docs/ACM/Knowledge/Math/\345\205\266\344\273\226/xor.md" @@ -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 + +#define LL long long +#define ULL unsigned long long +#define x first +#define y second +#define endl "\n" + +using namespace std; + +typedef pair PII; +typedef pair 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 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; +} ``` \ No newline at end of file diff --git a/docs/about/devilran.md b/docs/about/devilran.md index 0a6e773..42190e8 100644 --- a/docs/about/devilran.md +++ b/docs/about/devilran.md @@ -6,4 +6,10 @@ https://wdxtub.com/ https://blog.tonycrane.cc/ -https://note.tonycrane.cc/ \ No newline at end of file +https://note.tonycrane.cc/ + +论文网站 + +https://arxiv.org/ + +https://paperswithcode.com/ \ No newline at end of file