跳到正文

个人记录

2025.11.26

ddoogg约 10 分钟
原文
文章信息与版本

文章信息

发布
2025年12月3日
收录
2025年12月12日
更新
2026年10月29日
篇幅
约 10 分钟

版本

  1. v1当前

T699598 升起吧!潮汐!!!!

题意

现在有一片长度为 nn 的海滩,我们用 1,2,3,…,nn 来表示每一个点,每个点起始的高度都是 0。进行 mm 次操作,每次操作可以让区间 [l,r][l,r] 的高度增加 cc。

目的

输出 m 次操作后,海滩每一个点的高度情况。

思路

照题意模拟即可。

代码

C++
#include <bits/stdc++.h>
using namespace std;
int a[1005];
int main()
{
    int n, m;
    cin >> n >> m;
    while(m--)
    {
        int c, l, r;
        cin >> l >> r >> c;
        for(int i = l; i <= r; i++)
        {
            a[i] += c;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        cout << a[i] << ' ';
    }
    return 0;
}

T702378 平衡

题意

一个包含 nn 个正整数的序列 A\mathbb A。在此题中,一个序列是平衡的当且仅当存在一个正整数 ii 使得∑1iAi=∑i+1nAi\sum^i_1{\mathbb A_i} = \sum^n_{i + 1}{\mathbb A_i}。

目的

判断序列 A\mathbb A 是否是平衡的。

思路

照题意模拟即可。

代码

C++
#include <bits/stdc++.h>
using namespace std;
int s[10000];
int main()
{
    int t, n;
    cin >> t;
    while(t--)
    {
        cin >> n;
        for(int i = 1; i <= n; i++)
        {
            int e;
            cin >> e;
            s[i] = s[i - 1] + e;
        }
        bool b = 1;
        for(int i = 1; i <= n; i++)
        {
            if(s[i] == s[n] - s[i])
            {
                b = 0;
                break;
            }
        }
        if(b) cout << "Yes" << endl;
        else cout << "No" << endl
    }
    return 0;
}

ACAC 代码

C++
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main()
{
    int t, n;
    cin >> t;
    while(t--)
    {
    	int sl = 0, sr = 0;
        cin >> n;
        for(int i = 1; i <= n; i++)
        {
            cin >> a[i];
            sr += a[i];
        }
        bool b = 0;
        for(int i = 1; i <= n; i++)
        {
            sl += a[i];
            sr -= a[i];
            if(sl == sr)
            {
                b = 1;
                break;
            }
        }
        if(b) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

错因

编译错误。

T671140 合并两个有序序列

题意

给定两个升序(可以相等)集合 A\mathbb A 和 B\mathbb B,请你合并为一个升序(可以相等)集合 C\mathbb C。

目的

将集合 C\mathbb C 输出。

思路

照题意模拟即可。

代码

C++
#include <bits/stdc++.h>
using namespace std;
int a[500005], b[500005], c[500005];
int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= m; i++)
        cin >> b[i];
    for(int i = 1; i <= n; i++)
        c[i] = a[i];
    for(int i = n + 1; i <= m; i++)
        c[i] = b[i - n];
    sort(c + 1, c + n + m + 1);
    for(int i = 1; i <=n + m; i++)
        cout << c[i];
    return 0;
}

ACAC 代码

C++
#include <bits/stdc++.h>
using namespace std;
queue <int> q1, q2;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        q1.push(x);
    }
    for(int i = 1; i <= m; i++)
    {
        int x;
        cin >> x;
        q2.push(x);
    }
    q1.push(INT_MAX);
    q2.push(INT_MAX);
    while(q1.size() > 1 || q2.size() > 1)
    {
        if(q1.front() <= q2.front())
        {
            cout << q1.front() << ' ';
            q1.pop();
        }
        else
        {
            cout << q2.front() << ' ';
            q2.pop();
        }
    }
    return 0;
}

错因

提高了时间复杂度。

T688331 Snake Queue

题意

存在一个蛇的队列。初始时队列为空。给定 QQ 个查询,请按顺序处理。查询有以下三种类型:

  1. 以 1 ll 的形式给出。将长度为 ll 的蛇添加到队列末尾。此时,若原队列为空,则添加的蛇的头部坐标为 0;否则,新蛇的头部坐标为队列最后一条蛇的头部坐标加上其长度。
  2. 以 2 的形式给出。队列最前端的蛇离开队列。此时保证队列不为空。设离开的蛇长度为 mm,队列中剩余所有蛇的头部坐标将减少 mm。
  3. 以 3 kk 的形式给出。输出队列中从前往后数第 kk 条蛇的头部坐标。此时保证队列中至少有 kk 条蛇。

目的

输出查询结果。

思路

使用结构体模拟(不然会 TLETLE)。

代码

C++
#include <bits/stdc++.h>
int qu[300005];
int main()
{
    int q, l = 0, r = -1;
    cin >> q;
    while(q--)
    {
        int t;
        cin >> t;
        if(t == 1)
        {
            cin >> s;
            qu[++r] = s;
        }
        else if(t == 2) l++;
        else
        {
            for(int i = l; i <= r; i++)
            {
                int x = 0;
                if(i == k)
                {
                    cout << x << endl;
                    break;
                }
                x += qu[i] + 1;
            }
        }
    }
    return 0;
}

ACAC 代码

C++
#include <bits/stdc++.h>
#define ll long long
using namespace std;

struct st
{
    ll x, s;
}qu[300005];

int main()
{
    ll q, l = 1, r = 0, sum1 = 0, sum2 = 0;
    cin >> q;
    while(q--)
    {
        int t;
        cin >> t;
        if(t == 1)
        {
            cin >> qu[++r].s;
            sum1 += qu[r].s;
            qu[r].x = sum1 - qu[r].s;
        }
        else if(t == 2)
        {
            sum2 += qu[l].s;
            l++;
        }
        else
        {
            ll k;
            cin >> k;
            cout << qu[l + k - 1].x - sum2 << endl;
        }
    }
    return 0;
}

错因

编译错误。

原文