Title: http://www.lydsy.com/JudgeOnline/problem.php?id=1293
Record the color of each point and the coordinates of the previous color point, and then, after discretization, the endpoint of the enumeration is swept forward again.
#include <cstring>#include<iostream>#include<cstdio>#include<queue>#include<cmath>#include<algorithm>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#defineLow (x) (x& (×))#defineMAXN 1005000#defineINF Int (1E9)#defineMM 1000000007#definell Long Longusing namespacestd;intPre[maxn],last[maxn],a[maxn],v[maxn],n,m,ans,cnt;ll Read () {ll x=0, f=1;CharCh=GetChar (); while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}BOOLCalintx) { intmx=0; Rep (I,1, M) { while(v[last[i]]>x) {if(pre[last[i]]==0)return 0; Last[i]=Pre[last[i]]; } if(last[i]<=x) Mx=max (mx,x-V[last[i]]); } ans=min (ans,mx); return 1;}intMain () {//freopen ("In.txt", "R", stdin);N=read (); m=read (); Rep (I,1, M) { intt=read (); Rep (J,1, T) { intX=read (); V[++cnt]=x; a[cnt]=x; PRE[CNT]=last[i]; last[i]=CNT; }} sort (a+1, A +1+CNT); Ans=inf; Down (i,cnt,1){ if(a[i]!=a[i+1]) { if(!cal (A[i])) Break; }} printf ("%d\n", ans); return 0;}
BZOJ1293: [SCOI2009] Birthday present