代码源考试总结(全集)

· · 个人记录

暑假集训模拟赛 day1 (7.28)

前言

震惊,今天居然没有怎么挂分,太爽了👍

比赛基本情况

比赛日期 2026.7.28,比赛时常 8:00-12:30

预计分数:100+[70-100]+0+0+[25-45]

实际分数:100+70+0+0+45

代码源总榜排名:rk50/292

学校排名:rk12/37

比赛整体回顾

:::info[具体做题时间]

:::

整体感想:今天的比赛状态还不错🙂,但是时间还是感觉不够⌚,时间安排有待加强,整体感受良好。我认为这次题目难度还是蛮高的,整体质量还可以。

题目复盘

A. 蜗蜗的魔法序列

我一开始注意到了 n 为 2 的幂😮,想到二进制,便往位的方向去想,接着我们可以发现他只会做第二种操作一遍,因为是整体操作,两次操作可以合并🧐。

为了保证数列递增,我们可以很容易想到从高位往低位去做操作,每一次操作保证前几位是有大到下的,然后操作过程中我们直接通过排序找到变后的式子即可😎。

注意又因为我们要求最小所以我们每一次排序都要以之前的位置为第二号关键字。又第二次操作只会改变一位,所以前后相互独立。这题就完成了🎉。

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 3e5 + 5;

struct pp{
    int id, x;
} arr[MAXX];

bool cmp(pp a, pp b){
    if(a.x != b.x) return a.x < b.x;
    return a.id < b.id;
}

int n, cnt, a[MAXX], id1[MAXX], id2[MAXX], sum1, sum2, ans, num[MAXX], flag = 1, tmp1, tmp2, h1[MAXX], h2[MAXX];

signed main(){
    cin >> n;
    int h = n;
    while(h != 1) h /= 2, cnt++;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int k = cnt; k >= 1; k--){
        sum1 = 0, sum2 = flag, tmp1 = 0, tmp2 = 0;
        for(int i = 1; i <= n; i++) arr[i].x = num[i] = num[i] * 2 + (bool)((1 << (k - 1)) & a[i]), arr[i].id = i;
        sort(arr + 1, arr + 1 + n, cmp);
        for(int i = 1; i <= n; i++) id1[arr[i].id] = i;
        for(int i = 1; i <= n; i++) tmp1 += abs(i - id1[i]);
        for(int i = 1; i <= n; i++) arr[i].x = num[i] ^ 1, arr[i].id = i;
        sort(arr + 1, arr + 1 + n, cmp);
        for(int i = 1; i <= n; i++) id2[arr[i].id] = i;
        for(int i = 1; i <= n; i++) tmp2 += abs(i - id2[i]);
        sum1 += tmp1 / 2, sum2 += tmp2 / 2;
        ans += min(sum1, sum2);
        if(sum1 <= sum2){
            for(int i = 1; i <= n; i++) h1[id1[i]] = a[i], h2[id1[i]] = num[i];
            for(int i = 1; i <= n; i++) a[i] = h1[i], num[i] = h2[i];
        }else{
            flag = 0;
            for(int i = 1; i <= n; i++) h1[id2[i]] = a[i], h2[id2[i]] = num[i];
            for(int i = 1; i <= n; i++) a[i] = h1[i], num[i] = h2[i];
            for(int i = 1; i <= n; i++) num[i] ^= 1;
        }
    }
    cout << ans << '\n';
    return 0;
}

:::

时间复杂度是 O(nlog_n^2)

B. 蜗蜗的灵脉地图

这题居然是诈骗结论题,太可恶了😡

我一开始拿到这个题没有一点想法,直接构造根本构造不出来😞。我们可以发现如果两个点 a_{ij} 等于1,那么我们把这两个点连起来,如果这个地图是正确的那么组成的图也是合法的😶。那么我们就要判断其是不是无解。

但是我没有很好的想法,于是就暴力跑最短路使得最短路与二维数组的奇偶性一样。但是因为有可能是稠密图,最大时间复杂度可能达到 O(n(n+m)) = O(n^3)

:::info[考场代码]

#include<bits/stdc++.h>
#define PLL pair<int,int>


using namespace std;

const int MAXX = 2e3 + 5;

int t, n, vis[MAXX], ans, num[MAXX], dis[MAXX][MAXX], s[MAXX];
char a[MAXX][MAXX];
vector<int> e[MAXX];

void dfs(int x){
    if(vis[x]) return;
    vis[x] = 1;
    for(int i = 0; i < e[x].size(); i++) dfs(e[x][i]);
}

void P(int x){
    for(int i = 1; i <= n; i++) dis[x][i] = n + 1;
    for(int i = 1; i <= n; i++) s[i] = 0;
    dis[x][x] = 0;
    priority_queue<PLL, vector<PLL>, greater<PLL> > q;
    q.push({0, x});
    while(q.size()){
        int r1 = q.top().first, r2 = q.top().second;
        q.pop();
        if(s[r2]){
            continue;
        }
        s[r2] = 1;
        for(int i = 0; i < e[r2].size(); i++){
            int w = e[r2][i], h = 1;
            if(h + r1 < dis[x][w]){
                dis[x][w] = h + r1;
                q.push({dis[x][w], w});
            }
        }
    }
}

void solve(){ 
    cin >> n;
    bool xyz = 1;
    for(int i = 1; i <= n; i++) e[i].clear(), vis[i] = 0; ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin >> a[i][j];
            if(i != j && a[i][j] == '0') xyz = 0;
            if(a[i][j] == '1' && i < j) e[i].push_back(j), e[j].push_back(i), ans++;
        }
    }
    for(int i = 1; i <= n; i++) if(a[i][i] == '1'){ cout << "NO" << '\n'; return; }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(a[i][j] != a[j][i]){
                cout << "NO" << '\n';
                return;
            }
        }
    }
    dfs(1);
    bool flag = 1;
    for(int i = 1; i <= n; i++) if(!vis[i]) flag = 0;
    if(!flag){
        cout << "NO" << '\n';
        return;
    }
    if(!xyz){
        for(int i = 1; i <= n; i++) P(i);
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                if(dis[i][j] % 2 != a[i][j] % 2){
                    cout << "NO" << '\n';
                    return;
                } 
            } 
        }       
    }
    //cout << xyz << '\n';
    cout << "YES" << '\n' << ans << '\n';
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(a[i][j] == '1' && i < j) cout << i << " " << j << '\n';
        }
    }
}

signed main(){
    cin >> t;
    while(t--) solve();
}

:::

因为我们是这么构造,如果距离奇数的点会被连线,所以任意两个点的距离不会超过二,因为对于4个点的链,他的头和尾的距离也是奇数,所以他们也必须连接🤔。那么我们就可以知道了对于任意 a_{ij} = 0 的时候一定有一个公共的邻点 k 满足 a_{ik} = a_{jk} = 1 所以其的奇偶性是与原数组一样的,所以也是出现第一个结论的证明🙃。

那么,我们就可以用bitset解决,但是我不会用🤬。

C. 魔法材料整理

考试时来不及看了🙄

D. 星际跃迁

考试时来不及看了🙄

E. 逆序对

这道题我一开始就是往DP的方向思考的,但是没想出来😐。因为暴力简单,所以我便开始打暴力,由于暴力分太低所以开始想优化,首先 n 很小我想了折半,可是逆序对与两边选的数有关。

于是我便开始想剪纸,如果现在的逆序对数比它能达到最大长度的暂时最小逆序对还要小,那么其肯定是不合法的,直接return。

if(num > minn[n - (n - x - sum)]) return;

就是这点睛之笔使得又多了20分😮,为了使得暂时最小值越小,又数据随机,所以我用rand来抉择dfs顺序,但是没有啥用😛。

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 1e2;

int n, a[MAXX], minn[MAXX * MAXX], ans[MAXX * MAXX], zrr[MAXX], b[MAXX];

int L(int x){
    return x & (-x);
}

void add(int x, int w){
    for(int i = x; i < MAXX; i += L(i)){
        zrr[i] += w;
    }
}

int answer(int x){
    int ans = 0;
    for(int i = x; i >= 1; i -= L(i)){
        ans += zrr[i];
    }
    return ans;
}

