retired_treasure @ 2018-03-22 22:09:58
对拍机n<40000,m<40000跑了2h跑不出来错误555~ 感觉自己没救了...
/*
题号:1314
题名:聪明的质监员
作者:sgc
难度:提高+/省选-
*/
#include<bits/stdc++.h>
using namespace std;
int x[200010];
int v[200010];
int beg[200010];
int endss[200010];
long long pre_jz[200010];
long long pre_sl[200010];
long long ans=2147483467;
long long s,UKE;
int n,m;
long long thi=0;
void print()
{
for(int i=1;i<=n;i++)
cout<<pre_jz[i]<<" ";
cout<<endl;
for(int i=1;i<=n;i++)
cout<<pre_sl[i]<<" ";
cout<<endl;
system("pause");
}
bool pd(long long w)
{
memset(pre_sl,0,sizeof(pre_sl));
memset(pre_jz,0,sizeof(pre_jz));
for(int i=1;i<=n;i++)
if(x[i]>=w)
{
pre_jz[i]=v[i]+pre_jz[i-1];
pre_sl[i]=pre_sl[i-1]+1;
}
else
{
pre_jz[i]=pre_jz[i-1];
pre_sl[i]=pre_sl[i-1];
}
// print();
UKE=0,thi=0;
for(int i=1;i<=m;i++)
{
UKE+=(pre_jz[endss[i]]-pre_jz[beg[i]-1])*(pre_sl[endss[i]]-pre_sl[beg[i]-1]);
}
// cout<<UKE<<endl;
thi=llabs(UKE-s);
if(UKE>s) return 1;
else return 0;
}
int main()
{
scanf("%d%d%d",&n,&m,&s);
int mx=-20320,ml=2147483647;
for(int i=1;i<=n;i++)
{
scanf("%d%d",x+i,v+i);
mx=max(mx,x[i]);
ml=min(ml,x[i]);
}
for(int i=1;i<=m;i++)
{
scanf("%d%d",beg+i,endss+i);
}
// cout<<mx<<ml<<endl;
int left=ml-1,right=mx+2;
while(left<=right)
{
int mid=(left+right)>>1;
if(pd(mid)) left=mid+1;
else right=mid-1;
if(thi<ans) ans=thi;
}
cout<<ans<<endl;
return 0;
}
by retired_treasure @ 2018-03-22 22:10:48
35分,WA一堆