QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#330294#4590. Happy TravellingNYCU_CartesianTreeWA 30ms11760kbC++201.5kb2024-02-17 14:22:522024-02-17 14:22:52

Judging History

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

  • [2024-02-17 14:22:52]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:11760kb
  • [2024-02-17 14:22:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define F first 
#define S second 
#define pb push_back
#define ld double
const int mol=998244353;

multiset<pair<int,int>, greater<>> go[505];
void solve(){
    int n, k, dd;
    cin>>n>>k>>dd;

    vector<int>a(n+1), d(n+1), dp(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<n;i++) cin>>d[i];

    dp[0]=0, d[0]=1e18;
    if(k<=500){
        for(int i=1;i<=n;i++){
            int tot=-1e18;
            for(int j=0;j<k;j++){
                while(go[j].size()&&d[(*go[j].begin()).S]+(*go[j].begin()).S<i) go[j].erase(go[j].begin());
                if(go[j].size()) tot=max(tot, dp[(*go[j].begin()).S]-(i-(*go[j].begin()).S)/k*dd);
            }
            if(i==1) tot=0;
            dp[i]=tot+a[i];
            go[i%k].insert({-(n-i/k)*dd+dp[i], i});
        }
    }
    else{
        priority_queue<pair<int, int>>now;
        for(int i=1;i<=n;i++){
            if(i==1){
                dp[i]=a[i];
                now.push({a[i], i});
                continue;
            }
            while(1){
                auto t=now.top();
                int dis=-(i-t.S)/k*dd+dp[t.S];
                if(t.F!=dis) now.pop(), now.push({dis, t.S});
                else break;
            }
            dp[i]=now.top().S+a[i];
            now.push({dp[i], i});
        }
    }
    cout<<dp[n]<<"\n";
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3828kb

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: 0ms
memory: 3864kb

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: 3832kb

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: 3664kb

input:

2 1 0
-10000 10000
1

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 28ms
memory: 11760kb

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:

-84108

result:

ok single line: '-84108'

Test #6:

score: 0
Accepted
time: 24ms
memory: 11564kb

input:

98467 2 3
-5677 -9080 -6665 -5838 -5755 -8938 -6286 -5160 -7147 -8370 -8214 -6088 -9763 -5183 -7123 -7264 -5298 -8855 -6381 -6592 -9216 -8429 -9598 -7443 -7393 -8712 -5545 -6778 -6010 -5717 -9102 -7968 -6140 -9592 -7917 -5217 -5015 -7798 -9339 -5678 -7073 -7607 -7961 -6185 -9941 -6421 -8779 -5388 -8...

output:

-150169

result:

ok single line: '-150169'

Test #7:

score: 0
Accepted
time: 30ms
memory: 11544kb

input:

96173 2 1
-6463 -9099 -6269 -6169 -8273 -9839 -9929 -5447 -5908 -6884 -6908 -8359 -6477 -9414 -9207 -8180 -6264 -9293 -8981 -6557 -9260 -9700 -6785 -7121 -8382 -9712 -5178 -5821 -9107 -9004 -7472 -9306 -9311 -7160 -7965 -5394 -8048 -7415 -5233 -7746 -7390 -5298 -7721 -7915 -9646 -5371 -5712 -6234 -5...

output:

-45780

result:

ok single line: '-45780'

Test #8:

score: 0
Accepted
time: 26ms
memory: 11588kb

input:

96905 1 1
-7933 -5685 -6201 -5415 -7294 -9904 -8968 -8433 -6287 -6727 -5933 -5418 -8953 -6743 -7057 -7087 -7244 -5302 -5130 -8934 -5053 -9811 -8695 -5989 -7785 -5991 -8351 -9463 -7037 -8867 -8956 -8194 -5272 -6270 -7737 -7793 -8851 -5839 -5178 -7009 -8018 -7375 -6091 -9226 -7117 -9522 -9248 -6036 -8...

output:

-72336

result:

ok single line: '-72336'

Test #9:

score: 0
Accepted
time: 24ms
memory: 11524kb

input:

97070 2 1
-6843 -9736 -7145 -9801 -6733 -7807 -8835 -5776 -6971 -7101 -8428 -7429 -9250 -9405 -6152 -7904 -5761 -8347 -6597 -8875 -8741 -7759 -8905 -9136 -8820 -9272 -9124 -6384 -7302 -5351 -8660 -5499 -9551 -9598 -9332 -7226 -5354 -9753 -7657 -5512 -7806 -5845 -5320 -9052 -8654 -9068 -5744 -7548 -7...

output:

-52581

result:

ok single line: '-52581'

Test #10:

score: -100
Wrong Answer
time: 12ms
memory: 7552kb

input:

95643 95643 0
-5396 -7667 -7724 -8395 -5929 -5814 -6879 -7612 -6487 -5657 -6266 -7551 -8950 -6584 -5148 -7025 -7570 -6296 -6031 -7598 -5852 -5859 -7943 -6304 -6896 -5652 -9303 -5869 -9073 -6843 -7438 -6428 -8896 -5239 -7793 -6730 -7331 -7202 -8118 -9344 -8450 -8315 -8402 -8705 -5246 -9043 -7347 -872...

output:

86715

result:

wrong answer 1st lines differ - expected: '-13774', found: '86715'