Test instructions
Given a series, up to 100,000 queries L to R do not exceed the number of H.
Analysis:
Alas, too much food.
Online practice should be more obvious, interval maintenance balance tree, with a line of tree set balance tree, or block set balance tree, should be able to a, but did not try, just BB, if there is a mistake to welcome correct.
Actually the most convenient way to practice offline is too ingenious.
Sort the columns in ascending order, sorting all the queries in ascending order of H.
Each time the query is marked with a smaller position than H as 1, the query uses a bit sum (r)-sum (L-1) to
Because they are monotonous, so it is convenient.
In fact, many non-modified interval problems can be converted into offline problems.
Even some modified questions can be taken offline.
The key to these problems is how to transform, but also the key is to do the brain hole.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <iostream>5#include <vector>6 7 8 using namespacestd;9 Ten Const intINF =0x3f3f3f3f; One Const intMAXN =100010; A - intBIT[MAXN]; - intT, N, Q; the - intSuminti) { - ints =0; - while(I >0) { +s + =Bit[i]; -I-= i &-i; + } A returns; at } - - voidAddintIintx) { - while(I <=N) { -Bit[i] + =x; -i + = i &-i; in } - } to + structQ { - intL, R, H; the intindex; * } QUERY[MAXN]; $ Panax Notoginseng BOOLCMP (q A, q b) { - returnA.h <b.h; the } + Apair<int,int>A[MAXN]; the intANS[MAXN]; + - intMain () { $scanf"%d", &t); $ intKase =0; - while(t--) { -memset (bit,0,sizeof(bit)); thescanf"%d%d", &n, &q); - for(inti =1; I <= N; i++) {Wuyiscanf"%d", &A[i].first); theA[i].second =i; - } Wu for(inti =0; i < Q; i++) { -scanf"%d%d%d", &QUERY[I].L, &QUERY[I].R, &query[i].h); Aboutquery[i].l++, query[i].r++; $Query[i].index =i; - } -Sort (query, query +Q, CMP); -Sort (A +1, A + n +1); A intleft =1; + for(inti =0; i < Q; i++) { the while(Left <= n && a[left].first <=query[i].h) { -Add (A[left].second,1); $left++; the } the intR =sum (QUERY[I].R); the intL = SUM (QUERY[I].L-1); theAns[query[i].index] = R-l; - } inprintf"Case %d:\n", ++Kase); the for(inti =0; i < Q; i++) { theprintf"%d\n", Ans[i]); About } the } the the + - return 0; the Bayi}
(Tree-like array + offline query) HDU 4417-super Mario