[暑期考试]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)

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

posted @ 2022-07-02 07:49  Altwilio  阅读(32)  评论(0编辑  收藏  举报