1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #include <bits/stdc++.h> using namespace std;
const int N = 2e5 + 10; const int inf = 1 << 30; const long long llinf = 1ll << 60; const double PI = acos(-1);
#define lowbit(x) (x&-x) typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<db, db> pdd; typedef pair<ll, int> pli;
int n, m, k, q;
void work() { cin >> n; ll l = 0, r = 1e10, x; vector<int> vec; for (int i = 1, op; i <= n; i++) { cin >> op >> x; switch (op) { case 1: { l = max(x, l); break; } case 2: { r = min(x, r); break; } case 3: { vec.push_back(x); break; } } } if (l > r) { cout << 0 << endl; return; } sort(vec.begin(), vec.end()); unique(vec.begin(), vec.end()); auto it1 = lower_bound(vec.begin(), vec.end(), l); auto it2 = --upper_bound(vec.begin(), vec.end(), r); if (it2 - it1 < 0 || (*it1) < l || (*it2) > r) { cout << r - l + 1 << endl; } else { cout << r - l + 1ll - (ll)(it2 - it1 + 1) << endl; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t --> 0) { work(); } }
|