Vijos P1782 borrowing classrooms (prefixes and && differential sequences)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.