QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252576#4590. Happy TravellinglamWA 53ms42128kbC++141.8kb2023-11-15 21:34:392023-11-15 21:34:40

Judging History

你现在查看的是最新测评结果

  • [2023-11-15 21:34:40]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:42128kb
  • [2023-11-15 21:34:39]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e6 + 5;

int dp[maxn],dp2[maxn];
int f[4*maxn];
int a[maxn],t[maxn];
int n,k,d;
priority_queue<pair<int,int>,vector<pair<int,int>>,less<pair<int,int>> > pq[maxn];

void update(int x, int lx, int rx, int l, int r, int val)
{
    if (lx>r||rx<l) return;
    if (lx>=l&&rx<=r)
    {
        f[x]=max(f[x],val);
        return;
    }
    int mid=(lx+rx)/2;
    update(2*x,lx,mid,l,r,val);
    update(2*x+1,mid+1,rx,l,r,val);
}

int get(int x, int lx, int rx, int idx)
{
    if (lx==rx) return f[x];
    int mid=(lx+rx)/2;
    if (idx<=mid) return max(f[x],get(2*x,lx,mid,idx));
    else return max(f[x],get(2*x+1,mid+1,rx,idx));
}

signed main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> k >> d;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int j = 1; j < n; j++) cin >> t[j];
    fill_n(dp,n+1,-1e18);
    fill_n(dp2,n+1,-1e18);
    fill_n(f,4*n+1,-1e18);
    update(1,1,n,1,1,0);
    int mmax = -1;
    for (int i = 1; i <= n; i++)
    {
        while (!pq[i%k].empty() && i > pq[i%k].top().second) pq[i%k].pop();
        if (!pq[i%k].empty()) dp[i] = max(dp[i], -(i-1)/k*d + pq[i%k].top().first);
        int val2 = dp[i];
        dp[i] = max(dp[i], get(1,1,n,i));
        dp[i] += a[i];
        int val = dp[i];
//        cout << dp[i] << ' ' << val2 << " : ";
        if (i == n) continue;
        mmax = max(mmax, i+t[i]);
        int lo = (mmax - i) / k * k;
        update(1,1,n,i+lo,mmax,dp[i] - d * (lo / k));
//        cout << i << " : " << i + k - 1 << '\n';
        update(1,1,n,i+1,i+k-1,val2);
        update(1,1,n,i+1,min(mmax,i+k-1),val);
        pq[i%k].push({dp[i]+(i-1)/k*d,i+lo-1});

    }
    cout << dp[n] << '\n';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 40188kb

input:

6 2 1
8 -7 -8 9 0 2
5 3 3 2 1

output:

18

result:

ok single line: '18'

Test #2:

score: 0
Accepted
time: 3ms
memory: 39308kb

input:

8 8 8
10 -5 -5 -5 -5 -5 -5 10
5 2 5 3 2 1 1

output:

15

result:

ok single line: '15'

Test #3:

score: 0
Accepted
time: 0ms
memory: 34644kb

input:

13 2 2
-5 -4 -4 -1 7 -6 -5 -4 -3 -2 -1 5 -7
3 10 9 8 7 6 5 4 3 2 1 1

output:

-9

result:

ok single line: '-9'

Test #4:

score: 0
Accepted
time: 0ms
memory: 34664kb

input:

2 1 0
-10000 10000
1

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 53ms
memory: 42128kb

input:

98987 4 3
-8225 -8961 -5537 -5621 -8143 -5214 -5538 -6912 -6601 -8839 -7872 -7867 -9553 -9793 -7333 -7360 -5820 -7459 -8824 -9716 -9757 -5846 -5300 -5912 -7953 -8360 -7609 -5937 -5525 -9748 -7326 -8311 -9979 -9292 -8542 -7589 -7939 -5914 -7985 -9999 -9212 -8274 -8084 -6620 -5991 -7826 -6327 -5228 -6...

output:

-79111

result:

wrong answer 1st lines differ - expected: '-84108', found: '-79111'