codeforces D.In Love

思路

  • 用两个 m u l t i s e t multiset multiset 分别存 l , r l,r l,r你也可以写平衡树
  • l l l m u l t i s e t multiset multiset 里去查询是否存在比最小的 r r r 大的 l l l

Think Twice, Code Once

#include
#define il inline
#define get getchar
#define put putchar
#define is isdigit
#define int long long
#define dfor(i,a,b) for(int i=a;i<=b;++i)
#define dforr(i,a,b) for(int i=a;i>=b;--i)
#define dforn(i,a,b) for(int i=a;i<=b;++i,put(10))
#define mem(a,b) memset(a,b,sizeof a)
#define memc(a,b) memcpy(a,b,sizeof a)
#define pr 114514191981
#define gg(a) cout<<a,put(32)
#define INF 0x7fffffff
#define tt(x) cout<<x<<'\n'
#define ls i<<1
#define rs i<<1|1
#define la(r) tr[r].ch[0]
#define ra(r) tr[r].ch[1]
#define lowbit(x) (x&-x)
using namespace std;
typedef unsigned int ull;
typedef pair<int ,int > pii;
int read(void)
{
    int x=0,f=1;char c=get();
    while(!is(c)) (f=c==45?-1:1),c=get();
    while(is(c)) x=(x<<1)+(x<<3)+(c^48),c=get();
    return x*f;
}
void write(int x)
{
    if(x<0) x=-x,put(45);
    if(x>9) write(x/10);
    put((x%10)^48);
}
#define writeln(a) write(a),put(10)
#define writesp(a) write(a),put(32)
#define writessp(a) put(32),write(a)
const int N=1e6+10,M=3e4+10,SN=5e3+10,mod=998244353;
int n;
multiset<int > tr,tr1;
signed main()
{
    int T=read();
    string s;
    int l,r;
//    while(T--)
    dfor(i,1,T)
    {
        cin>>s;
        l=read(),r=read();
        if(s=="+") tr.insert(l),tr1.insert(r);
        else tr.erase(tr.find(l)),tr1.erase(tr1.find(r));
        auto it=tr.upper_bound(*tr1.begin());
        it!=tr.end()?puts("YES"):puts("NO");
    }
    return 0;
}

你可能感兴趣的:(codeforces题解,算法,c++,codeforces题解,思维,数据结构)