QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#307884#8016. 不休陀螺ftt_fan_club0 421ms128616kbC++142.2kb2024-01-19 10:56:362024-01-19 10:56:37

Judging History

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

  • [2024-01-19 10:56:37]
  • 评测
  • 测评结果:0
  • 用时:421ms
  • 内存:128616kb
  • [2024-01-19 10:56:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e6+7,inf=1e9+7;
int n,E,a[N],b[N],c[N];
ll sum[N],u[N];
int maxn[N][20],lg[N];
struct qry{
    int r,vl;
}f[2][N];
int tot=0;
int fi(ll x){
    int l=1,r=n+1;
    while(l<=r){
        int mid=(l+r)>>1;
        if(sum[mid]==x)
            return mid;
        if(sum[mid]<x)l=mid+1;
        else r=mid-1;
    }
}bool cmp(qry x,qry y){return x.r<y.r;}
void add(int ps){
    for(;ps<=n+1;ps+=ps&(-ps))
        c[ps]++;
    return;
}int qryy(int ps){
    int x=0;
    for(;ps;ps-=ps&(-ps))
        x+=c[ps];
    return x;
}int qry_maxn(int l,int r){
    int op=lg[r-l+1];
    return max(maxn[l][op],maxn[r-(1<<op)+1][op]);
}bool check(int l,int r){return sum[r]-sum[l-1]+qry_maxn(l,r)<=E;}
signed main(){
    //freopen("top.in","r",stdin);
    //freopen("top.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cin>>n>>E;
    for(int i=2;i<=n;i++)
        lg[i]=lg[i/2]+1;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++){
        u[i]=u[i-1]+a[i]-b[i];
        sum[i]=sum[i-1]+max(0,a[i]-b[i]);
        maxn[i][0]=min(a[i],b[i]);
    }for(int i=1;i<=19;i++)
        for(int j=1;j<=n;j++)
            if(j+(1<<(i-1))<=n)
            maxn[j][i]=max(maxn[j][i-1],maxn[j+(1<<(i-1))][i-1]);
    for(int i=1;i<=n;i++){
        int l=i,r=n,s=i-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(check(i,mid)){
                l=mid+1;
                s=mid;
            }else r=mid-1;
        }if(s>=i){
            tot++;
            f[0][tot].r=i-1;
            f[1][tot].r=s;
            f[0][tot].vl=f[1][tot].vl=u[i-1];
        }
    }for(int i=1;i<=n;i++)
        sum[i]=u[i];
    sum[n+1]=0;
    sort(sum+1,sum+n+2);
    for(int i=1;i<=n;i++)
        u[i]=fi(u[i]);
    ll ans=0;
    for(int h=0;h<=1;h++){
        memset(c,0,sizeof(c));
        int nw,rr=0;
        if(h==0)nw=-1;
        else nw=1;
        sort(f[h]+1,f[h]+tot+1,cmp);
        /*for(int i=1;i<=tot;i++){
            while(rr<f[h][i].r){
                rr++;
                add(u[rr]);
            }ans+=nw*qryy(fi(f[h][i].vl));
        }*/
    }cout<<ans<<"\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: 18124kb

input:

5000 939255322
47952340 92329911 61615795 40122788 47258178 29326499 9822850 42767362 86610596 60318756 52429688 87502511 50194916 96377063 74322128 19511341 28794957 53813791 79075058 35555414 5249682 45174421 101856091 25257909 94697470 45853817 82945426 108415825 41731145 87133877 75167193 598696...

output:

0

result:

wrong answer 1st lines differ - expected: '1846283', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 330ms
memory: 109184kb

input:

774484 763692678
47702350 34856775 28447988 4178162 45063720 8232662 36845607 27038945 44858289 5952529 39159657 21628528 60199611 5544054 59216841 39287087 43449994 20034684 56440004 11583811 44465341 32347476 49196492 22731571 9481143 11726859 35167370 23103544 23109378 38822668 29778048 58004104 ...

output:

0

result:

wrong answer 1st lines differ - expected: '124023429', found: '0'

Subtask #3:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 421ms
memory: 128616kb

input:

1000000 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

0

result:

wrong answer 1st lines differ - expected: '99999500000', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 44ms
memory: 41492kb

input:

174457 888
0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1...

output:

0

result:

wrong answer 1st lines differ - expected: '329807918', found: '0'

Subtask #5:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 130ms
memory: 60676kb

input:

343922 773619774
0 8292680 5684115 0 0 170056 5385926 0 0 1588575 0 0 10947891 170867 35145 0 0 103085 7231562 0 0 0 0 11128944 0 4872226 0 2879880 7565181 0 8631665 0 5162564 9511835 514165 0 9628987 14357934 174784 0 12400154 0 0 8198218 0 8496060 0 0 0 0 10376826 3523227 0 14548249 0 6840016 0 0 ...

output:

0

result:

wrong answer 1st lines differ - expected: '36107528', found: '0'

Subtask #6:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 175ms
memory: 77516kb

input:

468676 582048177
6889433 7293342 20676061 15545414 4911497 12352219 8921719 1705801 19695926 25259227 2645394 17518171 19753552 9449377 982708 22479531 1267985 15594372 20685422 9627290 2017543 6459134 18614020 16206301 14962487 12932255 7101003 29140540 6479702 20607124 2540287 15565156 20274141 11...

output:

0

result:

wrong answer 1st lines differ - expected: '353280708', found: '0'