Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- const int MAXN = 55;
- int a[MAXN], lazy[4 * MAXN], segtree[4 * MAXN];
- int merge(int a, int b) {
- return max(a, b);
- }
- void build(int idx, int l, int r) {
- if (l == r) {
- segtree[idx] = a[l];
- return;
- }
- int m = (l + r) / 2;
- build(idx * 2, l, m);
- build(idx * 2 + 1, m + 1, r);
- segtree[idx] = merge(segtree[idx * 2], segtree[idx * 2 + 1]);
- }
- void apply_lazy(int idx, int l, int r) {
- segtree[idx] += lazy[idx];
- if (l != r) {
- lazy[idx * 2] += lazy[idx];
- lazy[idx * 2 + 1] += lazy[idx];
- }
- lazy[idx] = 0;
- }
- void update(int idx, int l, int r, int ql, int qr, int val) {
- if (lazy[idx] != 0) apply_lazy(idx, l, r);
- if (ql > r || qr < l) return;
- if (ql <= l && r <= qr) {
- lazy[idx] += val;
- apply_lazy(idx, l, r);
- return;
- }
- int m = (l + r) / 2;
- update(idx * 2, l, m, ql, qr, val);
- update(idx * 2 + 1, m + 1, r, ql, qr, val);
- segtree[idx] = merge(segtree[idx * 2], segtree[idx * 2 + 1]);
- }
- int query(int idx, int l, int r, int ql, int qr) {
- if (lazy[idx] != 0) apply_lazy(idx, l, r);
- if (ql > r || qr < l) return 0;
- if (ql <= l && r <= qr) return segtree[idx];
- int m = (l + r) / 2;
- return merge(query(idx * 2, l, m, ql, qr), query(idx * 2 + 1, m + 1, r, ql, qr));
- }
- void up_pro(int idx, int l, int r, int ql, int qr, int val) {
- if (lazy[idx] != 0) apply_lazy(idx, l, r);
- if (ql > r || qr < l) return;
- if (ql <= l && r <= qr) {
- lazy[idx] = val;
- apply_lazy(idx, l, r);
- return;
- }
- int m = (l + r) / 2;
- update(idx * 2, l, m, ql, qr, val);
- update(idx * 2 + 1, m + 1, r, ql, qr, val);
- segtree[idx] = merge(segtree[idx * 2], segtree[idx * 2 + 1]);
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int tt;
- cin >> tt;
- while (tt--) {
- int n, k;
- cin >> n >> k;
- build(1, 1, 50);
- vector<pair<int, int>> vec;
- for (int i = 0; i < n; i++) {
- int l, r;
- cin >> l >> r;
- if (l <= k && k <= r) {
- vec.push_back({l, r});
- update(1, 1, 50, l, r, 1);
- }
- }
- // for (int i = 0; i < n; i++) {
- // int l = vec[i].first;
- // int r = vec[i].second;
- // if (l <= k && k <= r) {
- // continue;
- // }
- // update(1, 1, 50, l, r, -1);
- // }
- int mx1 = query(1, 1, 50, k, k);
- up_pro(1, 1, 50, k, k, -1);
- int check = -1;
- for (int i = 0; i < vec.size(); i++) {
- int l = vec[i].first;
- int r = vec[i].second;
- check = max(check, query(1, 1, 50, l, r));
- }
- // cout << mx1 << " " << check << endl;
- if (mx1 > check && check != -1) {
- cout << "YES" << '\n';
- } else {
- cout << "NO" << '\n';
- }
- memset(a, 0, sizeof(a));
- memset(lazy, 0, sizeof(lazy));
- memset(segtree, 0, sizeof(segtree));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement