QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#307889#8016. 不休陀螺ftt_fan_club30 347ms124220kbC++142.2kb2024-01-19 10:58:402024-01-19 10:58:41

Judging History

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

  • [2024-01-19 10:58:41]
  • 评测
  • 测评结果:30
  • 用时:347ms
  • 内存:124220kb
  • [2024-01-19 10:58:40]
  • 提交

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;
    }assert(0);
}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+1;i++)
        sum[i]=u[i-1];
    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: 20
Accepted

Test #1:

score: 20
Accepted
time: 5ms
memory: 16124kb

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:

1846283

result:

ok single line: '1846283'

Test #2:

score: 0
Accepted
time: 5ms
memory: 18168kb

input:

4329 694688892
165277824 152780705 114369871 103975989 100188012 147665514 101173335 39350309 37624153 95413467 157561608 10779445 35486823 19200231 55106545 50853515 35799174 92799915 152580135 158388210 132197954 75468895 66543749 104662491 59493152 108170563 22295314 152619070 77921052 105881528 ...

output:

889705

result:

ok single line: '889705'

Test #3:

score: 0
Accepted
time: 0ms
memory: 16136kb

input:

4932 10000000
879202 367773 895593 794951 253764 695611 164309 502290 638542 960084 766095 457948 783698 475707 157847 491793 196608 378324 211974 924944 42162 797172 334660 900879 522660 328814 402169 938267 498991 347773 922727 827106 16528 994043 12381 756925 642283 186848 423956 927655 344750 14...

output:

10724274

result:

ok single line: '10724274'

Test #4:

score: 0
Accepted
time: 2ms
memory: 18036kb

input:

4545 10000000
343712 838600 973396 360269 315252 660011 857231 837695 934030 232383 174532 293701 238344 367417 96713 556096 316705 468048 511763 208940 360904 853055 809137 119764 388946 415546 420603 893876 816501 899208 82913 705704 70043 223366 792251 899049 782406 849921 967761 54994 105919 384...

output:

5542899

result:

ok single line: '5542899'

Subtask #2:

score: 0
Runtime Error

Test #5:

score: 0
Runtime Error

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:


result:


Subtask #3:

score: 0
Runtime Error

Test #10:

score: 0
Runtime Error

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:


result:


Subtask #4:

score: 10
Accepted

Test #14:

score: 10
Accepted
time: 52ms
memory: 40112kb

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:

329807918

result:

ok single line: '329807918'

Test #15:

score: 0
Accepted
time: 130ms
memory: 69464kb

input:

402729 5000
0 1 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 1 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 1 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 1 0 1 1 0 1 ...

output:

4060615624

result:

ok single line: '4060615624'

Test #16:

score: 0
Accepted
time: 347ms
memory: 124220kb

input:

942956 10000
1 0 1 1 1 0 1 0 1 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 1 1 0 1 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 1 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 1...

output:

20162916507

result:

ok single line: '20162916507'

Test #17:

score: 0
Accepted
time: 298ms
memory: 112040kb

input:

802501 1000
1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 0 1 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 0 1 0 0 ...

output:

1660083853

result:

ok single line: '1660083853'

Subtask #5:

score: 0
Runtime Error

Test #18:

score: 0
Runtime Error

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:


result:


Subtask #6:

score: 0
Runtime Error

Test #24:

score: 30
Accepted
time: 300ms
memory: 75992kb

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:

353280708

result:

ok single line: '353280708'

Test #25:

score: -30
Runtime Error

input:

784267 870748450
16640230 34729067 17389326 19816959 33620307 37478599 33913657 25049965 6902010 9380232 7310329 20289065 20894948 36698878 14442257 16359540 28719955 22890081 28478376 3754189 32959471 19507131 24813668 42236708 1945451 16082602 30349832 14901697 28954054 11411772 23608962 31549506 ...

output:


result: