QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#649755#8112. Pastry shoprotcar07WA 1ms7736kbC++231.4kb2024-10-18 09:55:272024-10-18 09:55:27

Judging History

This is the latest submission verdict.

  • [2024-10-18 09:55:27]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7736kb
  • [2024-10-18 09:55:27]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    ll sum;int len,pos;
    node(ll s=0,int l=1,int p=0):sum(s),len(l),pos(p){}
    inline bool operator < (const node&o)const{return sum*o.len<o.sum*len;}
    inline node operator + (const node&o)const{return node(sum+o.sum,len+o.len,pos);}
};
vector<node> v;
constexpr int maxn=2e5+5;
int n,m;ll t[maxn];int d[maxn],id[maxn];ll ans[maxn];
ll s[maxn];int l[maxn];
int main(){
    cin>>n>>m;for(int i=1;i<=n;i++) cin>>t[i];
    for(int i=n;i>=1;i--) t[i]-=t[i-1];
    for(int i=1;i<=m;i++) cin>>d[i],id[i]=i;
    sort(id+1,id+m+1,[&](int x,int y){return d[x]<d[y];});
    stack<node> st;
    for(int i=1;i<=n;i++){
        auto cur=node(t[i],1,i);
        v.push_back(cur);
        while(!st.empty()&&!(cur<st.top())) cur=cur+st.top(),v.push_back(cur),st.pop();
        st.push(cur);
    }
    sort(v.begin(),v.end());
    // for(auto [a,b,c]:v) cout<<a<<' '<<b<<" "<<c<<'\n';
    ll A=0,B=0;auto it=v.begin();
    for(int i=1;i<=m;i++){
        int x=id[i];
        auto z=node(d[x]);
        if(it!=v.end()&&!(z<*it)){
            auto[su,le,p]=*it;it++;
            // cout<<i<<' '<<su<<' '<<le<<' '<<p<<'\n';
            A+=su-s[p],B+=le-l[p];
            s[p]=su,l[p]=le;
        }
        ans[x]=B*d[x]-A;
    }
    for(int i=1;i<=m;i++) cout<<ans[i]<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7716kb

input:

4 3
3 10 11 23
4 2 5

output:

4
1
6

result:

ok 3 number(s): "4 1 6"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7736kb

input:

100 100
1 3 5 5 6 10 10 12 13 14 14 14 14 15 16 17 18 19 19 19 20 22 24 26 26 29 29 30 30 30 31 31 32 32 33 36 37 38 40 40 42 43 43 46 47 47 48 49 55 56 59 60 61 61 63 64 64 65 65 66 67 68 72 74 76 76 77 79 80 80 81 81 81 81 82 82 82 84 84 84 85 87 87 88 89 89 89 90 90 91 91 91 92 93 94 95 99 100 10...

output:

16298
2498
90
270
15774
675
5704
1755
9454
7467
24803
754
576
9605
441
169
25895
9181
1512
1927
304
6
15075
99
10895
2205
8318
13706
28
624
25500
8647
195
110
26028
6443
700
1292
2754
18
17346
27388
16220
208
132
506
600
16394
8578
2909
1365
24737
529
14638
40
2016
400
48
4884
5294
1260
2
72
24764
1...

result:

wrong answer 1st numbers differ - expected: '439025', found: '16298'