Chef and odd queries
All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has N segments. For each i (1 ≤ i ≤ N), the i-th segment starts at point Li and ends at point Ri (let's denote it by [Li, Ri]).
Let's say that a segment [l, r] crosses a point x if l ≤ x ≤ r.
Chef wants you to answer Q queries. In each query, you are given a set of M distinct points X1, X2, ..., XM; you should compute the number of good segments [Li, Ri] among the given N segments. A segment is good if it crosses an odd number of points out of the given M points.
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N denoting the number of segments.
- The following N lines describe the segments. For each i, the i-th of these lines contains two space-separated integers Li and Ri.
- The next line contains a single integer Q denoting the number of queries.
- The following Q lines describe the queries. Each of these lines starts with an integer M — the number of points in this query, followed by M space-separated integers X1, X2, ..., XM.
- 1 ≤ T ≤ 100
- 1 ≤ Q ≤ N ≤ 100,000
- sum of M for all queries ≤ N
- sum of N over all test cases ≤ 200,000
- 1 ≤ Xi ≤ N for each valid i
- all Xi in each query are distinct
- 1 ≤ Li ≤ Ri ≤ N for each valid i
Subtask #1 (10 points): N, Q ≤ 300
Subtask #2 (90 points): original constraints
For each query, print a single line containing the number of good segments for that query.
Input: 2 5 4 5 3 5 2 4 1 3 5 5 2 4 1 2 3 4 1 4 5 4 5 3 5 2 4 2 3 5 5 2 2 2 5 3 1 2 5 Output: 3 3 5 5
|Tags||feb18, markysha, medium-hard, persistence, segment-tree, sqrt-decomp|
|Time Limit:||4 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions