luogu_P1314 smart quality supervision

Portal: https://www.luogu.org/problem/P1314

This SB was guilty of errors:

  1. Not open longlong see fathers ......
  2. Neither updated check the answer, and no final output determination ans (l); and ans (l + 1) which is the better

Binary parameters W, then the prefix and a lower, individually calculated test value Y.

Not open longlong see fathers

Not open longlong see fathers

Not open longlong see fathers

 

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define R register
typedef long long ll;
using namespace std;
ll n,m,s,ql[200100],qr[200100],w[200100],v[200100],l=1e18,r=-1e18;
ll cnt[200100];
ll sum[200100];
inline ll ans(ll fl){
    ll tot=0;
    memset(sum,0,sizeof(sum));memset(cnt,0,sizeof(cnt));
    for(R int i=1;i<=n;i++){
        if(w[i]>=fl) sum[i]+=v[i],cnt[i]++;
        sum[i]+=sum[i-1];cnt[i]+=cnt[i-1];
    }
    for(R int i=1;i<=m;i++){
        tot+=1ll*(sum[qr[i]]-sum[ql[i]-1])*(cnt[qr[i]]-cnt[ql[i]-1]);
    }
    return tot;
}
int main (){
    scanf("%lld%lld%lld",&n,&m,&s);
    for(R int i=1;i<=n;i++) scanf("%lld%lld",&w[i],&v[i]),l=min(l,w[i]),r=max(r,w[i]);
    for(R int i=1;i<=m;i++)    scanf("%lld%lld",&ql[i],&qr[i]);
    while(l<r){
        int mid=(l+r+1)>>1;
        if(ans(mid)>=s) l=mid;
        else r=mid-1;
    }
    printf("LLD% \ n" , Min (abs (years (l) -s), abs (years (l + 1 ) - s)));
     return  0 ; 
}
View Code

 

Guess you like

Origin www.cnblogs.com/coclhy/p/11748670.html