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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| #include<bits/stdc++.h>
using namespace std;
const int N =2e5+5,inf = 0x3f3f3f3f;
vector<int> v; int find(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); }
struct node{ int l,r; int low,h1,h2,b; int sz; }tr[N<<4];
void build(int u,int l,int r) { tr[u]={l,r,-1, -1, -1, inf, 0}; if(l==r) return ; else { int mid=l+r>>1; build(u<<1,l,mid); build(u<<1|1,mid+1,r); } }
void pushup(node &u,node &left,node &right) { u.sz=left.sz+right.sz; if(left.sz) u.low=left.low; else u.low=right.low; int h[4]={left.h2,left.h1,right.h1,right.h2}; sort(h,h+4); u.h2=h[2]; u.h1=h[3]; u.b = min(left.b, right.b); if(left.sz and right.sz) u.b=min(u.b,v[right.low]-v[left.h1]); } void pushup(int u) { pushup(tr[u],tr[u<<1],tr[u<<1|1]); }
void modify(int u,int x,int c) { if(tr[u].l==x&&tr[u].r==x) { tr[u].sz+=c; if(tr[u].sz<=0){ tr[u].low=-1,tr[u].h1=-1,tr[u].h2=-1; tr[u].b=inf; } else if(tr[u].sz==1) { tr[u].low=x,tr[u].h1=x,tr[u].h2=-1,tr[u].b=inf; } else { tr[u].b=0; tr[u].h1=x,tr[u].h2=x,tr[u].low=x; } return ; } int mid=tr[u].l+tr[u].r>>1; if(x<=mid) modify(u<<1,x,c); else modify(u<<1|1,x,c); pushup(u); } node query(int u,int l,int r) { if(tr[u].l>=l&&tr[u].r<=r) return tr[u]; else { int mid=tr[u].l+tr[u].r>>1; if(r<=mid) return query(u<<1,l,r); else if(l>mid) return query(u<<1|1,l,r); else { auto q1=query(u<<1,l,r); auto q2=query(u<<1|1,l,r); node res; pushup(res,q1,q2); return res; } } }
int main() { int op[N],x[N]; int q; cin>>q; for(int i=1;i<=q;i++) { cin>>op[i]>>x[i]; v.push_back(x[i]); } v.push_back(-1); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); build(1,0,v.size()-1); for(int i=1;i<=q;i++) { if(op[i]==1) { modify(1,find(x[i]),1); continue; } else if(op[i]==2) { modify(1,find(x[i]),-1); continue; } else { node q1=query(1,0,find(x[i])-1); if(q1.sz>=2&&v[q1.h1]+v[q1.h2]>x[i]) { cout<<"Yes"<<endl; continue; } node q2=query(1,find(x[i]),v.size()-1); if(q2.sz) { q1.b=inf; node res; pushup(res,q1,q2); if(res.b<x[i]) { cout<<"Yes"<<endl; continue; } } cout<<"No"<<endl; } } }
|