其他分享
首页 > 其他分享> > [暑期考试]2022.7.1

[暑期考试]2022.7.1

作者:互联网

\(1.\) 核酸检测(defend)

\[f[i] = f[j] + (i - j - 1) * (i - j) /2 + a[i] \]

\[f[j] + j * (j + 1) / 2 = i * j + f[i] - a[i] - i * (i - 1) / 2 \]

\[Y(f[j] + j * (j + 1) / 2 ) = k(i) X(j) + b(f[i] - a[i] - i * (i - 1) / 2) \]

const int N = 1e6 + 10;
int n, a[N], f[N];
int q[N], hh = 1, tt = 1;

inline int X(int i){ return i; }
inline int Y(int i){ return f[i] + (i * i + i) / 2; }

inline double slope(int i, int j){
    return (double)(Y(i) - Y(j)) / (X(i) - X(j));
}

signed main(){
    read(n);
    for(int i = 1; i <= n; i ++) read(a[i]);
    for(int i = 1; i <= n; i ++){
        while(hh < tt && slope(q[hh], q[hh + 1]) < i) ++ hh;
        f[i] = f[q[hh]] + (i - q[hh]) * (i - q[hh] - 1) / 2 + a[i];
        while(hh < tt && slope(q[tt - 1], q[tt]) > slope(q[tt], i)) -- tt;
        q[++ tt] = i; 
    }
    print(f[n]);
    return 0;
}

\(2.\) 排列(permu)

题意:对于给定序列询问区间内的最长连续值域。

标签:slope,return,int,double,tt,暑期,inline,2022.7,考试
来源: https://www.cnblogs.com/William-Sg/p/16436409.html