标签:
最近SLQ正在讲二分……感觉NOIP连考两年二分(聪明的质检员、借教室)也真是……
二分加前序和,水过。
//NOIRP:题目没说用long long啊,出题人你坑我= =
//出题人:(怪我咯?)10^9*10^6你不会算?
1 #include<iostream> 2 using namespace std; 3 const int N=1000005; 4 typedef long long LL; 5 struct ask{ 6 int l,r,s; 7 }xw[N]; 8 LL qz[N]; 9 int n,m,rs[N]; 10 bool check(int day){ 11 int i; 12 memset(qz,0,sizeof(qz)); 13 for(i=1;i<=day;i++){ 14 qz[xw[i].l]+=xw[i].s; 15 qz[xw[i].r+1]-=xw[i].s; 16 } 17 for(i=1;i<=n;i++){ 18 qz[i]+=qz[i-1]; 19 if(rs[i]<qz[i]) 20 return false; 21 } 22 return true; 23 } 24 void read(int &x){ 25 x=0; 26 char c=getchar(); 27 while(c<‘0‘||c>‘9‘)c=getchar(); 28 while(c>=‘0‘&&c<=‘9‘){ 29 x=x*10+c-48; 30 c=getchar(); 31 } 32 } 33 int main() 34 { 35 freopen("classroom.in","r",stdin); 36 freopen("classroom.out","w",stdout); 37 int i,lo,hi; 38 read(n),read(m); 39 for(i=1;i<=n;i++)read(rs[i]); 40 for(i=1;i<=m;i++)read(xw[i].s),read(xw[i].l),read(xw[i].r); 41 if(check(n)){ 42 cout<<0; 43 return 0; 44 } 45 lo=1,hi=n; 46 while(lo<hi){ 47 int mid=(lo+hi)>>1; 48 if(check(mid)) 49 lo=mid+1; 50 else 51 hi=mid; 52 } 53 cout<<-1<<endl<<lo; 54 return 0; 55 }
标签:
原文地址:http://www.cnblogs.com/NOIRP/p/4637184.html