题解:AT_abc457_e [ABC457E] Crossing Table Cloth

· · 题解

看到很多人都在用 set、ST 表、BIT 之类的 Data-Structure 做。

这里讲一个不需要 DS 的做法。

首先,对于每个询问 [s_q,t_q],分两种情况讨论:

Code:

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;

using i128 = __int128;
using u128 = unsigned __int128;

mt19937_64 mrand((u64)random_device{}() << 32 ^ random_device{}() ^
    chrono::high_resolution_clock::now().time_since_epoch().count());
template<class T = i64,class T2>T rnd(T l,T2 r){
return uniform_int_distribution<T>(l,r)(mrand);}

int main (){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    int n,m;
    cin >> n >> m;

    vector<vector<int>> l(n + 1),r(n + 1);
    vector<int> msr(n + 2,1e9);

    for (;m--;){
        int L,R;
        cin >> L >> R;

        msr[L] = min(msr[L],R);

        l[L].push_back(R);
        r[R].push_back(L);
    }

    for (int i = n;i;i--){
        msr[i] = min(msr[i],msr[i + 1]);
        sort(l[i].begin(),l[i].end());
        sort(r[i].begin(),r[i].end());
    }

    int q;
    cin >> q;

    for (;q--;){
        int L,R;
        cin >> L >> R;

        int x = upper_bound(l[L].begin(),l[L].end(),R) - l[L].begin();
        int y = lower_bound(r[R].begin(),r[R].end(),L) - r[R].begin();

        if (x&&l[L][x - 1] == R){
            if (x > 1||y + 1 < (int)r[R].size()||msr[L] < R)
                cout << "Yes\n";
            else
                cout << "No\n";
            continue;
        }

        cout << (x&&y != (int)r[R].size()&&r[R][y] <= l[L][x - 1] + 1?"Yes":"No") << '\n';
    }
}

都看到这了还不点个赞,

那还是人吗?