void dfs(int x, int sum, int num){
    if(num > minn[n - (n - x - sum)]){
        return;
    }
    if(x == 0){
        if(minn[sum] > num) minn[sum] = num, ans[sum] = 1;
        else if(minn[sum] == num) ans[sum]++;
        return;
    }
    if(rand() % 2){
        int tmp = answer(a[x] - 1); add(a[x], 1);
        dfs(x - 1, sum + 1, num + tmp);
        add(a[x], -1), dfs(x - 1, sum, num);        
    }else{
        dfs(x - 1, sum, num);
        int tmp = answer(a[x] - 1); add(a[x], 1);
        dfs(x - 1, sum + 1, num + tmp);
        add(a[x], -1);
    }

}

signed main(){
    srand(time(0));
    cin >> n;
    memset(minn, 0x3f, sizeof minn);
    for(int i = 1; i <= n; i++) cin >> a[i];
    dfs(n, 0, 0);
    for(int i = 1; i <= n; i++){
        cout << minn[i] << " " << ans[i] << '\n';
    }
    return 0;
}

:::

整体反思

这场比赛我的代码正确率比较高😁,其次这次比赛状态还可以。但是时间安排与代码暴力能力上还有很多进步空间🤡。

暑假集训模拟赛 day2 (7.31)

前言

死磕T2没有写出来😡,变成祝睿融了🐽,也是被别人暴打了好吧😭!

比赛基本情况

比赛日期 2026.7.31,比赛时常 8:00-12:30

预计分数:100+20+0+10+0

实际分数:100+40+0+10+0

代码源总榜排名:rk119/292

学校排名:rk19/37

比赛整体回顾

:::info[具体做题时间]

:::

整体感想:今天也是孬爆了,B题都没写出来😤,整体题目难度比上次简单一点但是由于时间分配没有太多时间思考了😒。个人能力还是需要加强🐱‍🏍。

题目复盘

A. 项目分组

第一题也是非常的简单好吧,也是一眼就想到了解法🤪。我们可以先思考不合理的情况:

那么前面两个可以直接用枚举质数解决,那么第二个我们可以用给图染色解决😮。

又因为对于每个质数,他最多有两个倍数才合法,那么边的数量是完全不会超的🤤,那么我们找倍数又是一个 log 时间复杂度的,t 又很小完全可以做好吧😛!

:::info[考场代码]

#include<bits/stdc++.h>

using namespace std;

const int MAXX = 2e6 + 5, INF = 2e6 + 1;

int n, sum[MAXX], a[MAXX], sum1, sum0, vis[MAXX], flag, t, cnt, prime[MAXX], num[MAXX];
vector<int> e[MAXX], G[MAXX], zrr1, zrr0, ans, xyz;

void init(){
    for(int i = 1; i <= n; i++) sum[a[i]]--, e[a[i]].clear();
    for(int i = 1; i <= n; i++) G[i].clear();
}

void dfs(int x, int col){
    if(flag) return;
    vis[x] = col;
    if(col) sum1++, zrr1.push_back(x);
    else sum0++, zrr0.push_back(x);
    for(int i = 0; i < G[x].size(); i++){
        int y = G[x][i];
        if(vis[y] == -1) dfs(y, 1 - col);
        if(vis[y] == vis[x]){
            flag = 1; return;
        }
    }
}

void solve(){
    cin >> n; ans.clear();
    for(int i = 1; i <= n; i++) vis[i] = -1;
    for(int i = 1; i <= n; i++) cin >> a[i], sum[a[i]]++, e[a[i]].push_back(i);
    for(int i = 1; i <= n; i++){
        if(sum[a[i]] > 2){
            cout << -1 << '\n'; init(); return;
        }
    }
    for(int i = 1; i <= cnt; i++){
        int tmp = prime[i]; xyz.clear();
        for(int j = tmp; j <= INF; j += tmp){
            for(int k = 0; k < e[j].size(); k++) xyz.push_back(e[j][k]);
        }
        for(int j = 0; j < xyz.size(); j++){
            for(int k = 0; k < xyz.size(); k++){
                if(j != k) G[xyz[j]].push_back(xyz[k]);
            }
        }
        if(xyz.size() > 2){
            cout << -1 << '\n'; init(); return;
        }
    }
    for(int i = 1; i <= n; i++){
        if(vis[i] == -1){
            zrr0.clear(), zrr1.clear(), flag = sum0 = sum1 = 0; dfs(i, 0);
            sort(zrr0.begin(), zrr0.end()), sort(zrr1.begin(), zrr1.end());
            if(flag){
                cout << -1 << '\n'; init(); return;
            }
            if(sum0 < sum1 || (sum1 == sum0 && zrr1[0] < zrr0[0])) for(int j = 0; j < zrr1.size(); j++) ans.push_back(zrr1[j]);
            else if(sum0 > sum1 || (sum1 == sum0 && zrr1[0] > zrr0[0])) for(int j = 0; j < zrr0.size(); j++) ans.push_back(zrr0[j]);
        }
    }
    cout << ans.size() << '\n';
    sort(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
    cout << '\n';
    init();
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    for(int i = 2; i <= INF; i++){
        if(num[i] == 0) prime[++cnt] = i;
        for(int j = i * 2; j <= INF; j += i) num[i] = 1;
    }
    cin >> t;
    while(t--) solve();
    return 0;
} 

:::

B. 信号清晰度分析

考场思路:我发现通过枚举01分界线似乎可以更好的算答案🤔,然后对于01分界点我们找到最左边的点使得其到中点的所有后缀和他的 0 多于 1 的数量,同理找到一个最右的点使得他的前缀和的 1 多于 0 的数量🤨。那么我们就可以用单调栈解决😯。

但是他的答案并不是很好维护,所以没有想好完整代码就开始实践,浪费了很多时间😥。最终只能写一个暴力放上去,居然还有40分😏。

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 1e7 + 5;

int n, a[MAXX], ans, t, num[MAXX];
char ch;

void solve(){
    cin >> n; ans = 0;
    for(int i = 1; i <= n; i++) cin >> ch, a[i] = (ch == '0' ? 0 : 1);
    for(int i = 1; i <= n; i++) num[i] = num[i - 1] + (a[i] == 0);
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j++){
            int maxx = 0;
            for(int k = i - 1; k <= j; k++) maxx = max(maxx, (num[k] - num[i - 1] + (j - k) - (num[j] - num[k])));
            ans += maxx;
        }
    }
    cout << ans << '\n';
}

signed main(){
    cin >> t;
    while(t--) solve();
    return 0;
}

:::

正解思路:DFbd的做法太强了👍!膜拜谭云开。

对于这道题,我们要求总最长上升子序列的长度,又因为只有 0 和 1。所以我们可以考虑每一个点对于序列的贡献,所以我们固定右端点来思考做法😦。

对于一个已选出来的以 1 结尾最长上升子序列,我们如果不把 1 删掉那么我们就只能放 1,如果放 0 的话那么我们就会有代价,代价就为结尾 1 的数量减去可以放的 0 的数量😶。那么我们知道一个重要的性质:如果它将 1 换成 0 的代价为 0 的时候优先换,因为以 0 结尾的序列有更多的空间😏,这就可以保持上升序列最长。

接下来我们通过举例子的方法来思考下一步的做法。对于一个序列 011110001 我们可以试图写出每个左端点对右端点的加贡献。

0 1 1 1 1 0 0 0 1
+1
+1 +1
+1 +1 +1
+1 +1 +1 +1
+1 +1 +1 +1 +1
+0 +1
+0 +1 +1 +1
+0 +1 +1 +1 +1 +1
+1 +1 +1 +1 +1 +1 +1 +1 +1

注释:其中+0是指抵消的值(就是上文代价为 0)。

我们可以发现他的贡献是连续的,我们可以通过反证法来证明。如果不是连续的,又他们的两段贡献的中间就一定有 0。所以不成立😇,虽然这个没有什么用😝。

然后我会学习deekseep将核心代码逐行讲解🐋。

我们维护 end0 只以 0 为结尾的子序列数量。

