Test instructions: n segments [Li, Ri], M queries, each query consists of CNT dots, and the output contains the total number of segments at any point in the CNT point.
Because there is no modification, so we should first go offline to think, but I did not think out.
First, the total number of line segments that do not contain this CNT point is required, so the segments that do not contain these points must be between the CNT points (here you need to add two points one is 0, one is max),
We can classify all segments by RI and then loop through the right end, for the current segment can be at Li +1, and then for each query between the two points (x, y) between the number of segments,
Only need to query the left endpoint is greater than or equal to the number of X is good, because it is the right endpoint from small to large traversal, so do not consider using the endpoint.
found that most of the offline processing is the first one of the one-dimensional order from small to large, and then processing another dimension. This is equivalent to dimensionality reduction.
1#include <bits/stdc++.h>2 3 Const intMAXN = 1e6 +Ten;4typedef std::p Air <int,int>PII;5Std::vector <int>SEG[MAXN], Q[MAXN];6Std::vector <pii>RQ[MAXN];7 namespacefenwicktree{8 intARR[MAXN];9 voidInc (intXintd) {Ten while(X <MAXN) { OneARR[X] + =D; Ax + = x &-x; - } - } the intQueryintx) { - intres =0; - while(X >0){ -Res + =Arr[x]; +X-= x &-x; - } + returnRes; A } at intQueryintUaintUB) { - returnQuery (UB)-Query (ua-1); - } - } - intANS[MAXN]; - voidinit () { inmemset (ans,0,sizeof(ans)); - for(inti =0; i < MAXN; i++){ to seg[i].clear (); + q[i].clear (); - rq[i].clear (); the } * } $ intMain ()Panax Notoginseng { - #ifndef Online_judge theFreopen ("In.txt","R", stdin); + #endif //Online_judge A intN, M; the while(~ scanf ("%d%d", &n, &m)) { + init (); - for(inti =0; I < n; i++){ $ intUA, UB; $scanf"%d%d", &ua, &UB); -ua++, ub++; - Seg[ub].push_back (UA); the } - for(inti =0; I < m; i++){Wuyi intcnt, p; thescanf ("%d", &CNT); -Q[i].push_back (1); Wu while(cnt--){ -scanf ("%d", &p); Aboutp++; $ Q[i].push_back (p); - } -Q[i].push_back (maxn-1); - for(intj =0; J < Q[i].size ()-1; J + +){ A intUA = q[i][j]+1; + intUB = q[i][j+1]-1; the Rq[ub].push_back (Std::make_pair (UA, i)); - } $ } the for(inti =1; i < MAXN; i++){ the for(intj =0; J < Seg[i].size (); J + +){ the intTMP =Seg[i][j]; theFenwicktree::inc (Seg[i][j],1); - } in for(intj =0; J < Rq[i].size (); J + +){ the intIDX =Rq[i][j].second; the intTMP =Rq[i][j].first; AboutANS[IDX] + =Fenwicktree::query (Rq[i][j].first, i); the } the } the for(inti =0; I < m; i++){ +printf"%d\n"Nans[i]); - } the }Bayi return 0; the}
Codeforces Round #216 (Div. 2) E. Valera and Queries tree-like array for offline processing