Common Goods

3

1 votes
Data Structures, Hard, Segment Trees
Problem

There are N packets of goods each having some number of items in it.The number of items is in the form of an array A (A[i] items of ith type). There are M number of persons in total each having a share in the goods. They have shares in the form of L and R which means that they hold a share of goods [L....R]. Bob wants Q items. He reports the items one by one.
Each time he takes an item you are required to determine how many people have lost all the items from their share.

Note: If Bob wants an item which is unavailable then he will not get it. Here, by "lost all items" we mean that there is not any item left in the share which he holds.

Input Format

First line contains an integer N(number of goods).

Then N integers follow representing the number of items of each type of good.

Then there is an integer M(number of persons) followed by the number 2 .

Then we have M lines containing 2 integers L and R representing their share.

Then there is an integer Q followed by Q integers (each integer in a separate line) representing goods which Bob wants.

Output Format

Print Q space separated integers representing the number of people who lost all the items of their share.

Constraints

1N,M,Q105

1A[i]105

1LRN

All Q integers will be in range 1 to N.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

After 2nd query goods are 2 1 0 0. So pair (3,3) is lost.

After 4th query goods are 1 0 0 0. So pairs (3,3) and (2,3) are lost .

After 5th query goods are 0 0 0 0. So all the 3 pairs are lost.

Editor Image

?