Simple greedy, only need to maintain each point can reach the previous minimum and minor values.
Alas, still too weak, the game time to write also quite long, forget to judge the right end of the same interval.
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <set>#include <queue>#include <map>using namespace STD;#define MAX (x, Y) ((() > (y))? ( x):(y))#define MIN (x, y) ((< (y))? ( x):(y))#define N 50010#define PI ACOs ( -1.0)#define INF 100000000typedef Long Longlltypedef unsigned Long LongUllstructlink{intb;} A[n];BOOLCMP (link a, link b) {returna.b<b.b;}intF1[n];intF2[n];intMain () {intN,m,q; while(~scanf("%d%d%d", &n,&m,&q)) {memset(F1,127,sizeof(F1));memset(F2,127,sizeof(F2));intMax1=inf;intMax2=inf; for(intI=1; i<=m;i++) {scanf("%d%d", &A[I].B,&A[I].A); } sort (A +1, A +1+M,CMP);intE=m; for(inti=n;i>=1; i--) {if(a[e].b!=i) {f1[i]=max1; F2[I]=MAX2; }Else if(a[e].b==i) {if(MAX1>A[E].A) {max2=max1; MAX1=A[E].A; }Else if(MAX2>A[E].A) {max2=a[e].a; } f1[i]=max1; F2[I]=MAX2; e--; i++; } }inttmp for(intI=1; i<=q;i++) {scanf("%d", &tmp);intAns=tmp-max (F1[tmp],f2[tmp]);if(ans<0) ans=0;printf("%d\n", ans); } }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ZOJ_3888_7/27 Zhejiang University Month race h