$end1[i]$ 维护以 $1$ 结尾的数且当前代价为 $i$ 可以替换的子序列数量。 $val$ 只的是现在的需要的代价。 - 对于当前节点为 $0$ 的时候,我们就可以增加一个结尾为 $0$ 的数量,同时 $0$ 可以为所有以 $0$ 结尾的数做一次贡献。同时我们可以将之前为当前代价时存入的数直接拿走,同时更新当前代价。 - 对于当前节点为 $1$ 的时候,我们现在的代价会增加,同时这个 $1$ 会接到所有以 $0$ 结尾的数后面所以我们将其存入当前代价的数组中,为下一次替换做准备。同时更新答案和变量。 核心代码: ```cpp for(int i = 1; i <= n; i++){ cin >> ch; if(ch == '0'){ end0++, num += end0, end0 += end1[val]; end1[val] = 0, val = max(0, val - 1); }else{ end1[++val] += end0 + 1; num += i, end0 = 0; } ans += num; } ``` 是不是很神奇,当然也很绕😵,我是DFbd,太强啦🤯! ### C. 蜗蜗的数字迷宫 考试时来不及看了🙄 ### D. 沙海奥秘 我看这题暴力最好写,写了个暴力便走人了🤩。 :::info[赛事代码] ```cpp #include<bits/stdc++.h> #define int long long using namespace std; const int MAXX = 1e7 + 5; int n, a[MAXX], ans, q; char ch; void solve(){ cin >> n >> q; for(int i = 1; i <= n; i++) cin >> a[i]; int INF = a[(n + 1) / 2]; for(int i = 0; i <= INF; i++){ for(int j = i + 1; j <= INF; j++){ bool flag = 1; for(int k = 1; k <= n / 2; k++){ if(min(j - i, max(0ll, a[k] - i)) != min(j - i, max(0ll, a[n - k + 1] - i))) flag = 0; } ans += flag; } } cout << ans << '\n'; } signed main(){ int t = 1; while(t--) solve(); return 0; } ``` ::: ### E. 排列 考试时来不及看了🙄 ## 整体反思 这场比赛没有挂分,但是还是太菜了,B题没有写出来,哇哇哇哇🤬。个人能力还需增强,暴力能力与时间管理还有很大的进步空间🤫。 # 暑假集训模拟赛 day3 (8.2) ## 前言 妈的,我是傻逼,他妈又唐了🍭。T3那么简单居然没有调出来🤬!又是吃屎的一天🤮。 ## 比赛基本情况 比赛日期 $2026.8.2$,比赛时常 $8:00-12:30

预计分数:100+100+30+0+0

实际分数:100+100+30+0+0

代码源总榜排名:rk81/300

学校排名:rk14/37

比赛整体回顾

:::info[具体做题时间]

:::

整体感想:今天也是唐飞了好吧!还有这B题样例也太水了吧,差评👎!今天的时间又又又又又不够,而且很简单的思路思考时间比较久😔。

题目复盘

A. 蜗蜗的魔法手环

这一道题是一个大分讨题目,我是通过手玩来写的😊。

通过发现我们可以轻松的得出以下结论😋:

:::info[考场代码]

#include<bits/stdc++.h>

using namespace std;

const int MAXX = 1e3 + 5;

string s;
int sum[MAXX], maxx, id, num;
vector<int> e;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> s;
    int n = s.size(); s = ' ' + s;
    for(int i = 1; i <= n; i++) sum[int(s[i] - 'a' + 1)]++;
    for(int i = 1; i <= 26; i++){
        if(maxx < sum[i]) maxx = sum[i], id = i;
        num += (bool)(sum[i]);
    }
    if(num == 1){
        cout << "NO"; return 0;
    }else if(num == 2){
        if(maxx > n / 2){
            if(maxx >= n - 2){
                cout << "NO"; return 0;
            }else{
                cout << "YES" << '\n';
                for(int i = 1; i <= 26; i++){
                    if(i == id) continue;
                    while(sum[i]--) e.push_back(i); 
                }
                for(int i = 1; i <= maxx / 2 - 1; i++) cout << char('a' + id - 1);
                cout << char('a' + e[0] - 1);
                for(int i = maxx / 2; i <= maxx; i++) cout << char('a' + id - 1);
                for(int i = 1; i < e.size(); i++) cout << char('a' + e[i] - 1);
            }
        }else{
            cout << "YES" << '\n';
            for(int i = 1; i <= 26; i++){
                while(sum[i]--) cout << char('a' + i - 1);
            }
        }
    }else{
        cout << "YES" << '\n';
        for(int i = 1; i <= 26; i++){
            if(i == id) continue;
            while(sum[i]--) e.push_back(i); 
        }
        for(int i = 1; i <= maxx / 2; i++) cout << char('a' + id - 1);
        cout << char('a' + e[0] - 1);
        for(int i = maxx / 2 + 1; i <= maxx; i++) cout << char('a' + id - 1);
        for(int i = 1; i < e.size(); i++) cout << char('a' + e[i] - 1);
    }
    return 0;
} 

:::

B. 蜗蜗的舒适旋律

前景提要:我写的错的解法能过大样例,这大样例使用脚趾造的吗🤐!

赛时思考1

因为我们要求对于一个数最左边小于它的数且两数中间有一个数的值在他们两个数构造的值域之内🤔。

所以我想当然了直接求对于一个数第一个小于等于他的数,然后递归两边我就以为这样就行了😶,然后用线段树维护也为维护个错的,但是过了大样例❓。

赛时思考2

因为发现前面的想法错了,被迫换了写法😣。这次我们不直接递归而是枚举其两边的数用单调栈求😕。然后就有了一个正确的区间。那么只需要我们用线段树维护二位偏序即可🙂。

:::info[考场代码]

#include<bits/stdc++.h>


using namespace std;

const int MAXX = 4e5 + 5;

struct pp{
    int op, l, r, id;
} e[MAXX];

int n, q, a[MAXX], l, r, t[MAXX * 4], id1[MAXX], id2[MAXX], arr[MAXX], h[MAXX], cnt, num[MAXX], T, ans[MAXX];

void pushup(int x){
    t[x] = min(t[x * 2], t[x * 2 + 1]);
}

void build(int x, int l, int r){
    if(l == r){
        t[x] = n; return;
    }
    int mid = (l + r) / 2;
    build(x * 2, l, mid), build(x * 2 + 1, mid + 1, r);
    pushup(x);
}

void add(int x, int l, int r, int L, int val){
    if(l > L || r < L) return;
    if(l == r && l == L){
        t[x] = min(t[x], val);
        return;
    }
    int mid = (l + r) / 2;
    add(x * 2, l, mid, L, val);
    add(x * 2 + 1, mid + 1, r, L, val);
    pushup(x);
}

int answer(int x, int l, int r, int L, int R){
    if(l > R || r < L) return n;
    if(L <= l && r <= R) return t[x];
    int mid = (l + r) / 2;
    return min(answer(x * 2, l, mid, L, R), answer(x * 2 + 1, mid + 1, r, L, R));
}

bool cmp(pp a, pp b){
    if(a.r != b.r) return a.r < b.r;
    return a.op < b.op;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> T;
    while(T--){
        cin >> n >> q;
        for(int i = 1; i <= n; i++) cin >> a[i], num[i] = 0;
        cnt = 0;
        for(int i = n; i >= 1; i--){
            while(cnt && a[h[cnt]] >= a[i]) id1[h[cnt]] = i, cnt--;
            h[++cnt] = i;
        }
        while(cnt) id1[h[cnt]] = -1, cnt--;
        cnt = 0;
        for(int i = 1; i <= n; i++){
            while(cnt && a[h[cnt]] <= a[i]) id2[h[cnt]] = i, cnt--;
            h[++cnt] = i;
        }
        while(cnt) id2[h[cnt]] = -1, cnt--;
        for(int i = 1; i <= n; i++){
            if(id1[i] == -1 || id2[i] == -1) continue;
            else e[++cnt] = {0, id1[i], id2[i], 0};
        }
        build(1, 1, n);
        for(int i = 1; i <= q; i++) cin >> l >> r, e[++cnt] = {1, l, r, i};
        sort(e + 1, e + 1 + cnt, cmp);
        for(int i = 1; i <= cnt; i++){
            if(e[i].op == 0) add(1, 1, n, e[i].l, (e[i].r - e[i].l + 1 - 3));
            else{
                int tmp = answer(1, 1, n, e[i].l, e[i].r);
                if(tmp >= n) ans[e[i].id] = -1;
                else ans[e[i].id] = (e[i].r - e[i].l + 1) - tmp;
            }
        }
        for(int i = 1; i <= q; i++) cout << ans[i] << '\n';
    }
}

