QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#379175#8572. Passing Gameucup-team206#WA 54ms10204kbC++171.7kb2024-04-06 16:29:512024-04-06 16:29:52

Judging History

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

  • [2024-04-06 16:29:52]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:10204kb
  • [2024-04-06 16:29:51]
  • 提交

answer

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

#define int long long

using pii=pair<int,int>;

const int N=3e5+1e3+7;

int T,n,k;

pii a[N];

int ans[N];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T;
    while(T--)
    {
        cin>>n>>k;
        for(int i=1;i<=n;i++)
            cin>>a[i].first;
        for(int i=1;i<=n;i++)
            cin>>a[i].second;
        if(a[1].first>a[n].first)
        {
            for(int i=1;i<=n;i++)
                a[i].first=(int)1e9-a[i].first+1;
        }
        int st=a[1].first,ed=a[n].first;
        sort(a+1,a+n+1);
        int p=-1,q=-1;
        for(int i=1;i<=n;i++)
        {
            if(a[i].first==st)
                p=i;
            if(a[i].first==ed)
                q=i;
        }
        vector<int> v;
        v.push_back(q);
        for(int i=q-1;i>=p;i--)
        {
            while(v.size()>1&&a[i].second<a[v.back()].second)
                v.pop_back();
            ans[i]=ans[v.back()]+(a[v.back()].first-a[i].first)*a[i].second;
        }
        int ANS=ans[p];
        if(k>=1)
        {
            int tot=0,ms=a[p].first;
            for(int i=p-1;i>=1;i--)
            {
                tot+=(a[i+1].first-a[i].first)*ms;
                ms=min(ms,a[i].second);
                int l=-1,r=v.size()-1;
                while(r-l>1)
                {
                    int mid=(l+r)>>1;
                    if(a[v[mid]].second<a[i].second)
                        r=mid;
                    else
                        l=mid;
                }
                ANS=min(ANS,ans[v[r]]+tot+(a[v[r]].first-a[i].first)*a[i].second);
            }
        }
        cout<<ANS<<"\n";
    }
}

详细

Test #1:

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

input:

2
4 2
3 2 1 6
3 1 1 3
2 0
1 2
1 2

output:

7
1

result:

ok 2 number(s): "7 1"

Test #2:

score: -100
Wrong Answer
time: 54ms
memory: 10204kb

input:

1
300000 204334
809492393 304618667 173130445 377106790 364888630 949045125 622060683 557772818 216607577 848817467 862855568 507840723 120816645 639713488 741781998 682531787 685261161 601686403 355792373 162819930 710057718 234560726 998604853 678957602 485413982 855985802 109303681 979706626 4822...

output:

64728219028926

result:

wrong answer 1st numbers differ - expected: '31313390701066', found: '64728219028926'