QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#327658#8016. 不休陀螺27455185850 467ms76720kbC++142.2kb2024-02-15 11:46:272024-02-15 11:46:28

Judging History

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

  • [2024-02-15 11:46:28]
  • 评测
  • 测评结果:0
  • 用时:467ms
  • 内存:76720kb
  • [2024-02-15 11:46:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline char gc()
{
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
template<typename T> inline void read(T &x)
{
    T u=1,t=0;char c=gc();
    while(c<'0'||c>'9') {if(c=='-') u=-1; c=gc();}
    while(c>='0'&&c<='9') t*=10,t+=c-'0',c=gc();
    x=u*t;return;
}
template<typename T,typename ...O> inline void read(T &x,O &...o) {read(x),read(o...);}
const int N=1000001;
int n,k,a[N],b[N],d[N];
ll f[N],g[N],h[N];
namespace sgt1
{
    struct tree
    {
        int l,r;
        ll s;
    }T[N<<2];
    void pushup(int x)
    {
        T[x].s=max(T[x<<1].s,T[x<<1|1].s);
    }
    void build(int x,int l,int r)
    {
        T[x].l=l,T[x].r=r;
        if(l==r)
        {
            T[x].s=a[l]-max(a[l]-b[l],0);
            return;
        }
        int z=l+r>>1;
        build(x<<1,l,z);
        build(x<<1|1,z+1,r);
        pushup(x);
    }
    ll sum(int x,int l,int r)
    {
        if(T[x].l>=l&&T[x].r<=r)
        {
            return T[x].s;
        }
        int z=T[x].l+T[x].r>>1;
        ll s=-1e18;
        if(l<=z) s=max(s,sum(x<<1,l,r));
        if(r>z) s=max(s,sum(x<<1|1,l,r));
        return s;
    }
}
namespace sgt2
{
    int T[N];
    void add(int x,int k)
    {
        while(x<=n) T[x]+=k,x+=x&-x;
    }
    int sum(int x)
    {
        int s=0;
        while(x>=1) s+=T[x],x-=x&-x;
        return s;
    }
}
bool check(int l,int r)
{
    return k-(f[r]-f[l-1])>=sgt1::sum(1,l,r);
}
int main()
{
    read(n),read(k);
    for(int i=1;i<=n;++i) read(a[i]);
    for(int i=1;i<=n;++i) read(b[i]);
    sgt1::build(1,1,n);
    for(int i=1;i<=n;++i)
    {
        f[i]=f[i-1]+max(a[i]-b[i],0);
        g[i]=g[i-1]+(b[i]-a[i]);
        h[i]=g[i];
    }
    sort(h+1,h+n+1);
    for(int i=1;i<=n;++i)
    {
        d[i]=lower_bound(h+1,h+n+1,g[i])-h;
    }
    int x=0;
    ll s=0;
    for(int i=1;i<=n;++i)
    {
        if(x<i) x=i-1;
        while(x+1<=n&&check(i,x+1)) sgt2::add(n-d[++x]+1,1);
        s+=sgt2::sum(n-d[i-1]-1);
        if(x>=i) sgt2::add(n-d[i]+1,-1);
    }
    printf("%lld",s);
    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: 2ms
memory: 14236kb

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:

1845600

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 401ms
memory: 73276kb

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:

124003166

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 467ms
memory: 76720kb

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:

99998500009

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 70ms
memory: 31568kb

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:

318603929

result:

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

Subtask #5:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 165ms
memory: 49496kb

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:

36102164

result:

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

Subtask #6:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 238ms
memory: 53172kb

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:

353264667

result:

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