:::

C. 蜗蜗的魔力数字

暴力的写法就是数位DP板子,不需要太多解释😑。

由于我们直接跑数位DP它的状态是存不下的🤨,所以我们思考如何将他当前1的个数状态消除。我们观察他给我们递推式子👀,其实是可以直接将答案的整体通过这个式子进行求答案的😬,就可以把它的第二维舍去🤯。

但是不知道是记忆化搜索不是很好写还是傻逼错误导致我始终没有过大样例😤,下面是一种 for 循环的更好方法。

我们定义维度 sum_{1,i,limit} 表示前 i 个数,是否有约束的所有 f(i-1) 的总值。

定义维度 sum_{2,i,limit} 表示前 i 个数,是否有约束的所有 f(i-2) 的总值。

对于有限制时的转移:

所以便有:

sum_{1,i + 1,s_i=0} += sum_{1,i,1} sum_{0,i + 1,s_i=0} += sum_{0,i,1}

当对于有限制的情况下当前位可以取到 1 时

sum_{1,i + 1,s_i=1} += a \times sum_{1,i,1} + sum_{0,i,1} sum_{0,i + 1,s_i=1} += sum_{1,i,1}

对于没有限制时的转移:

sum_{1,i+1,0} += sum_{1,i,0} + sum_{1,i,0} \times a + sum_{0,i,0} sum_{1,i+1,0} += sum_{0,i,0} + sum_{1,i,0}

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 1e7 + 5, M = 1e9 + 7;

string s;
int n, sum[2][MAXX][2], a;

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> s >> a;
    n = s.size(); s = ' ' + s;
    sum[1][1][1] = 1;
    for(int i = 1; i <= n; i++){
        sum[1][i + 1][s[i] - '0' == 0] = (sum[1][i + 1][s[i] - '0' == 0] + sum[1][i][1]) % M;
        sum[0][i + 1][s[i] - '0' == 0] = (sum[0][i + 1][s[i] - '0' == 0] + sum[0][i][1]) % M;
        if(s[i] - '0' == 1){
            sum[1][i + 1][s[i] - '0' == 1] = (sum[1][i + 1][s[i] - '0' == 1] + sum[1][i][1] * a + sum[0][i][1]) % M;
            sum[0][i + 1][s[i] - '0' == 1] = (sum[0][i + 1][s[i] - '0' == 1] + sum[1][i][1]) % M;
        }
        sum[1][i + 1][0] = (sum[1][i + 1][0] + (sum[1][i][0] + sum[1][i][0] * a % M + sum[0][i][0]) % M) % M;
        sum[0][i + 1][0] = (sum[0][i + 1][0] + (sum[0][i][0] + sum[1][i][0]) % M) % M;
    }
    cout << (sum[0][n + 1][0] + sum[0][n + 1][1]) % M;
    return 0;
}

:::

D. 蜗蜗的连线博弈

考试时来不及看了🙄

E. Jump

考试时来不及看了🙄

整体反思

一句话评价:我是zrr🐷。

对于时间分配还是不行,实则没有打暴力的欲望。代码调试能力有待加强🚀!思路分析不过严谨😡!

暑假集训模拟赛 day4 (8.5)

前言

不好挂分了,也是荣誉拿下倒数好吧,我不爱写总结!

比赛基本情况

比赛日期 2026.8.5,比赛时常 8:00-12:30

预计分数:100+100+20+60+0

实际分数:100+100+0+60+0

代码源总榜排名:rk100/292

学校排名:rk19/37

比赛整体回顾

:::info[具体做题时间]

:::

整体感想:这次调题做题和思考用的时间太长了😥,并且C题还没有想出来,这场考试的题目与整体难度并不算难,也是唐完了🍭。

题目复盘

A. 蜗是符文法师

我看到这种博弈论的题目就先往算贡献的方面想了😮。

一开始我思考对于每个1,他要几步才能到达最右边,可是我题目读错了😱,以为是 0 变成 1,1 变成 0 所以浪费了很多时间😡。

后面才发现,对于每个操作,他要么是1往右走了两步,要么走了一步,那么这个问题就转换成小学博弈论了😋,我们就只用判断他是否可以配 3 整除即可🙃。

小学知识,不详细证明😄。

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long 

using namespace std;

string s;
int flag, n, sum, num;

signed main(){
    cin >> s;
    n = s.size(), s = ' ' + s;
    for(int i = 1; i <= n; i++){
        if(s[i] == '1') num++;
        else if(num) sum += num; 
    }
    if(sum % 3 != 0) cout << "Yes" << '\n';
    else cout << "No";
    return 0;
}

:::

B. 蜗蜗的重力通道

这道题思路是一眼题,但是我们要思考如何卡常🤔。

对于这道题,因为他们的宽度最大都只有 100,所以我们很容易就可以造出一个 dp 状态😦。dp_{ij} 表示现在在第 i 个块中,现在的高度是 j 的方案数,转移我们就只用枚举高度差即可🤗。

但是我们发现我们转移需要求组合数,T 有为 100 所以我们需要预处理 l_i 的阶乘👍,并且在美剧高度差的时候也要算阶乘,这样后面算组合数就可以用O(1) 解决了,也不会出现 MLE 的情况👌。

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 1e2 + 5, M = 998244353;

struct pp{
    int sum, i, j;
} zrr[MAXX * MAXX];

int n[MAXX], id[MAXX][MAXX], num[MAXX][MAXX], h[MAXX][MAXX], l[MAXX][MAXX], numf[MAXX][MAXX];
int dp[MAXX][MAXX], inc[MAXX], inf[MAXX], cnt, op[MAXX][MAXX], T;

int qpow(int a, int b){
    int res = 1;
    while(b){
        if(b & 1) res = res * a % M;
        b >>= 1, a = a * a % M;
    }
    return res;
}

void solve(int id){
    memset(dp, 0, sizeof dp);
    for(int i = 1; i <= h[id][1]; i++) dp[1][i] = 1;
    for(int i = 1; i < n[id]; i++){
        for(int j = 1; j <= h[id][i]; j++){
            if(op[id][i] == 0){
                int tmp = num[id][i];
                for(int k = 0; k < j; k++){
                    if(k) tmp = tmp * (k + l[id][i]) % M;
                    if((j - k) > h[id][i + 1]) continue;
                    (dp[i + 1][j - k] += tmp * inf[k] % M * numf[id][i] % M * dp[i][j] % M) %= M;
                }
            }else{
                int tmp = num[id][i];
                for(int k = 0; k <= min(h[id][i + 1] - j, h[id][i] - j); k++){
                    if(k) tmp = tmp * (k + l[id][i]) % M;
                    (dp[i + 1][j + k] += tmp * inf[k] % M * numf[id][i] % M * dp[i][j] % M) %= M;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= 100; i++) ans = (ans + dp[n[id]][i]) % M;
    cout << ans << '\n';
}

bool cmp(pp a, pp b){
    return a.sum < b.sum;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> T;
    inc[0] = inf[0] = 1;
    for(int i = 1; i <= 101; i++){
        inc[i] = inc[i - 1] * i % M;
        inf[i] = qpow(inc[i], M - 2);
    }
    for(int i = 1; i <= T; i++){
        cin >> n[i];
        for(int j = 1; j <= n[i]; j++){
            cin >> l[i][j] >> h[i][j] >> op[i][j]; l[i][j]--;
            zrr[++cnt] = {l[j][i], i, j};
        }
        n[i]++, l[i][n[i]] = 1, h[i][n[i]] = h[i][n[i] - 1];
    }
    sort(zrr + 1, zrr + 1 + cnt, cmp);
    int tmp = 1, lst = 1;
    for(int i = 1; i <= cnt; i++){
        while(lst <= zrr[i].sum) tmp = tmp * lst % M, lst++;
        num[zrr[i].i][zrr[i].j] = tmp, numf[zrr[i].i][zrr[i].j] = qpow(tmp, M - 2);
    }
    for(int i = 1; i <= T; i++) solve(i);
    return 0;
}

:::

总而言之,这个代码就是坨#。

C. 蜗蜗的魔法决斗榜

我一开始往数据结构去思考了,导致没有想到题目的关键,最后就只能打个最简单的暴力跑路了😶。

但是结构暴力都错了!

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 5e2 + 5;

int n, ans, t, k, q, zrr, a[MAXX][MAXX], vis[MAXX][MAXX], id, l, r;

void solve(){
    cin >> n >> k >> q >> zrr;
    for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) vis[i][j] = 0;
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= n; j++){
            cin >> a[i][j];
            for(int k = 1; k < j; k++){';
                vis[a[i][k]][a[i][j]] = 1;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(i == j || vis[i][j]) continue;
            for(int k = 1; k <= n; k++){
                if(j == k || i == k) continue;
                if(vis[i][k] && vis[k][j]) vis[i][j] = 1;
            }
        } 
    }
    while(q--){
        ans = 0;
        cin >> id >> l >> r;
        for(int i = l; i <= r; i++){
            for(int j = i + 1; j <= r; j++){
                if(vis[a[id][i]][a[id][j]] == 1 && vis[a[id][j]][a[id][i]] == 1) ans++;
            }
        }
        cout << ans << '\n';
    }
}

signed main(){
    cin >> t;
    while(t--) solve();
    return 0;
}

:::

经过中午TYK的指点也是明白了他那种很妙的方法🤪。

这题的关键是在想到分界点,若对于所有榜单的前 i 列,刚好只有 i 种数字,那么我们称其为分界点🤓。

我们可以知道对于两个相邻分界点设他们长度为 L 他们可以造出的贡献为 L (L - 1) / 2 个互相压制🤨。

这个东西我们可以用反证法证明,若两个元素 x 和 y 不是互相压制,我们设在所有榜单中 x 在 y 的上面,所以 x 压制 y,那么肯定有一个 k 使得在一个榜单中 k 在他们两上面,一个榜单中 k 在他们的下面,所以他们还是互相压制的。若不存在这样的 k 那么它们两肯定不是相邻的😵。

我们又可以知道对于不同相邻分界点组成的区间之中,他们两是互相没有贡献的,证明读者自证不难😓。

所以题目就转换为对于一个区间 [l,r] 我们要在他们中间找两个最边缘的分界点,然后里面的贡献可以用个前缀和处理,然后再处理一下两边的即可🤯。

D. 蜗蜗的全一数

我却,python还是太好用了好吧,也是直接拿到了 60 分的好成绩😍。

:::info[考场代码]

def solve():
    n = int(input())
    h = n
    cnt = 0
    while h > 0:
        cnt += 1
        h = h // 10
    ans = 0
    for i in range(1, cnt + 1):
        tmp = 0
        for j in range(1, i + 1):
            tmp = tmp * 10 + 1
        if n % tmp == 0:
            ans = i
    print(ans)

t = int(input())
for _ in range(t):
    solve()

:::

E. CP连线大作战

感觉暴力也不好打,所以最后就没咋看了🙄。

:::info[考场代码]

我说了我没写,你还打开干嘛!
zrr so cute

:::

整体反思

我是唐😬,C题也是成功没想到,这也说明我的刷题还是太少了😦,其次我写代码和读题的时候并不是很细心,这也导致我调代码会用很长的时间,需要改进🙄。

暑假集训模拟赛 day4 (8.8)

前言

我吃柠檬,又挂分了,再次拿到倒数的好成绩。

比赛基本情况

比赛日期 2026.8.8,比赛时常 8:00-12:30

预计分数:100+100+20+25+0

实际分数:100+100+0+25+0

代码源总榜排名:rk71/292

学校排名:rk17/37

比赛整体回顾

:::info[具体做题时间]

:::

整体感受:我靠今天的题目就是“食”🤢,两个题需要写 Check,其中还有一道是大数据结构,气笑了😤。今天依旧继承了上次的唐病,暴力都能Wa😠!

题目复盘

A. 蜗蜗的魔法牌堆

这是一道类似诈骗题,写题前请看数据范围🙃。

因为我们可以的操作次数高达 5e5,我们便不由自主的对每个数字看其它需要的贡献😁。

我们发现若我们将一个数从开头移到结尾他的每次步数是递增的,那么对于每个数他的最坏的贡献只有 log(n)🤨 又因为 n 只有 1000 并且每个数字移动距离是越变越小的,我们直接暴力交换即可,时间完全充裕😄!

:::info[考场代码]

#include<bits/stdc++.h>


using namespace std;

const int MAXX = 5e5 + 5;

struct pp{
    int x, y;
} ans[MAXX];

int n, a[MAXX], cnt;

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++){
        int id = 0;
        for(int j = i; j <= n; j++){
            if(a[j] == i){
                id = j; break;
            }
        }
        while(id != i){
            int tmp = min(id - i, n - id + 1);
            for(int j = id; j <= tmp + id - 1; j++) swap(a[j], a[id - tmp + (j - id)]);
            ans[++cnt] = {id - tmp, id + tmp - 1};
            id = id - tmp;
        }
    }
    cout << cnt << '\n';
    for(int i = 1; i <= cnt; i++) cout << ans[i].x << " " << ans[i].y << '\n';
    return 0;
}

:::

B. 磁力实验

这题还是很有难度的🤔。我们可以发现磁和铁的配对可以只有两种情况:

  1. 完全包含
  2. 不相交

因为如果他们有相交且没有完全包含的情况时,要么可以转变成完全包含,要么不相交更优(手玩一下即可)😜。

那么我们对于一个磁,如果它的左边有一个还没有匹配的铁,那么就可以将它们匹配(注意:要最近的😯)。同理,如果对于一个铁,如果他的左边有一个还没匹配的磁,那么也可以将他们匹配🤐。

这样我们就可以知道如何匹配的了,接下来我们要为启动顺序排序🤩。

我们发现如果他们匹配的不是最近的,那么我们发现会有一段区间的配对要在其之前完成抵消👌,那么我们可以用线段树维护 topu 的入度值,然后每次进栈,我们用线段数维护最小值,然后查找最小值为 0 的点即可😕。

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 2e5 + 5;

struct PP{
    int minn, lazy;
} t[MAXX * 4];

struct pp{
    int op, x;
} e[MAXX * 2];

int n, a[MAXX], b[MAXX], cnt, tot, h1, h2, p[MAXX], q[MAXX], num, id[MAXX], zrr[MAXX];
queue<int> Q; 
vector<int> ans;

void pushup(int x){
    t[x].minn = min(t[x * 2].minn, t[x * 2 + 1].minn);
}

void update(int x, int l, int r){
    if(!t[x].lazy) return;
    int mid = (l + r) / 2;
    t[x * 2].minn += t[x].lazy, t[x * 2 + 1].minn += t[x].lazy;
    t[x * 2].lazy += t[x].lazy, t[x * 2 + 1].lazy += t[x].lazy;
    t[x].lazy = 0;
}

void add(int x, int l, int r, int L, int R, int w){
    if(l > R || r < L) return;
    if(L <= l && r <= R){
        t[x].minn += w, t[x].lazy += w;
        return;
    }
    update(x, l, r);
    int mid = (l + r) / 2;
    add(x * 2, l, mid, L, R, w), add(x * 2 + 1, mid + 1, r, L, R, w);
    pushup(x);  
}

void Find(int x, int l, int r){
    if(t[x].minn) return;
    if(l == r){
        t[x].minn = n + 1, Q.push(l);
        return;
    }
    update(x, l, r);
    int mid = (l + r) / 2;
    Find(x * 2, l, mid), Find(x * 2 + 1, mid + 1, r);
    pushup(x); 
}

bool cmp(pp a, pp b){
    return a.x < b.x;
}

