CSP-S 2026第二轮游记

· · 生活·游记

CSP-S 2026第二轮题目

14:30,严肃进入考场。

注意到1号机器是@Amethyzhe,非常好猫娘,使我的键盘旋转。

考试开始,做第一题。

以下是我的左右脑相互搏击过程:

注意到需要选取尽量大的区间平均分配m令所有值相等。

(区间和+m)mod区间长度=0?我想不到我怎么更正了,但是我用了一些奇异搞笑的东西:线段树求区间和、区间最值……最后还是注意到:

区间最大值 * 区间长度 - 区间和 < m就:

ans = max(ans, 区间长度)

我们可以排序后用前缀和求区间和,从右端点得出区间最大值,双指针做法。当然没有用线段树了,都前缀和了。

std::sort万岁!

后面胡乱捣鼓发现sort就行了,第一题完。 T1 code:

#include <cstdio>
#include <algorithm>
#define lovelive long long
#if defined(__linux__) || defined(linux) || defined(__linux)
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

const int maxn = 5*114514;
lovelive a[maxn], b[maxn], m;
int n;
int read();
lovelive llread();
FILE *in = stdin, *out = stdout;

int main(){
    //in = fopen("crystal.in", "r");out = fopen("crystal.out", "w");
    n = read(), m = llread();
    for(int i = 1; i <= n; ++i){
        a[i] = llread();
    }
    std::sort(a+1, a+1+n);
    for(int i = 1; i <= n; ++i){
        b[i] = a[i]+b[i-1];
    }
    //Why NOI Linux in this test doesn't suppport using Chinese to input?
    lovelive sum, maxn, honaka;
    int len, ans=1;
    int l=1;
    for(int r = 1; r <= n; ++r){
        maxn = a[r];
        len = r-l+1;
        honaka = maxn*len-(b[r]-b[l-1]);
        while(honaka > m){
            ++l;
            len = r-l+1;
            honaka = maxn*len-(b[r]-b[l-1]);
        }
        ans = std::max(ans, len);
    }
    fprintf(out, "%d", ans);
    return 0;
}

int read(){
    int ans = 0, f = 1;
    char ch = fgetc(in);
    while(ch < '0' or ch > '9'){
        if(ch == '-'){
            f = -1;
        }
        ch = fgetc(in);
    }
    while('0' <= ch and ch <= '9'){
        ans = ans*10+ch-'0';
        ch = fgetc(in);
    }
    return ans*f;
}
lovelive llread(){
    lovelive ans = 0, f = 1;
    char ch = fgetc(in);
    while(ch < '0' or ch > '9'){
        if(ch == '-'){
            f = -1;
        }
        ch = fgetc(in);
    }
    while('0' <= ch and ch <= '9'){
        ans = ans*10+ch-'0';
        ch = fgetc(in);
    }
    return ans*f;
}

T2

我注意到可以对每个车站和线路建点,然后我对每个询问跑一次以起点为原点的dijkstra,没有想到floyd,喜提32pts。。。依旧int128存储边权。。。

T3 T4

写了一些小注释。推荐一些木柜子动画。

结算:

这是我第一次写游记。