This page is still under construction.

Parts of this page are still being built. What you see may change.

Mafia

Time limit1sMemory limit1024 MB

Summary
Given accusations of honesty or corruption between cops, count for each queried C the number of size-C corrupt sets consistent with all accusations.
Level

Hard8 of 10

Topics
Graph, Union-find, Combinatorics, Dynamic programming
Solved
No attempts yet

Problem

A mafia has infiltrated the city <insert name here>. This has left the police force of <insert name here> in deep confusion, with accusations of corruption coming from every direction. The city's NN cops (numbered from 00 to N−1N - 1) have made a number of accusations about other policemen. Each accusation is one of the following:

  1. Police officer ii is an honest cop.
  2. Police officer ii is a corrupt cop.

An honest cop always tells the truth, while a corrupt cop always lies. In total there have been MM accusations.

The chief of police is now trying to fix the situation, starting by determining how many of her police officers are corrupt. She has GG different guesses about the number of corrupt cops, and for each such number CC she wants to know how many different sets of size CC can be corrupt (with all remaining cops honest), given that all accusations are consistent.

Input

The judge reads input in the following format:

  • line 11: N M
  • line 22: A[0] ... A[M - 1]
  • line 33: B[0] ... B[M - 1]
  • line 44: T[0] ... T[M - 1]
  • line 55: G, the number of calls made to guess(C).
  • line 66: C1 ... CG, the parameters of the GG calls to guess(C).

Output

The judge writes GG lines containing the return values of guess(C).

Constraints

Let GG be the number of calls to guess(C).

  • N≤2 000N \le 2\,000
  • M≤70 000M \le 70\,000
  • G≤2 000G \le 2\,000

Examples1

  1. Example 1

    Input
    3 2
    1 2
    0 1
    2 2
    4
    0 1 2 3
    
    Expected output
    0 1 1 0