signed main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i]; e[++cnt].op = n + i, e[cnt].x = a[i];
    }
    for(int j = 1; j <= n; j++){
        cin >> b[j]; e[++cnt].op = j, e[cnt].x = b[j];
    }
    sort(e + 1, e + 1 + cnt, cmp);
    for(int i = 1; i <= cnt; i++){
        if(e[i].op > n){
            if(h1){
                num += abs(e[p[h1]].x - e[i].x);
                id[e[i].op - n] = e[p[h1]].op, h1--;
            }else q[++h2] = i;
        }else{
            if(h2){
                num += abs(e[q[h2]].x - e[i].x);
                id[e[q[h2]].op - n] = e[i].op, h2--;
            }else p[++h1] = i;
        } 
    }
    for(int i = 1; i <= n; i++){
        int x = b[id[i]], y = a[i];
        int tmp = abs(x - y);
        if(x < y){
            int l = 1, r = i - 1, j = -1;
            while(l <= r){
                int mid = (l + r) / 2;
                if(abs(x - a[mid]) <= tmp) j = mid, r = mid - 1;
                else l = mid + 1;
            }
            zrr[i] = j;
            if(j != -1) add(1, 1, n, j, i - 1, 1);
        }else{
            int l = i + 1, r = n, j = -1;
            while(l <= r){
                int mid = (l + r) / 2;
                if(abs(x - a[mid]) < tmp) j = mid, l = mid + 1;
                else r = mid - 1;
            }
            zrr[i] = j;
            if(j != -1) add(1, 1, n, i + 1, j, 1);
        }
    }
    Find(1, 1, n);
    while(!Q.empty()){
        int x = Q.front(); Q.pop();
        ans.push_back(id[x]);
        if(b[id[x]] < a[x]){
            if(zrr[x] != -1) add(1, 1, n, zrr[x], x - 1, -1);
        }else{
            if(zrr[x] != -1) add(1, 1, n, x + 1, zrr[x], -1);
        }
        Find(1, 1, n);
    }
    cout << num << '\n';
    for(int i = (int)ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
    return 0;
}

:::

还蛮好玩的😋,但就是有点“食”🤮。

C. 符文奥秘

由于B题占用时间过多,直接打暴力😃!

:::info[考场代码]

#include<bits/stdc++.h>


using namespace std;

const int MAXX = 1e5 + 5, M = 131, mod = 998244353, M2 = 97, mod2 = 1e9 + 7;

int a[MAXX], ans, n, t, k;
map<pair<int, int>, int> mp;

void dfs(int x){
    if(x > n){
        int sum = 0;
        for(int i = 1; i <= k; i++) sum += a[i];
        int tmp = sum, tmp2 = sum;
        for(int i = 2; i <= n; i++){
            int zrr = (i + k - 1);
            if(zrr > n) zrr -= n;
            sum = sum - a[i - 1] + a[zrr];
            tmp = (tmp * M + sum) % mod;
            tmp2 = (tmp2 * M2 + sum) % mod2;
        }
        if(!mp.count({tmp, tmp2})) mp[{tmp, tmp2}] = 1, ans++;
        return;
    }
    a[x] = 0;
    dfs(x + 1);
    a[x] = 1;
    dfs(x + 1);
}

int main(){
    cin >> t;
    cin >> n >> k;
    dfs(1);
    cout << ans << '\n';
    return 0;
}

:::

D. 蜗蜗的符文树

由于B题占用时间过多,直接打暴力🙄!

然后最后暴力居然炸了🤣,也是直接损失 25 分😭。

E. 优先队列

压根没看😑!

整体反思

暴力又又又又又炸了🤬!今天的时间管理中平,主要是今天的B对我而言思维和代码都有一点点难,但是这种题还是蛮好玩的🤡。

然后今天第三题其实还好,但是我对数学的敏感度还是不足😥,有待提升空间。其次暴力的正确度也要提升🚀。

暑假集训模拟赛 day5 (8.10)

前言

今天的题目也是非常的“食”💩,一上午都在改 B👿。连暴力都没时间写了,实则是没心情写了😵。哈哈哈哈哈!TYK A没删调试😜!

比赛基本情况

比赛日期 2026.8.10,比赛时常 8:00-12:30

预计分数:100+100+20+0+0

实际分数:100+100+20+0+0

代码源总榜排名:rk65/300

比赛整体回顾

:::info[具体做题时间]

:::

整体感想:我讨厌改题😡,B题搬题人是ZRR,A也是恶心题,CCH还说是好题🤬!?感觉时间还是不太够用,总体时间分配也不平均🙄,也是跟B杠上了好吧!只能说至少今天没挂分😔。

题目复盘

A. 对称风铃

前景提要:这一题有坑,需要多想一下🤔!

对于他的操作次数我们很好解决,就是对于每个线看他平行的有多少根😁,又因为绳子挂的点都不相同,所以我们很容易就可以想到,一定有方案可以使得每个绳子最多动一下👌。

那么我们问题就可以转换为如何解决约束矛盾的问题,其实也并不难,我们可以考虑建图来解决约束🙂,如果对于一个点他的一个断点的对应点属于一条线的点,那么这两条线就不能同时选了这条平行于标准的线,那么又因为所有点不同,边数与时间复杂度完全不会爆🤨!

:::info[考场代码]

#include<bits/stdc++.h>



using namespace std;

const int MAXX = 1e6 + 5;

struct pp{
    int x, y, z;
} ans[MAXX];

int n, x[MAXX], y[MAXX], minn = INT_MAX, cnt, sum[MAXX], ID, vis[MAXX], X[MAXX], Y[MAXX], zrr, id[MAXX];
vector<pair<int, int> > e[MAXX][2];

void dfs(int u, int id){
    if(vis[u]) return;
    if(id == 0) ans[++cnt] = {u, y[u], Y[u]};
    else ans[++cnt] = {u, x[u], X[u]};
    vis[u] = 1;
    for(int i = 0; i < e[u][id].size(); i++){
        dfs(e[u][id][i].first, e[u][id][i].second);
    }
}

signed main(){
    freopen("popipa.in", "r", stdin);
    freopen("popipa.out", "w", stdout);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
        sum[(x[i] + y[i]) % (2 * n)]++;
        id[x[i]] = id[y[i]] = i;
    }
    for(int i = 0; i < 2 * n; i++){
        int tmp = n - sum[(i + ((i + 1) % (2 * n))) % (2 * n)];
        if(tmp < minn) ID = (i + ((i + 1) % (2 * n))) % (2 * n), minn = tmp;
    }
    for(int i = 0; i < n; i++){
        if((x[i] + y[i]) % (2 * n) == ID){
            vis[i] = 1; continue;
        }
        zrr = i;
        Y[i] = (x[i] <= ID ? ID - x[i] : (ID + 2 * n) - x[i]);
        X[i] = (y[i] <= ID ? ID - y[i] : (ID + 2 * n) - y[i]);
        if(x[id[Y[i]]] == Y[i]) e[i][0].push_back({id[Y[i]], 1});
        else if(y[id[Y[i]]] == Y[i]) e[i][0].push_back({id[Y[i]], 0});
        if(x[id[X[i]]] == X[i]) e[i][1].push_back({id[X[i]], 1});
        else if(y[id[X[i]]] == X[i]) e[i][1].push_back({id[X[i]], 0});
    }
    for(int i = 0; i < n; i++){
        if(!vis[i]) dfs(i, 0);
    }
    cout << cnt << '\n';
    for(int i = 1; i <= cnt; i++){
        cout << ans[i].x << " " << ans[i].y << " " << ans[i].z << '\n';
    }
    return 0;
}

:::

B. 魔法石共鸣

这题也是与第一天的A非常的像好吧😍!但是调了我很久😨。

我们直接套路按位考虑,我们从高位往低位思考,如果有 1 那么我们肯定我们要把 1 放一边是最优的,所以我们就有了个基础贪心策略😄。

  1. 我们先从最高位考虑,分到两个队列里面。

  2. 对于现在这个位,如果为 1 的序列里面的数这个位有 1,那么我们就将 0 的序列中这个位为 1 的数塞到 1 序列中。

  3. 对于现在这个位,如果为 1 的序列里面的数这个位没 1,那么我们就将 0 的序列中所有这个位为 1 的数合并,使得他们永远都捆绑在一起,维护答案(合并也就是直接或运算即可)。

