题目:
翻译:
思路:
1、找到最大的下限min
2、找到最小的上限max
3、则max-min+1满足1、2约束条件的个数
4、max-min+1减去约束条件3的个数,即为最终答案
5、如果min大于max,则结果为0,不存在满足约束条件的数
代码:
#iclude<iostream>
#include<algorithm>
#include<set>
using namespace std;
int main()
{int t;cin >> t;while (t--){int n;cin >> n;long long min = 0, max = 2e9;set<int> set1;for (int i = 0; i < n; i++){long long a, x;cin >> a >> x;if (a == 1 && x > min){min = x;}else if (a == 2 && x < max){max = x;}elseset1.insert(x);}int flag = 1;if (min > max)flag = 0;if (flag == 1){int ans = max - min+1;for (auto it : set1){if (it >= min && it <= max)ans--;}cout << ans << endl;}elsecout << 0 << endl;}
}