Topic Link: Borrowing Classroom
Test instructions: Give n days to the number of classrooms, m to borrow classroom list, in order to borrow classroom, ask which list is not satisfied and output
Analysis: Can be done with the line segment tree, will T, the constant is larger, choose to maintain the prefix and the difference sequence, two-point answer can be
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 intans,n,m,r[1001000],d[1001000],s[1001000],t[1001000],pre[1001000];7 //inline int read () {int X=0;char ch=getchar (); ch>= ' 0 ' &&ch<= ' 9 ')) Ch=getchar (); while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();}; return x;}8 9 intCheckintx)Ten { One intsum=0; Amemset (PRE,0,sizeof(pre)); - for(intI=1; i<=x;i++) pre[s[i]]+=d[i],pre[t[i]+1]-=D[i]; - for(intI=1; i<=n;i++) the { -sum+=Pre[i]; - if(Sum>r[i])return 0; - } + return 1; - } + A intMain () at { -scanf"%d%d",&n,&m); -ans=0; - for(intI=1; i<=n;++i) scanf ("%d", r+i); - for(intI=1; i<=m;++i) {scanf (" %d%d%d", d+i,s+i,t+i);} - intL=1, r=m; in while(l<R) - { to intMid= (l+r) >>1; + if(check (mid) = =0) ans=mid,r=mid; - ElseL=mid+1; the } * if(ANS) printf ("-1\n%d\n", ans); $ ElsePuts"0"); Panax Notoginseng}
View Code
Vijos P1782 borrowing classrooms (prefixes and && differential sequences)