标签:
4 3
2 5 4 3
2 1 3
3 2 4
4 2 4
-1
2
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define ll __int64 #define mod 1000000007 int scan() { int res = 0 , ch ; while( !( ( ch = getchar() ) >= ‘0‘ && ch <= ‘9‘ ) ) { if( ch == EOF ) return 1 << 30 ; } res = ch - ‘0‘ ; while( ( ch = getchar() ) >= ‘0‘ && ch <= ‘9‘ ) res = res * 10 + ( ch - ‘0‘ ) ; return res ; } int ans[1000010]; int a[1000010],x; struct is { int l,r,change; }t[1000010]; int check(int k) { memset(ans,0,sizeof(ans)); for(int i=1;i<=k;i++) { ans[t[i].l]+=t[i].change; ans[t[i].r+1]-=t[i].change; } int sum=0; for(int t=1;t<=x;t++) { sum+=ans[t]; if(sum>a[t]) return 0; } return 1; } int main() { int y,z,i; scanf("%d%d",&x,&y); for(i=1;i<=x;i++) scanf("%d",&a[i]); for(i=1;i<=y;i++) scanf("%d%d%d",&t[i].change,&t[i].l,&t[i].r); int st=1; int en=y; int mid=(st+en)>>1; while(st<en) { mid=(st+en)>>1; if(check(mid)) st=mid+1; else en=mid; } if(check(st)) printf("0\n"); else printf("-1\n%d\n",st); return 0; }
tyvj 2075 [NOIP2012T5]借教室 区间更新+二分
标签:
原文地址:http://www.cnblogs.com/jhz033/p/5352002.html