"Test Instructions Overview"
Give a [0,1,000,000,000] integer axis, starting at the beginning of each position is 0, there are n interval plus operation, and finally asked the number of the largest numbers on the axis.
Exercises
I'm writing about the minimum maintenance interval of a segment tree after discretization.
Actually does not seem to use line tree Qaq ...
#include <cstdio> #include <algorithm> #define N 400010#define RG register#define ls (u<<1) #define RS (U <<1|1) #define MID ((A[U].L+A[U].R) >>1) using namespace std; int n,ans,l[n],r[n],b[n];struct tree{int l,r,del,mx;} A[n];inline int read () {int f=1,k=0; char C=getchar (); while (c< ' 0 ' | | C> ' 9 ') c== '-' && (f=-1), C=getchar (); while (' 0 ' <=c&&c<= ' 9 ') k=k*10+c-' 0 ', C=getchar (); return K*f;} inline int max (int a,int b) {return a>b?a:b;} inline void pushup (int u) {a[u].mx=max (a[ls].mx,a[rs].mx);} inline void pushdown (int u) {if (!a[u].del) return; int d=a[u].del; a[u].del=0;a[ls].del+=d; a[ls].mx+=d;a[rs].del+=d; a[ Rs].mx+=d;} void build (int u,int l,int r) {a[u].l=l; a[u].r=r; a[u].mx=0;if (l<r) Build (Ls,l,mid), build (Rs,mid+1,r);} void Add (int u,int l,int R,int d) {if (l<=a[u].l&&a[u].r<=r) {a[u].del+=d; a[u].mx+=d; return;} Pushdown (U), if (l<=mid) Add (ls,l,r,d), if (r>mid) Add (rs,l,r,d);p ushup (u);} int query (int u,int l,int R) {if (L<=A[U].L&&A[U].R<=R) return A[u].mx;pushdown (U); int ret=0;if (L<=MID) ret=query (ls,l,r), if (R>mid) Ret=max (Ret,query (rs,l,r)); return ret;} int main () {n=read (); for (RG int i=1;i<=n;i++) {l[i]=b[i]=read (); R[i]=b[i+n]=read ();} Sort (b+1,b+1+ (n<<1)); int N2=unique (b+1,b+1+ (n<<1))-b-1;for (RG int i=1;i<=n;i++) L[i]=lower_bound (B+1,b+1+n2,l[i])-b;for (RG int I =1;i<=n;i++) R[i]=lower_bound (B+1,b+1+n2,r[i])-b;//for (RG int i=1;i<=n;i++) {//printf ("%d%d\n", l[i],r[i]);// }//printf ("n2=%d\n", n2); ans=0; Build (1,1,N2), for (RG int i=1;i<=n;i++) {Add (1,l[i],r[i],1);} for (RG int i=1;i<=n2;i++) {Ans=max (Ans,query (1,i,i));//printf ("%d\n", Query (1,i,i));} printf ("%d\n", ans); return 0;}
Bzoj 2501 [usaco2010 Oct]soda Machine