---
id: 1664
lang: en
translation_of: index.md
source_sha256: f8632a0a3fe529478efcdcaaa97f4df66aaad07e403a1f1a6e6588727d125dc0
title: "[2018 Quanzhou National Day Training Camp #1] - Problem-Solving Report"
description: "Notes on three camp problems: a brute force that somehow passes, a per-node trie count for an XOR sum, and a subset count whose answer is 2^(nk)."
tags: ["OI","Trie","Brute Force","Problem-Solving Report","Partial Order"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "国庆集训 rendered as “National Day Training Camp” (a training camp held over China's National Day holiday)."
  - "元素个数就是 2^{nk} kept literally as “the number of elements is 2^{nk}”, although the author presumably means the number of configurations."
  - "非偏序的点 rendered as “non-partially-ordered points”, i.e. points incomparable under the partial order."
---

## A - Gift

<span class="slang" data-zh="sb" data-gloss="Initials of 傻逼 (shǎbī). A vulgar insult, roughly “idiot” or “stupid”.">Stupid</span> <span class="slang" data-zh="暴力出奇迹" data-gloss="bàolì chū qíjì, “brute force produces miracles”. An OI saying for when a naive brute-force solution unexpectedly passes.">brute force works miracles</span>, toying with people's feelings.

So it turns out your <span class="slang" data-zh="特么" data-gloss="tème, a euphemistic spelling of 他妈 (tāmā), “his mother”. A mild curse, like “damn” or “freaking”.">damn</span> $1e9$ complexity passes too? I'm honestly floored.

<!--more-->

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

using namespace std;

const int MAX_N = 1010;

int prefix[MAX_N][MAX_N], suffix[MAX_N][MAX_N];
int n, ai[MAX_N], bi[MAX_N], ci[MAX_N], m;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d%d%d", &ai[i], &bi[i], &ci[i]);
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < MAX_N; j++)
        {
            prefix[i][j] = prefix[i - 1][j];
            if (j >= ai[i])
                prefix[i][j] = max(prefix[i][j], prefix[i - 1][j - ai[i]] + bi[i]);
        }
    for (int i = n; i >= 1; i--)
        for (int j = 0; j < MAX_N; j++)
        {
            suffix[i][j] = suffix[i + 1][j];
            if (j >= ai[i])
                suffix[i][j] = max(suffix[i][j], suffix[i + 1][j - ai[i]] + bi[i]);
        }
    scanf("%d", &m);
    while (m--)
    {
        int del, money;
        scanf("%d%d", &del, &money), del++;
        int ans = 0;
        for (int i = 0; i <= money; i++)
            ans = max(ans, prefix[del - 1][i] + suffix[del + 1][money - i]);
        printf("%d\n", ans);
    }
    return 0;
}
```

## B - XOR

This problem is way too <span class="slang" data-zh="特么" data-gloss="tème, a euphemistic spelling of 他妈 (tāmā), “his mother”. A mild curse, like “damn” or “freaking”.">damn</span> <span class="slang" data-zh="傻逼" data-gloss="shǎbī. A vulgar insult, roughly “idiot” or “stupid”.">stupid</span>.

Consider that a bit can contribute to the answer if and only if all the bits before it are equal. On a trie, any node guarantees that the prefixes are equal, so the contribution of each node is $2^{len} \times son_0 \times son_1$.

```cpp
// B.cpp
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAX_N = 1e5 + 200;
const ll mod = 199907210507;

struct node
{
    int ch[2];
    ll val;
} nodes[MAX_N * 70];

ll ptot = 1, n, arr[MAX_N], ans, pow2[70];

void insert(ll x)
{
    int p = 1;
    for (int i = 0; i <= 62; i++)
    {
        int bit = (x >> i) & 1;
        if (nodes[p].ch[bit] == 0)
            nodes[p].ch[bit] = ++ptot;
        nodes[p].val++, p = nodes[p].ch[bit];
    }
}

void dfs(int u, int cnt)
{
    if (u == 0)
        return;
    (ans += 1LL * nodes[nodes[u].ch[0]].val * nodes[nodes[u].ch[1]].val % mod * pow2[cnt]) %= mod;
    dfs(nodes[u].ch[0], cnt + 1), dfs(nodes[u].ch[1], cnt + 1);
}

int main()
{
    scanf("%lld", &n);
    for (int i = pow2[0] = 1; i < 70; i++)
        pow2[i] = 1LL * pow2[i - 1] * 2 % mod;
    for (int i = 1; i <= n; i++)
        scanf("%lld", &arr[i]), insert(arr[i]);
    dfs(1, 0), printf("%lld", 1LL * ans * 2 % mod);
    return 0;
}
```

## C - Subsets

A really intriguing problem.

The answer is $2^{n \times k}$. I thought for a long time about a reason to explain this answer, and thanks as well to XG_Zepto and CrazyDave for their thinking. We can see that choosing a monotone (non-partially-ordered) set of points, and filling numbers into such sets, is enough to determine the whole configuration.

By “non-partially-ordered points” we mean points related the way the two B points in the diagram are:

```text
A
^
|
A <- A
^    ^
|    |
A <- A <- B
^    ^    ^
|    |    |
A <- B <- A <- A
```

Define such a point as the earliest point where some element exists; putting an element into such a point makes the whole upstream region covered by that element. Consider that there are $2^k$ such point sets (that is, the number of subsets of the set made up of “non-partially-ordered points”), and then each element is put into one of the sets, so the number of elements is $2^{nk}$.

Roughly like this; I still need to think it over some more.

A proof that the number of subsets of the set made up of “non-partially-ordered points” is $2^k$, from XG_Zepto:

> Let $f(k)$ be the number of non-partially-ordered point sets from row $k$ upward. Considering that row $k$ includes all the earlier cases, $f(k) = 2 + \sum_{i = 1}^{k - 1} f(i)$, and this $2$ stands for the exclusive cases.

That's about it.

```cpp
// C.cpp
#include <bits/stdc++.h>
#define ll unsigned long long

using namespace std;

const ll mod = 7528443412579576937;

ll quick_mul(ll x, ll y)
{
    ll res = 0;
    if (x < y)
        swap(x, y);
    while (y)
    {
        if (y & 1LL)
            res = (res + x < mod) ? (res + x) : (res + x - mod);
        x = (x + x < mod) ? (x + x) : (x + x - mod);
        y >>= 1LL;
    }
    return res;
}

ll quick_pow(ll bas, ll tim)
{
    ll ans = 1;
    while (tim)
    {
        if (tim & 1LL)
            ans = quick_mul(ans, bas);
        bas = quick_mul(bas, bas);
        tim >>= 1LL;
    }
    return ans;
}

int main()
{
    ll n, k;
    scanf("%lld%lld", &n, &k), printf("%lld", quick_pow(2, 1LL * n * k));
    return 0;
}
```
