Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
98391 CSYZChenQX 早凉与序列4 C++ 通过 100 56 MS 56396 KB 1237 2023-08-14 17:33:49

Tests(60/60):


#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 2e5 + 5; int t, n, k, lg[MX]; ll x; ll w[MX], c[MX], mul[18], st1[18][MX], st2[18][MX]; void ST() { for(int i=1; i<=17; i++) for(int x=0; x<=n-mul[i]+1; x++) st1[i][x] = min(st1[i-1][x], st1[i-1][x+mul[i-1]]), st2[i][x] = min(st2[i-1][x], st2[i-1][x+mul[i-1]]); } ll mx1(int l, int r) { int k = lg[r-l+1]; return min(st1[k][l], st1[k][r-mul[k]+1]); } ll mx2(int l, int r) { int k = lg[r-l+1]; return min(st2[k][l], st2[k][r-mul[k]+1]); } int main() { cin>>n>>k>>x; if(x<0) x=-x, k = n-k; for(int i=1; i<=n; i++) { scanf("%lld", &w[i]); c[i] = w[i]+c[i-1]; } mul[0] = 1; for(int i=1; i<=17; i++) mul[i] = mul[i-1]*2; lg[1] = 0; for(int i=2; i<=n; i++) lg[i] = lg[i>>1]+1; for(int i=1; i<=n; i++) st1[0][i] = c[i] + 1ll*i*x, st2[0][i] = c[i]-1ll*i*x; ST(); ll ans = 0, x1, x2, p; for(int i=1; i<=n; i++) { p = max(i-k, 0); x1 = mx1(p, i); ans = max(ans, st1[0][i]-x1); x2 = mx2(0, p); ans = max(ans, st1[0][i]-st1[0][p]+st2[0][p]-x2); } printf("%lld\n", ans); return 0; }


测评信息: