Offline processing + scan line. Test instructions is easy to convert: Several rectangles form a set and ask if some points are in and focused?
The official puzzle is not to do so .... That would be more efficient, not for the time being. This is 4500ms g++, c++tle ...
Interval plus a value, ask for a single point value, you can use a tree-like array. Using a line segment tree may cause a large constant of tle.
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePI = ACOs (-1.0), EPS = 1e-8;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} InlineintRead () {Charc = GetChar (); while(!isdigit (c)) C =GetChar (); intx =0; while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();} returnx;}intT, N, PS, PQ, v[1010], c[2000000+Ten];inta[2000000+Ten], sz;structSeg {intX, y1, Y2, F; }s[2000000+Ten];intNS;structquary {intx, y, id; }q[500000+Ten];intNQ;intans[500000+Ten];intLowbit (intx) {returnx& (-x); }voidAddintPintVal) { while(P <= sz) c[p] = C[p] + val, p = p +lowbit (P);}intSumintP) {intR =0; while(P >0) R = r + c[p], p = p-lowbit (p);returnR;}voidUpdateintLintRintval) {Add (L, Val); Add (R +1, -val); }voidADDSEG (intLintRintLintR) {s[ns].x= L, s[ns].y1 = l, S[ns].y2 = R, s[ns].f =1, ns++; s[ns].x= r, S[ns].y1 = L, S[ns].y2 = r, S[ns].f =-1, ns++; A[sz+ +] = L, a[sz++] =R;}BOOLCMP (seg A, seg b) {if(a.x = = b.x)returnA.F > B.f;returnA.x <b.x;}BOOLCMP2 (Quary A, quary b) {returnA.x <b.x;}void Get(){ intx = Lower_bound (A, A + SZ, q[pq].y)-A; X + +; if(sum (x) >0) Ans[q[pq].id] =1;ElseAns[q[pq].id] =0; pq++;}voidInsert () {intL = Lower_bound (A, A + SZ, s[ps].y1)-A; l++; intR = Lower_bound (A, A + SZ, s[ps].y2)-A; r++; Update (L, R, S[PS].F); PS++;}intMain () {scanf ("%d", &T); while(t--) {scanf ("%d%d", &n, &NQ); for(inti =1; I <= N; i++) scanf ("%d", &V[i]); NS=0; SZ =0; for(inti =1; I <= N; i++) { intL =0, r =0, L =0, R =0, W =0, B =0; if(I &1) Addseg (0, V[i],0,0);ElseADDSEG (0,0,0, V[i]); for(intj = i +1; J <= N; J + +) {L= R = w; L = R =b; if(I &1) R = r + V[i];ElseR = r +V[i]; if(J &1) R = r + V[j];ElseR = r +V[j]; Addseg (L, R, L, R); if(J &1) W = w + v[j];ElseB = B +V[j]; } } for(inti =0; i < NQ; i++) {scanf ("%d%d", &q[i].x, &Q[I].Y); Q[i].id =i; A[sz++] =q[i].y; } sort (s, S+ NS, CMP); Sort (q, q +NQ, CMP2); Sort (A, a+ SZ); SZ = Unique (A, A + SZ)-A; PS=0, PQ =0; Memset (c,0,sizeofc); while(PQ <NQ) { if(PS = = ns)Get(); Else { if(S[ps].x <q[pq].x) insert (); Else if(S[ps].x > q[pq].x)Get(); Else{if(S[PS].F = =1) insert ();Else Get(); } } } for(inti =0; i < NQ; i++) printf ("%d", Ans[i]); printf"\ n"); } return 0;}
HDU 5741 Helter Skelter