备注:这个代码需要处理很多例如边界😑,序列不为空的情况,也是写了我很久好吧🤮!

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 4e5 + 5;

int a[MAXX], n, t, ans, vis[MAXX], k, tot;

void solve(){
    cin >> n; ans = k = tot = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i], vis[i] = 0;
    }
    sort(a + 1, a + 1 + n);
    int tmp = a[n];
    while(tmp) tmp /= 2, k++;
    for(; k >= 1; k--){
        int num = 0;
        for(int i = 1; i <= n; i++) num += ((a[i] >> (k - 1)) & 1);
        if(num < n && num != 0){
            for(int i = 1; i <= n; i++) if((a[i] >> (k - 1)) & 1) vis[i] = 1, tot++;
            ans = (1 << (k - 1)), k--;
            break;
        }
    }
    for(; k >= 1 && tot < n - 1; k--){
        int num = 0;
        for(int i = 1; i <= n; i++) if(vis[i] == 1) num += ((a[i] >> (k - 1)) & 1);
        if(num){
            int xyz = 0;
            for(int i = 1; i <= n; i++) if(vis[i] == 0 && ((a[i] >> (k - 1)) & 1)) xyz++;
            if(tot + xyz == n) continue;
            for(int i = 1; i <= n; i++) if(vis[i] == 0 && ((a[i] >> (k - 1)) & 1)) vis[i] = 1, tot++;
            ans += (1 << (k - 1));
        }else{
            int zrr = 0;
            for(int i = 1; i <= n; i++) if(vis[i] == 0 && ((a[i] >> (k - 1)) & 1)) zrr = i;
            if(!zrr) continue;
            for(int i = 1; i < zrr; i++) if(vis[i] == 0 && ((a[i] >> (k - 1)) & 1)) vis[i] = 2, a[zrr] |= a[i], tot++;
            ans += (1 << (k - 1));
        }
    }
    for(; k >= 1; k--){
        int num1 = 0, num2 = 0;
        for(int i = 1; i <= n; i++) if(vis[i] == 1) num1 += ((a[i] >> (k - 1)) & 1);
        for(int i = 1; i <= n; i++) if(vis[i] == 0) num2 += ((a[i] >> (k - 1)) & 1);
        if((num1 && !num2) || (!num1 && num2)) ans += (1 << (k - 1));
    }
    cout << ans << '\n';
}

signed main(){
    freopen("magic.in", "r", stdin);
    freopen("magic.out", "w", stdout);
    cin >> t;
    while(t--) solve();
    return 0;
}

:::

C. 能量核心共鸣

这道题直接写暴力好吧😶。

:::info[考场代码]

#include<bits/stdc++.h>
#define int unsigned long long

using namespace std;

const int MAXX = 5e3 + 5;

int op[MAXX], l[MAXX], r[MAXX], x[MAXX], a[MAXX], n, q, ans, sum[MAXX], num[MAXX];

void solve1(){
    for(int i = 1; i <= q; i++){
        cin >> op[i];
        if(op[i] == 1){
            cin >> l[i] >> r[i] >> x[i];
            for(int j = l[i]; j <= r[i]; j++) a[j] &= x[i];
        }else if(op[i] == 2){
            cin >> l[i] >> x[i];
            a[l[i]] = x[i];
        }else{
            cin >> l[i] >> r[i];
            sum[l[i]] = a[l[i]], num[r[i]] = a[r[i]];
            for(int j = l[i] + 1; j <= r[i]; j++) sum[j] = sum[j - 1] & a[j];
            for(int j = r[i] - 1; j >= l[i]; j--) num[j] = num[j + 1] & a[j];
            ans = max(num[l[i] + 1], sum[r[i] - 1]);
            for(int j = l[i] + 1; j < r[i]; j++) ans = max(ans, sum[j - 1] & num[j + 1]);
            cout << ans << '\n';
        }
    }
}

void solve2(){
    int sum1 = 0, sum2 = 0, sum3 = 0;
    for(int i = 1; i <= q; i++){
        cin >> op[i];
        if(op[i] == 1){
            sum1++;
            cin >> l[i] >> r[i] >> x[i];
        }else if(op[i] == 2){
            sum2++;
            cin >> l[i] >> x[i];
        }else{
            sum3++;
            cin >> l[i] >> r[i];
        }
    }
}

signed main(){
    freopen("energy.in", "r", stdin);
    freopen("energy.out", "w", stdout);
    cin >> n >> q;
    for(int i = 1; i <= n; i++) cin >> a[i];
    if(n <= 5000) solve1();
    else solve2();
    return 0;
}

:::

D. 蜗蜗的零件仓库

这题不想看了,呜呜呜呜😭!

E. 加一2.5

这题不想看了,呜呜呜呜😭!

整体反思

时间还是不够,调试代码能力太弱了😥,写代码也不够细心,做题前没有考虑代码的正确性😣。

其次我还是太菜了,没有能力考高分😟。

哎~菜就多练吧🏀!

暑假集训模拟赛 day6 (8.13)

前言

妈的今天又挂分了😡,足足挂了 100 分,妈的我就是傻逼🤬。

:::error[比赛感想] 我是傻逼🤬。

我是傻逼🤬。

我是傻逼🤬。

我是傻逼🤬。

我是傻逼🤬。

我是傻逼🤬。

我是傻逼🤬。

我是傻逼🤬。

比赛基本情况

比赛日期 2026.8.13,比赛时常 8:00-12:30

预计分数:100+100+100+0

实际分数:100+100+0+0

代码源总榜排名:rk150/300

比赛整体回顾

:::info[具体做题时间]

整体感想:我是傻子😤,这次题目整体比较简单,而且只有四道题,我却考炸了😩。最后一次模拟赛也是遗憾离场好吧😞!呜呜呜呜😭。

题目复盘

A. 蜗蜗的能量水晶

这一道题是送分题,我们先将数组排序,因为我们要让它的值最小所以我们可以想到最基础的贪心:我们只会选连续的两个数,这样才是最优的👍。

那我们直接选前 n 小的即可吗🤔?

不是,因为对于选的数,他是有一个限制的。因为是最小值做差,我们若选的数字非常的后面这会导致我往里面塞的其他数太小了😮,所以对于我们选的第 i 个数有区间 [1,1+(i-1) \times 2k] 🤨。其实这里可以直接发现单调性二分答案,我一开始写了个线段树,贪心找点会影响两边的答案,会出问题,糖糖🍭。

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long


using namespace std;

const int MAXX = 1e6 + 5;

int n, k, a[MAXX], num[MAXX], ans, N;

bool check(int x){
    int cnt = 0;
    for(int i = 1; i <= N; i++){
        if(num[i] <= x){
            cnt++;
            if(i > 1 + (cnt - 1) * 2 * k) return 0;
            i++;
        }
    }
    return cnt >= n;
}

signed main(){
    freopen("crystal.in", "r", stdin);
    freopen("crystal.out", "w", stdout);
    cin >> n >> k; N = 2 * n * k - 1;
    for(int i = 1; i <= 2 * n * k; i++) cin >> a[i];
    sort(a + 1, a + 1 + 2 * n * k);
    for(int i = 1; i <= N; i++) num[i] = a[i + 1] - a[i];
    int l = 0, r = 1e9;
    while(l <= r){
        int mid = (l + r) / 2;
        if(check(mid)) ans = mid, r = mid - 1;
        else l = mid + 1;
    }
    cout << ans << '\n';
    return 0;
} 

:::

B. 观星

这道题我们可以惊奇的发现😯,他 n,m 的总和不超过 2000 所以综合一下 t = 10 左右,所以 nm^2 的时间复杂度完全可以过😍。

我们发现一个性质:一个人顺时针走,一个人逆时针走,且两个人步数相同,又因为这是一个环所以所有人的坐标值和再取模 m 是不变的🤯,那么我们就可以写 DP 了,剩下步骤啥子都会写😊。

这道题的主要难点就是找到这个性质😄。

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 2e2 + 5;

int n, m, k, a[MAXX], sum, h[MAXX][MAXX], dp[MAXX][MAXX], t, X;

