p406.ans1
======================
1
6 1 2 3 1 2 3
2
6 1 2 3 1 2 3
4 3 2 4 5
1
4 3 2 4 5
0
1
4 3 2 4 5

=================
p406.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n, m;
vector<vector<int>> seqs;
vector<set<int>> present;

void read() {
    cin >> n >> m;
    seqs.assign(n, {});
    present.assign(n, {});
    for(int i = 0; i < n; i++) {
        int k;
        cin >> k;
        seqs[i].resize(k);
        cin >> seqs[i];
        for(int x: seqs[i]) {
            present[i].insert(x);
        }
    }
}

void solve() {
    // Each database sequence stores its element multiset (as a vector to
    // preserve order) and a set of present values for O(log) membership tests.
    // A query lists wanted values (positive) and unwanted values (negative);
    // a sequence matches if it contains every positive value and none of the
    // values whose negation is given. We scan sequences in input order and
    // print the matching ones in their original format.

    while(m--) {
        int l;
        cin >> l;
        vector<int> query(l);
        cin >> query;
        vector<int> matched;
        for(int i = 0; i < n; i++) {
            bool ok = true;
            for(int q: query) {
                if(q > 0 && !present[i].count(q)) {
                    ok = false;
                } else if(q < 0 && present[i].count(-q)) {
                    ok = false;
                }
            }

            if(ok) {
                matched.push_back(i);
            }
        }

        cout << matched.size() << '\n';
        for(int idx: matched) {
            cout << seqs[idx].size() << ' ' << seqs[idx] << '\n';
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    read();
    solve();

    return 0;
}

=================
p406.in1
======================
3 5
6 1 2 3 1 2 3
4 3 2 4 5
2 4 2
3 1 2 3
2 3 2
3 2 -1 3
2 4 -2
2 4 5

=================
statement.txt
======================
406. Goggle
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



Everybody knows search engine Goggle. But only advanced users know that it is possible to search number sequences. You can enter a set of numbers and the search engine will find all sequences which contain it. Goggle developers decided to improve the engine. New feature will help you if you know numbers which shouldn't be in the result. These numbers must be entered with the opposite sign. For example, if somebody enters "5 -3 6", the engine will find all the sequences which contain 5 and 6, but do not contain 3.

Help Goggle developers to implement the feature.

Input
The first line of the input will contain two integer numbers n and m (1 ≤ n ≤ 10, 1 ≤ m ≤ 10), where n is the number of sequences in Goggle database and m is the number of queries. Following n lines describe sequences in the Goggle database. The first integer k in each line is the length of the sequence (1 ≤ k ≤ 10). Next k numbers are the sequence elements. All of them are integers between 1 and 100, inclusive. Following m lines describe queries. The first integer l of each line is the numbers in query (1 ≤ l ≤ 10). Next l numbers bi are the sequence elements (1 ≤ |bi| ≤ 100, bi ≠ 0). These numbers have different absolute values.

Output
For each query print t — the number of found sequences on a separate line. Each of the next t lines should contain found sequence. The relative order of sequences should be preserved (in compliance with the input). The order of numbers in sequences should not change (in compliance with the input). Write sequences in format as they were given in the input.

Example(s)
sample input
sample output
3 5
6 1 2 3 1 2 3
4 3 2 4 5
2 4 2
3 1 2 3
2 3 2
3 2 -1 3
2 4 -2
2 4 5
1
6 1 2 3 1 2 3
2
6 1 2 3 1 2 3
4 3 2 4 5
1
4 3 2 4 5
0
1
4 3 2 4 5


=================
