Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- using ld = long double;
- using pii = pair<int, int>;
- constexpr int N = 2e5 + 5;
- int t, n, m;
- vector<int> start, fin;
- vector<int> num;
- void Solve() {
- cin >> n >> m;
- num.resize(n + 1);
- for (int i = 0, a, b; i < m; i++) {
- cin >> a >> b;
- if (a > b) {
- start.push_back(b);
- fin.push_back(a);
- }
- }
- sort(start.begin(), start.end());
- sort(fin.begin(), fin.end());
- int cur = 0, si = 0, fi = 0;
- for (int i = 1; i <= n; i++) {
- while(si < m && start[si] == i)
- cur++, si++;
- num[i] = cur;
- while(fi < m && fin[fi] == i)
- cur--, fi++;
- }
- int val = *max_element(num.begin(), num.end());
- if (val != m - n + 2) {
- cout << 0 << endl;
- }
- else {
- vector<int> ans;
- for (int i = 1; i <= n; i++)
- if (num[i] == val)
- ans.push_back(i);
- cout << ans.size() << " ";
- for (int v: ans)
- cout << v << " ";
- cout << endl;
- }
- start.clear();
- fin.clear();
- num.clear();
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- cin >> t;
- while(t--)
- //auto start = chrono::high_resolution_clock::now();
- Solve();
- //auto end = chrono::high_resolution_clock::now();
- //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement