wa了两个点?!!#6#20感觉上下界没错呀

P1314 [NOIP2011 提高组] 聪明的质监员

森海塞尔 @ 2017-10-27 08:43:53

#include<cstdio>
#include<iostream>
#include<algorithm> 
#include<cstring>
#define ll long long 
using namespace std;
ll s,ans=999999999999999999;
ll m,n,w[200001],v[200001];
int ask[200001][2];
int pv[200001];
int pw[200001];
ll abss(ll a)
{
    if(a<0)return -a;
    else return a;
}
int main()
{    
//    freopen("123.txt","r",stdin);
    ll l=233333333333,r=0;
    cin>>n>>m>>s;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&w[i]);
        scanf("%lld",&v[i]); 
        r=max(r,w[i]);
//        l=min(l,w[i]);
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&ask[i][0],&ask[i][1]);
    }
    r=r*2+1;
    l=0;
    while(l<r)
    {   memset(pv,0,sizeof(pv));
        memset(pw,0,sizeof(pw));
        ll tmp=0;
        ll mid=(l+r)/2;
        for(int i=1;i<=n;i++)
        {
            if(w[i]>=mid)
            {pw[i]=pw[i-1]+1;pv[i]=pv[i-1]+v[i];}
            else 
            {
            pw[i]=pw[i-1];pv[i]=pv[i-1];}
        }
        for(int i=1;i<=m;i++)
        {
            tmp+=(pw[ask[i][1]]-pw[ask[i][0]-1])*(pv[ask[i][1]]-pv[ask[i][0]-1]);
        }
        if(tmp<s)r=mid;
        if(tmp==s)
        {
            cout<<0;return 0;
        }
        if(tmp>s)l=mid+1;
        ans=min(abss(tmp-s),ans);
    }
    cout<<ans;
}

by silverxz @ 2017-10-28 16:38:53

@森海塞尔 咱俩错的一样。把前缀和数组改成longlong就可以A了233……


by 森海塞尔 @ 2017-10-29 08:29:22

@银芒 哇谢谢,我看了一个小时都没检查出来错,原来是忘开long long 了


|