// Each query scans everyone in the row/column (in the right direction), // checking each if they're eliminated. #include using namespace std; #pragma GCC optimize("O3,unroll-loops") tuple>, vector>, vector>, vector>> read(int n) { vector> rows, cols; vector> row_index(n, {-1, -1}), col_index(n, {-1, -1}); unordered_map row_map, col_map; vector> locations(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; locations[i] = {x, y}; if (!col_map.count(x)) { col_map[x] = (int)cols.size(); cols.push_back({}); } if (!row_map.count(y)) { row_map[y] = (int)rows.size(); rows.push_back({}); } cols[col_map[x]].push_back(i); rows[row_map[y]].push_back(i); } for (auto &r : rows) sort(r.begin(), r.end(), [&](int i, int j) { return locations[i] < locations[j]; }); for (auto &c : cols) sort(c.begin(), c.end(), [&](int i, int j) { return locations[i] < locations[j]; }); for (int i = 0; i < (int)rows.size(); i++) for (int j = 0; j < (int)rows[i].size(); j++) row_index[rows[i][j]] = {i, j}; for (int i = 0; i < (int)cols.size(); i++) for (int j = 0; j < (int)cols[i].size(); j++) col_index[cols[i][j]] = {i, j}; return {rows, cols, row_index, col_index}; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; auto [rows, cols, row_index, col_index] = read(n); vector eliminated(n, false); vector elimination_order; while (m--) { int t; char d; cin >> t >> d; t--; if (eliminated[t]) { cout << "ignore\n"; continue; } elimination_order.resize(0); elimination_order.reserve(n); const vector &line = (d == 'N' || d == 'S') ? cols[col_index[t].first] : rows[row_index[t].first]; int my_index = (d == 'N' || d == 'S') ? col_index[t].second : row_index[t].second; int start = -1, end = -1; switch (d) { case 'N': case 'E': start = my_index + 1; end = line.size(); break; case 'S': case 'W': start = 0; end = my_index; break; } for (int i = start; i < end; i++) { int candidate = line[i]; if (!eliminated[candidate]) elimination_order.push_back(candidate); } cout << elimination_order.size(); for (int x : elimination_order) eliminated[x] = true; if (d == 'S' || d == 'W') { for (int i = (int)elimination_order.size() - 1; i >= 0; i--) cout << ' ' << (elimination_order[i] + 1); } else { for (int x : elimination_order) cout << ' ' << (x + 1); } cout << '\n'; } }