QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#731824#8951. 澡堂int_R0 278ms410848kbC++143.0kb2024-11-10 11:35:442024-11-10 11:35:44

Judging History

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

  • [2024-11-10 11:35:44]
  • 评测
  • 测评结果:0
  • 用时:278ms
  • 内存:410848kb
  • [2024-11-10 11:35:44]
  • 提交

answer

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int MAXN=1e6+10;
const ll INF=1e18;
int n,m,q,t[MAXN],top,s[MAXN];
ll T;__int128 S,now,ans;
struct node
{
    int I,n;vector <int> t,f[20];
    vector <ll> w,h[20],g[20];
    inline ll Q(int l,int r)
    {
        int t=__lg(r-l+1);
        return max(h[t][r],h[t][l+(1<<t)-1]);
    }
    inline void calc(int l,int r,int del=0)
    {
        l=(l-I)/m+((l-I)%m!=0),r=(r-I)/m;
        if(l>r) return ;del=-del*T;
        if(Q(l,r)+del<=now){ans+=(r-l+1)*now;return ;}
        int L=l,R=r;while(L<R)
            {int m=(L+R)>>1;(Q(l,m)+del>now)?R=m:L=m+1;}
        ans+=(L-l)*now;int tmp=L;
        for(int i=__lg(n);~i;--i)
            if(f[i][L]&&f[i][L]<=r) ans+=g[i][L],L=f[i][L];
        ans+=(L-tmp)*del;
        now=w[L]+del,ans+=(r-L+1)*now;return ;
    }
    inline void init()
    {
        n=t.size(),top=0,w.resize(n);
        for(int i=0;i<=__lg(n);++i)
            f[i].resize(n),g[i].resize(n),h[i].resize(n);
        for(int i=0;i<n;++i)
        {
            S+=(h[0][i]=w[i]=t[i]-i*T);
            for(int j=1;j<=__lg(i+1);++j)
                h[j][i]=max(h[j-1][i],h[j-1][i-(1<<j-1)]);
        }
        for(int i=n-1;~i;--i)
        {
            while(top&&w[s[top]]<=w[i]) --top;
            g[0][i]=w[i]*((f[0][i]=s[top])-i),s[++top]=i;
            for(int j=1;f[j-1][i];++j)
                f[j][i]=f[j-1][f[j-1][i]],
                g[j][i]=g[j-1][i]+g[j-1][f[j-1][i]];
        }
    }
}o[5];
inline void calc(ll num)
    {if(num>now) now=num;ans+=now;}
inline void write(__int128 num)
{
    if(!num) return ;write(num/10);
    cout<<(int)(num%10);return ;
}
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("shuju.txt","r",stdin);
    freopen("out.out","w",stdout);
#endif
    cin.tie(0),cout.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>m>>q>>T;
    for(int i=0;i<m;++i) o[i].I=i;
    for(int i=0;i<n;++i)
        cin>>t[i],o[i%m].t.push_back(t[i]);
    for(int i=0;i<m;++i) o[i].init();
    for(int x,y;q;--q)
    {
        cin>>x>>y;--x,ans=0;
        int k=upper_bound(t,t+n,y)-t-1;
        if(x==k)
        {
            for(int i=0;i<m;++i)
            {
                now=-INF,o[i].calc(0,x-1);
                if(x%m==i) calc(y-1ll*(x/m)*T);
                o[i].calc(x+1,n-1);
            }
        }
        else if(x<k)
        {
            for(int i=0;i<m;++i)
            {
                now=-INF,o[i].calc(0,x-1);
                o[(i+1)%m].calc(x+1,k-1,-1);
                if((k-1)%m==i) calc(y-1ll*((k-1)/m)*T);
                o[i].calc(k,n-1);
            }
        }
        else
        {
            for(int i=0;i<m;++i)
            {
                now=-INF,o[i].calc(0,k-1);
                if(k%m==i) calc(y-1ll*(k/m)*T);
                o[(i+m-1)%m].calc(k,x-1,+1);
                o[i].calc(x+1,n-1);
            }
        }
        write(ans-(S-t[x]+y)),cout<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5876kb

input:

1000 5 1000 1969617
59993 133807 154199 240894 438118 483699 540258 892751 922552 1049554 1092961 1153394 1287745 1315664 1372758 1550447 1634967 1817853 1825455 2023239 2064188 2117896 2250036 2453036 2492474 2794776 2917935 3047993 3153958 3163156 3237767 3443614 3664074 3716235 3801008 3822067 40...

output:

144389506914
144316774580
144320117758
144361337807
144355307613
144353348038
144321611979
144370520087
144377063413
144374874567
144349790793
144376222537
144318072013
144277478292
144403028642
144368167333
144342577109
144285276200
144300883513
144308772568
144431158915
144353733430
144387542963
1...

result:

wrong answer 1st lines differ - expected: '145473107761', found: '144389506914'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 20
Accepted
time: 227ms
memory: 410748kb

input:

1000000 1 100000 1165
83 197 266 277 299 529 538 601 629 760 792 1081 1208 1211 1387 1726 1873 1932 2198 2437 2448 2584 2715 2813 3113 3169 3207 3386 3934 4013 4032 4057 4137 4213 4396 4666 4754 4786 4856 4917 4966 5054 5124 5151 5196 5505 5548 5583 5730 5763 6031 6161 6169 6372 6446 6517 6712 6744 ...

output:

532526465394304
532526382684731
532526432382169
532526335149396
532526336776485
532526441654485
532526419072018
532526448365904
532526461590885
532526446716107
532526451559614
532526448428416
532526467783803
532526436578785
532526455446447
532526418608776
532526437618228
532526421765463
532526361938...

result:

ok 100000 lines

Test #7:

score: 0
Wrong Answer
time: 239ms
memory: 410848kb

input:

1000000 1 100000 320
81 176 196 266 277 418 437 447 561 667 671 686 708 916 945 987 1077 1147 1343 1447 1459 1622 1739 1821 1907 2052 2211 2334 2483 2502 2553 2681 2879 2899 2996 3003 3075 3089 3141 3197 3312 3411 3450 3488 3525 3711 3870 4033 4066 4103 4216 4290 4341 4406 4500 4578 4600 4655 4697 4...

output:

110078125101649
110078095701794
110078065549730
110078084700891
110078055599406
110078147872941
110078125921229
110078050034681
110078131570282
110078020684010
110078081392840
110078123741061
110078124999461
110078092777746
110078093138994
110078104230505
110078088736720
110078130160314
110078088020...

result:

wrong answer 97401st lines differ - expected: '110078111679391', found: '110078431679758'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 278ms
memory: 372264kb

input:

1000000 5 100000 1887
112 168 223 393 535 558 577 631 631 678 682 1043 1099 1268 1337 1396 1437 1472 1510 1587 1804 1984 2013 2290 2294 2392 2474 2547 2694 2717 2742 2841 2880 2906 2985 3030 3047 3064 3108 3275 3375 3440 3451 3488 3950 3957 3963 4047 4086 4335 4378 4448 4490 4544 4622 4864 4875 4897...

output:

138783873196785
138783888417540
138783955288683
138783834805955
138783848981991
138783842939772
138783789843353
138783814957779
138783859262009
138783802297397
138783820489937
138783904312477
138783934551912
138783919050582
138783861289086
138783860784186
138783834460040
138783893781295
138783857159...

result:

wrong answer 1st lines differ - expected: '138785143191754', found: '138783873196785'

Subtask #6:

score: 0
Skipped

Dependency #3:

0%