void solve(){
    cin >> n >> m >> X;
    for(int i = 1; i <= n; i++){
        cin >> a[i]; a[i]--; sum += a[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < m; j++) cin >> h[i][j];
    }
    sum %= m;
    memset(dp, -0x7f, sizeof dp);
    dp[0][sum] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < m; j++){
            if(dp[i - 1][j] == dp[0][m + 1]) continue;
            for(int k = 0; k <= m; k++){
                int tmp = k * X % m;
                dp[i][(j + tmp + m) % m] = max(dp[i][(j + tmp + m) % m], dp[i - 1][j] + h[i][(a[i] + tmp) % m]);
                dp[i][(j - tmp + m) % m] = max(dp[i][(j - tmp + m) % m], dp[i - 1][j] + h[i][(a[i] - tmp + m) % m]);
            }
        }
    }
    cout << dp[n][sum] << '\n';
}

signed main(){
    freopen("liel1a.in", "r", stdin);
    freopen("liel1a.out", "w", stdout);
    cin >> t;
    while(t--) solve();
    return 0;
}

:::

C. 生日聚会

由于这个题目搭档保证唯一,我们先思考如何求搭档🤨。

对于一个点如果他现在出度为 1 那么他与其连边。又由于题目保证其图是一个类似的二分图所以不存在基环,因此可以用 topu 就一定可以配对,这样搭档就求出来了😏,那么我们思考如何找连续的😶。

我一开始是这么想的,我们直接把搭档缩成一个点,然后再跑图。但是我们可以发现,如果这样子就不能保证其一定经过搭档边,所以还需改进😐。

但是如果我们构造的图就让他经过这条边即可,因此我想到了新的构图方法👌。

\newcommand{\px}[1]{\color{#1}{\rule{6pt}{6pt}}} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{3b5dc9} \px{3b5dc9} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{ef7d57} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{3b5dc9} \px{3b5dc9} \px{3b5dc9} \px{3b5dc9} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{3b5dc9} \px{3b5dc9} \px{3b5dc9} \px{3b5dc9} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{38b764} \px{38b764} \px{38b764} \px{ffffff} \px{ffffff} \px{1a1c2c} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{3b5dc9} \px{3b5dc9} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{1a1c2c} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{41a6f6} \px{41a6f6} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{1a1c2c} \px{41a6f6} \px{41a6f6} \px{41a6f6} \px{41a6f6} \px{ef7d57} \px{ef7d57} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{38b764} \px{1a1c2c} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{41a6f6} \px{41a6f6} \px{41a6f6} \px{41a6f6} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffcd75} \px{ffcd75} \px{ffcd75} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{38b764} \px{38b764} \px{38b764} \px{ffffff} \px{ffffff} \px{1a1c2c} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{41a6f6} \px{41a6f6} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{1a1c2c} \px{ffffff} \px{ffffff} \px{ffffff} \px{73eff7} \px{73eff7} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{ef7d57} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{b13e53} \px{ffffff} \px{1a1c2c} \px{1a1c2c} \px{73eff7} \px{73eff7} \px{73eff7} \px{73eff7} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{73eff7} \px{73eff7} \px{73eff7} \px{73eff7} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{73eff7} \px{73eff7} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ef7d57} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt] \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \px{ffffff} \\[-6pt]

我们对于两个搭档点绿和黄,我们直接跨过绿连接绿的邻节点,就如图中橙色连边。由于缩点性质不变依然可以跑 topu 排序👍。

:::info[考场代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 2e6 + 5;

int n, m, in[MAXX], vis[MAXX], pre[MAXX], ans[MAXX], tot, u, v, id[MAXX], cnt, flag[MAXX], dp[MAXX], maxx, ID;
pair<int, int> num[MAXX];
vector<int> e[MAXX], G[MAXX];
queue<int> q, Q;

signed main(){
    freopen("party.in", "r", stdin);
    freopen("party.out", "w", stdout);
    cin >> n >> m; n *= 2;
    for(int i = 1; i <= m; i++){
        cin >> u >> v;
        e[u].push_back(v), e[v].push_back(u);
        in[u]++, in[v]++;
    }
    for(int i = 1; i <= n; i++){
        if(in[i] == 1) q.push(i);
    }
    while(!q.empty()){
        int x = q.front(); q.pop();
        for(int i = 0; i < e[x].size(); i++){
            int y = e[x][i];
            if(!id[y]){
                id[x] = y, id[y] = x; 
                for(int j = 0; j < e[id[x]].size(); j++){
                    in[e[id[x]][j]]--;
                    if(in[e[id[x]][j]] == 1) q.push(e[id[x]][j]);
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < e[id[i]].size(); j++){
            int y = e[id[i]][j];
            if(y == i) continue;
            G[i].push_back(y);
            flag[y]++;
//          cout << i << " " << y << '\n';
        }
    }
    for(int i = 1; i <= n; i++){
        if(flag[i] == 0) Q.push(i);
    }
    while(!Q.empty()){
        int x = Q.front(); Q.pop(); dp[x] += 2;
//      cout << x << " | " << dp[x] << '\n';
        if(dp[x] > maxx) maxx = dp[x], ID = x;
        for(int i = 0; i < G[x].size(); i++){
            int y = G[x][i]; flag[y]--;
            if(dp[y] < dp[x]) pre[y] = x, dp[y] = dp[x];
            if(flag[y] == 0) Q.push(y);
        }
    }
    while(ID != 0){
        ans[++tot] = ID; ans[++tot] = id[ID];
        ID = pre[ID];
    }
    cout << tot << '\n';
    for(int i = tot; i >= 1; i--) cout << ans[i] << " ";
    return 0;
}

:::

:::info[AC代码]

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXX = 2e6 + 5;

int n, m, in[MAXX], vis[MAXX], pre[MAXX], ans[MAXX], tot, u, v, id[MAXX], cnt, flag[MAXX], dp[MAXX], maxx, ID;
pair<int, int> num[MAXX];
vector<int> e[MAXX], G[MAXX];
queue<int> q, Q;

signed main(){
//  freopen("party.in", "r", stdin);
//  freopen("party.out", "w", stdout);
    cin >> n >> m; n *= 2;
    for(int i = 1; i <= m; i++){
        cin >> u >> v;
        e[u].push_back(v), e[v].push_back(u);
        in[u]++, in[v]++;
    }
    for(int i = 1; i <= n; i++){
        if(in[i] == 1) q.push(i);
    }
    while(!q.empty()){
        int x = q.front(); q.pop();
        for(int i = 0; i < e[x].size(); i++){
            int y = e[x][i];
            if(!id[y]){
                id[x] = y, id[y] = x; 
                for(int j = 0; j < e[id[x]].size(); j++){
                    in[e[id[x]][j]]--;
                    if(in[e[id[x]][j]] == 1) q.push(e[id[x]][j]);
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < e[id[i]].size(); j++){
            int y = e[id[i]][j];
            if(y == i) continue;
            G[i].push_back(y);
            flag[y]++;
//          cout << i << " " << y << '\n';
        }
    }
    for(int i = 1; i <= n; i++){
        if(flag[i] == 0) Q.push(i);
    }
    while(!Q.empty()){
        int x = Q.front(); Q.pop(); dp[x] += 2;
//      cout << x << " | " << dp[x] << '\n';
        if(dp[x] > maxx) maxx = dp[x], ID = x;
        for(int i = 0; i < G[x].size(); i++){
            int y = G[x][i]; flag[y]--;
            if(dp[y] < dp[x]) pre[y] = x, dp[y] = dp[x];
            if(flag[y] == 0) Q.push(y);
        }
    }
    while(ID != 0){
        ans[++tot] = id[ID]; ans[++tot] = ID;
        ID = pre[ID];
    }
    cout << tot << '\n';
    for(int i = tot; i >= 1; i--) cout << ans[i] << " ";
    return 0;
}

:::

没错就是因为输出顺序导致的,还我 100 分🙁。

D. 蜗蜗的星际帝国

C 题都没调出来写个蛋啊😢!

整体反思

今天挂了本学期最多的一次挂分,也是荣誉再次拿下倒数了😨。

感觉自己的思维和对算法的运用能力还要加强😑。

自我感觉粗心错误以无药可救💀。