Problem:
Queries with Six Inequeties
四つの整数の組
(a,b,c,d)
の集合が与えられます。
j
番目のクエリでは、
x_j < a_i < y_j < b_i
かつ
z_j < c_i < w_j < d_i
なる
i
が存在するか判定します。
入力
N Q
a_1 b_1 c_1 d_1
a_2 b_2 c_2 d_2
:
a_n b_n c_n d_n
x_1 y_1 z_1 w_1
x_2 y_2 z_2 w_2
:
x_q y_q z_q w_q
出力
ans_1
ans_2
:
ans_q
j
行目には、
j
番目のクエリに対する答えを出力せよ。
条件を満たす添字
i
が存在するなら
Yes
、存在しないなら
No
を出力する。
制約
1 \leq N,Q \leq 10^5
1 \leq a_i < b_i \leq 10^5
1 \leq c_i < d_i \leq 10^5
1 \leq x_j < y_j \leq 10^5
1 \leq z_j < w_j \leq 10^5
入力例
2 2
14 86 9 121
3 34 3 34
1 14 5 14
1 9 1 9
出力例
No
Yes

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<PP> vpp;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pb emplace_back
const ll mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){for(auto x:v)outv(x);}
template<class T> void outp(T p){cout<<'('<<p.fi<<','<<p.se<<')'<<endl;}
template<class T> void outvp(T v){for(auto p:v)cout<<'('<<p.fi<<','<<p.se<<')';cout<<endl;}
const ll inf=1001001001001001001;

class segtree{
    vi seg;ll N=1;
public:
    ll g=-inf;
    ll f(ll a,ll b){
        return max(a,b);
    }
    segtree(ll n,ll k){
        while(N<n)N*=2;
        seg=vi(N*2-1,g);
        rep(i,n)seg[i+N-1]=k;
        for(ll i=N-2;i>=0;i--)seg[i]=f(seg[i*2+1],seg[i*2+2]);
    }
    segtree(vi v){
        while(N<v.size())N*=2;
        seg=vi(N*2-1,g);
        rep(i,v.size())seg[i+N-1]=v[i];
        for(ll i=N-2;i>=0;i--)seg[i]=f(seg[i*2+1],seg[i*2+2]);
    }
    void add(ll i,ll x){
        i+=N-1;
        seg[i]+=x;
        while(i>0){
            i=(i-1)/2;
            seg[i]=f(seg[i*2+1],seg[i*2+2]);
        }
    }
    void update(ll i,ll x){
        i+=N-1;
        seg[i]=x;
        while(i>0){
            i=(i-1)/2;
            seg[i]=f(seg[i*2+1],seg[i*2+2]);
        }
    }
    ll get(ll l,ll r){
        ll res=g;
        l+=N-1;r+=N-1;
        while(l<r){
            if(!(l&1))res=f(res,seg[l]);
            if(!(r&1))res=f(res,seg[r-1]);
            l=l>>1;
            r=(r-1)>>1;
        }
        return res;
    }
    void debug(ll n){
        rep(i,n)cout<<' '<<seg[i+N-1];cout<<endl;
    }
};
int main(){
    ll mx=100005;
    ll n,q;cin>>n>>q;
    vvi v(n,vi(4));rep(i,n)rep(j,4)cin>>v[i][j];
    vvi query(q,vi(4));rep(i,q)rep(j,4)cin>>query[i][j];
    vvp al(mx);
    rep(i,n)al[v[i][0]].pb(i,0);
    rep(i,q)al[query[i][0]].pb(i,1);
    queue<P> que;que.push(P(0,mx));
    vp srtc(n);
    rep(i,n)srtc[i]=P(v[i][2],i);
    sort(all(srtc));
    segtree seg(n,-inf);
    vb ans(q,false);
    while(!que.empty()){
        ll l,r;tie(l,r)=que.front();que.pop();
        if(r-l<=1)continue;
        ll md=(l+r)/2;
        vpp srt;
        REP(i,l,md)for(auto x:al[i])if(x.se)srt.pb(query[x.fi][1],1,x.fi);
        REP(i,md,r)for(auto x:al[i])if(!x.se){
            srt.pb(v[x.fi][0],2,x.fi);srt.pb(v[x.fi][1],0,x.fi);
        }
        sort(all(srt));
        for(auto x:srt){
            ll i=get<2>(x);
            // cout<<get<1>(x)<<' '<<i<<endl;
            if(get<1>(x)==2)seg.update(lb(srtc,P(v[i][2],i)),v[i][3]);
            if(get<1>(x)==0)seg.update(lb(srtc,P(v[i][2],i)),-inf);
            if(get<1>(x)==1){
                ll ma=seg.get(lb(srtc,P(query[i][2],inf)),lb(srtc,P(query[i][3],-inf)));
                // out(ma);
                if(ma>query[i][3])ans[i]=true;
            }
        }
        que.push(P(l,md));que.push(P(md,r));
    }
    for(auto x:ans){
        if(x)out("Yes");
        else out("No");
    }
}
accuracy: 1
time_ms: 980
memory_kb: 45360
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<PP> vpp;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pb emplace_back
const ll mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){for(auto x:v)outv(x);}
template<class T> void outp(T p){cout<<'('<<p.fi<<','<<p.se<<')'<<endl;}
template<class T> void outvp(T v){for(auto p:v)cout<<'('<<p.fi<<','<<p.se<<')';cout<<endl;}
const ll inf=1001001001001001001;

class segtree{
    vi seg;ll N=1;
public:
    ll g=-inf;
    ll f(ll a,ll b){
        return max(a,b);
    }
    segtree(ll n,ll k){
        while(N<n)N*=2;
        seg=vi(N*2-1,g);
        rep(i,n)seg[i+N-1]=k;
        for(ll i=N-2;i>=0;i--)seg[i]=f(seg[i*2+1],seg[i*2+2]);
    }
    segtree(vi v){
        while(N<v.size())N*=2;
        seg=vi(N*2-1,g);
        rep(i,v.size())seg[i+N-1]=v[i];
        for(ll i=N-2;i>=0;i--)seg[i]=f(seg[i*2+1],seg[i*2+2]);
    }
    void add(ll i,ll x){
        i+=N-1;
        seg[i]+=x;
        while(i>0){
            i=(i-1)/2;
            seg[i]=f(seg[i*2+1],seg[i*2+2]);
        }
    }
    void update(ll i,ll x){
        i+=N-1;
        seg[i]=x;
        while(i>0){
            i=(i-1)/2;
            seg[i]=f(seg[i*2+1],seg[i*2+2]);
        }
    }
    ll get(ll l,ll r){
        ll res=g;
        l+=N-1;r+=N-1;
        while(l<r){
            if(!(l&1))res=f(res,seg[l]);
            if(!(r&1))res=f(res,seg[r-1]);
            l=l>>1;
            r=(r-1)>>1;
        }
        return res;
    }
    void debug(ll n){
        rep(i,n)cout<<' '<<seg[i+N-1];cout<<endl;
    }
};
int main(){
    ll mx=100005;
    ll n,q;cin>>n>>q;
    vvi v(n,vi(4));rep(i,n)rep(j,4)cin>>v[i][j];
    vvi query(q,vi(4));rep(i,q)rep(j,4)cin>>query[i][j];
    vvp al(mx);
    rep(i,n)al[v[i][0]].pb(i,0);
    rep(i,q)al[query[i][0]].pb(i,1);
    queue<P> que;que.push(P(0,mx));
    vp srtc(n);
    rep(i,n)srtc[i]=P(v[i][2],i);
    sort(all(srtc));
    segtree seg(n,-inf);
    vb ans(q,false);
    while(!que.empty()){
        ll l,r;tie(l,r)=que.front();que.pop();
        if(r-l<=1)break;
        ll md=(l+r)/2;
        vpp srt;
        REP(i,l,md)for(auto x:al[i])if(x.se)srt.pb(query[x.fi][1],1,x.fi);
        REP(i,md,r)for(auto x:al[i])if(!x.se){
            srt.pb(v[x.fi][0],2,x.fi);srt.pb(v[x.fi][1],0,x.fi);
        }
        sort(all(srt));
        for(auto x:srt){
            ll i=get<2>(x);
            // cout<<get<1>(x)<<' '<<i<<endl;
            if(get<1>(x)==2)seg.update(lb(srtc,P(v[i][2],i)),v[i][3]);
            if(get<1>(x)==0)seg.update(lb(srtc,P(v[i][2],i)),-inf);
            if(get<1>(x)==1){
                ll ma=seg.get(lb(srtc,P(query[i][2],inf)),lb(srtc,P(query[i][3],-inf)));
                // out(ma);
                if(ma>query[i][3])ans[i]=true;
            }
        }
        que.push(P(l,md));que.push(P(md,r));
    }
    for(auto x:ans){
        if(x)out("Yes");
        else out("No");
    }
}
accuracy: 0.2
time_ms: 680
memory_kb: 32844
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<PP> vpp;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pb emplace_back
const ll mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){for(auto x:v)outv(x);}
template<class T> void outp(T p){cout<<'('<<p.fi<<','<<p.se<<')'<<endl;}
template<class T> void outvp(T v){for(auto p:v)cout<<'('<<p.fi<<','<<p.se<<')';cout<<endl;}
const ll inf=1001001001001001001;

class segtree{
    ll N=1;vi seg;
public:
    segtree(ll n){
        while(N<n)N*=2;
        seg=vi(N*2-1,-inf);
    }
    void update(ll i,ll x){
        i+=N-1;
        seg[i]=x;
        while(i>0){
            i=(i-1)>>1;
            seg[i]=max(seg[i*2+1],seg[i*2+2]);
        }
    }
    ll get(ll l,ll r){
        l+=N-1;r+=N-1;
        ll res=-inf;
        while(l<r){
            if(!(l&1))chmax(res,seg[l]);
            if(!(r&1))chmax(res,seg[r-1]);
            l>>=1;r=(r-1)>>1;
        }
        return res;
    }
};
int main(){
    ll mx=100005;
    ll n,q;cin>>n>>q;
    vvi v(n,vi(4));rep(i,n)rep(j,4)cin>>v[i][j];
    vvi query(q,vi(4));rep(i,q)rep(j,4)cin>>query[i][j];
    vvp al(mx);
    rep(i,n)al[v[i][0]].pb(i,0);
    rep(i,q)al[query[i][0]].pb(i,1);
    queue<P> que;que.push(P(0,mx));
    vp srtc(n);
    rep(i,n)srtc[i]=P(v[i][2],i);
    sort(all(srtc));
    segtree seg(n);
    vb ans(q,false);
    while(!que.empty()){
        ll l,r;tie(l,r)=que.front();que.pop();
        if(r-l<=1)break;
        ll md=(l+r)/2;
        vpp srt;
        REP(i,l,md)for(auto x:al[i])if(x.se)srt.pb(query[x.fi][1],1,x.fi);
        REP(i,md,r)for(auto x:al[i])if(!x.se){
            srt.pb(v[x.fi][0],2,x.fi);srt.pb(v[x.fi][1],0,x.fi);
        }
        sort(all(srt));
        for(auto x:srt){
            ll i=get<2>(x);
            // cout<<get<1>(x)<<' '<<i<<endl;
            if(get<1>(x)==2)seg.update(lb(srtc,P(v[i][2],i)),v[i][3]);
            if(get<1>(x)==0)seg.update(lb(srtc,P(v[i][2],i)),-inf);
            if(get<1>(x)==1){
                ll ma=seg.get(lb(srtc,P(query[i][2],inf)),lb(srtc,P(query[i][3],-inf)));
                // out(ma);
                if(ma>query[i][3])ans[i]=true;
            }
        }
        que.push(P(l,md));que.push(P(md,r));
    }
    for(auto x:ans){
        if(x)out("Yes");
        else out("No");
    }
}
accuracy: 0.2
time_ms: 700
memory_kb: 32936
final_rank: 20

code_snippet: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Monoid>
struct RMQ {
  RMQ(int sz, const Monoid UNITY) : UNITY(UNITY) {
    init(sz);
    dat.assign((n << 1) - 1, UNITY);
  }

  RMQ(const vector<Monoid> &a, const Monoid UNITY) : UNITY(UNITY) {
    int a_sz = a.size();
    init(a_sz);
    dat.resize((n << 1) - 1);
    REP(i, a_sz) dat[n - 1 + i] = a[i];
    for (int i = n - 2; i >= 0; --i) dat[i] = max(dat[(i << 1) + 1], dat[(i << 1) + 2]);
  }

  void update(int node, Monoid val) {
    node += n - 1;
    dat[node] = val;
    while (node > 0) {
      node = (node - 1) >> 1;
      dat[node] = max(dat[(node << 1) + 1], dat[(node << 1) + 2]);
    }
  }

  Monoid query(int a, int b) { return query(a, b, 0, 0, n); }

  int find(int a, int b, Monoid val) { return find(a, b, val, 0, 0, n); }

  Monoid operator[](const int idx) const { return dat[idx + n - 1]; }

private:
  int n = 1;
  const Monoid UNITY;
  vector<Monoid> dat;

  void init(int sz) { while (n < sz) n <<= 1; }

  Monoid query(int a, int b, int node, int left, int right) {
    if (right <= a || b <= left) return UNITY;
    if (a <= left && right <= b) return dat[node];
    return max(query(a, b, (node << 1) + 1, left, (left + right) >> 1), query(a, b, (node << 1) + 2, (left + right) >> 1, right));
  }

  int find(int a, int b, Monoid val, int node, int left, int right) {
    if (dat[node] < val || right <= a || b <= left) return -1;
    if (right - left == 1) return node - (n - 1);
    int res_l = find(a, b, val, (node << 1) + 1, left, (left + right) >> 1);
    if (res_l != -1) return res_l;
    return find(a, b, val, (node << 1) + 2, (left + right) >> 1, right);
  }
};

int main() {
  const int M = 400000;
  int n, q; cin >> n >> q;
  vector<int> a(n), b(n), c(n), d(n), x(q), y(q), z(q), w(q);
  REP(i, n) cin >> a[i] >> b[i] >> c[i] >> d[i], --a[i], --b[i], --c[i], --d[i];
  REP(i, q) cin >> x[i] >> y[i] >> z[i] >> w[i], --x[i], --y[i], --z[i], --w[i];
  vector<pair<pair<int, int>, int> > fix;
  REP(i, n) {
    fix.emplace_back(make_pair(a[i], 2), i);
    fix.emplace_back(make_pair(b[i], 0), i);
  }
  REP(i, q) {
    fix.emplace_back(make_pair(x[i], 3), i);
    fix.emplace_back(make_pair(y[i], 1), i);
  }
  sort(ALL(fix));
  REP(i, fix.size()) {
    if (fix[i].first.second == 0) {
      b[fix[i].second] = i;
    } else if (fix[i].first.second == 1) {
      y[fix[i].second] = i;
    } else if (fix[i].first.second == 2) {
      a[fix[i].second] = i;
    } else if (fix[i].first.second == 3) {
      x[fix[i].second] = i;
    }
  }
  fix.clear();
  REP(i, n) {
    fix.emplace_back(make_pair(c[i], 2), i);
    fix.emplace_back(make_pair(d[i], 0), i);
  }
  REP(i, q) {
    fix.emplace_back(make_pair(z[i], 3), i);
    fix.emplace_back(make_pair(w[i], 1), i);
  }
  sort(ALL(fix));
  REP(i, fix.size()) {
    if (fix[i].first.second == 0) {
      d[fix[i].second] = i;
    } else if (fix[i].first.second == 1) {
      w[fix[i].second] = i;
    } else if (fix[i].first.second == 2) {
      c[fix[i].second] = i;
    } else if (fix[i].first.second == 3) {
      z[fix[i].second] = i;
    }
  }
  vector<int> x_pos(M, -1), a_pos(M, -1);
  REP(i, n) a_pos[a[i]] = i;
  REP(i, q) x_pos[x[i]] = i;
  vector<bool> ans(q, false);
  RMQ<int> rmq(M, -INF);
  function<void(int, int)> calc = [&](int l, int r) {
    if (r <= l + 1) return;
    int mid = (l + r) / 2;
    vector<pair<int, pair<int, int> > > v;
    FOR(i, l, mid) {
      if (x_pos[i] != -1) {
        int idx = x_pos[i];
        v.emplace_back(y[idx], make_pair(1, idx));
      }
    }
    FOR(i, mid, r) {
      if (a_pos[i] != -1) {
        int idx = a_pos[i];
        v.emplace_back(a[idx], make_pair(2, idx));
        v.emplace_back(b[idx], make_pair(0, idx));
      }
    }
    sort(ALL(v));
    for (auto e : v) {
      int type, idx; tie(type, idx) = e.second;
      if (type == 0) {
        rmq.update(c[idx], -INF);
      } else if (type == 1) {
        if (rmq.query(z[idx] + 1, w[idx]) > w[idx]) ans[idx] = true;
      } else if (type == 2) {
        rmq.update(c[idx], d[idx]);
      }
    }
    calc(l, mid);
    calc(mid, r);
  };
  calc(0, M);
  REP(i, q) cout << (ans[i] ? "Yes\n" : "No\n");
  return 0;
}
accuracy: 1
time_ms: 530
memory_kb: 25708
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;
typedef pair<P, llint> E;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = -inf;
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = max(seg[i*2], seg[i*2+1]);
		}
	}

	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return -inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return max(lval, rval);
	}
	llint query(int a, int b)
	{
		if(a > b) return -inf;
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, Q;
llint a[100005], b[100005], c[100005], d[100005];
llint x[100005], y[100005], z[100005], w[100005];
bool ans[100005];

vector<llint> xvec[100005], avec[100005];
vector<P> cvec;
SegTree seg(17);
llint cpos[100005];

void calc(llint l, llint r)
{
	if(r-l+1 <= 1) return;
	llint m = (l+r)/2;
	
	vector<E> vec;
	for(int i = l; i <= m; i++){
		for(int j = 0; j < xvec[i].size(); j++){
			int id = xvec[i][j];
			vec.push_back(E(P(y[id], 2), id));
		}
	}
	for(int i = m+1; i <= r; i++){
		for(int j = 0; j < avec[i].size(); j++){
			int id = avec[i][j];
			vec.push_back(E(P(a[id], 3), id));
			vec.push_back(E(P(b[id], 1), id));
		}
	}
	sort(vec.begin(), vec.end());
	
	for(int i = 0; i < vec.size(); i++){
		int type = vec[i].first.second, id = vec[i].second;
		if(type == 1) seg.update(cpos[id], -inf);
		if(type == 3) seg.update(cpos[id], d[id]);
		if(type == 2){
			llint lb = upper_bound(cvec.begin(), cvec.end(), P(z[id], inf)) - cvec.begin();
			llint ub = lower_bound(cvec.begin(), cvec.end(), P(w[id], 0)) - cvec.begin() - 1;
			if(seg.query(lb, ub) > w[id]) ans[id] = true;
		}
	}
	calc(l, m), calc(m+1, r);
}

int main(void)
{
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
	for(int i = 1; i <= Q; i++) cin >> x[i] >> y[i] >> z[i] >> w[i];
	
	for(int i = 1; i <= n; i++) avec[a[i]].push_back(i);
	for(int i = 1; i <= Q; i++) xvec[x[i]].push_back(i);
	
	for(int i = 1; i <= n; i++) cvec.push_back(P(c[i], i));
	sort(cvec.begin(), cvec.end());
	for(int i = 0; i < cvec.size(); i++) cpos[cvec[i].second] = i;
	
	seg.init();
	
	calc(1, 100000);
	for(int i = 1; i <= Q; i++){
		if(ans[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 950
memory_kb: 69408
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;
typedef pair<P, llint> E;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = -inf;
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = max(seg[i*2], seg[i*2+1]);
		}
	}

	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return -inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return max(lval, rval);
	}
	llint query(int a, int b)
	{
		if(a > b) return -inf;
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, Q;
llint a[100005], b[100005], c[100005], d[100005];
llint x[100005], y[100005], z[100005], w[100005];
bool ans[100005];

vector<llint> xvec[100005], avec[100005];
vector<P> cvec;
SegTree seg(17);
llint cpos[100005];

void calc(llint l, llint r)
{
	if(r-l+1 <= 1) return;
	llint m = (l+r)/2;
	
	vector<E> vec;
	for(int i = l; i <= m; i++){
		for(int j = 0; j < xvec[i].size(); j++){
			int id = xvec[i][j];
			vec.push_back(E(P(y[id], 2), id));
		}
	}
	for(int i = m+1; i <= r; i++){
		for(int j = 0; j < avec[i].size(); j++){
			int id = avec[i][j];
			vec.push_back(E(P(a[id], 3), id));
			vec.push_back(E(P(b[id], 1), id));
		}
	}
	sort(vec.begin(), vec.end());
	
	for(int i = 0; i < vec.size(); i++){
		int type = vec[i].first.second, id = vec[i].second;
		if(type == 1) seg.update(cpos[c[id]], -inf);
		if(type == 3) seg.update(cpos[c[id]], d[id]);
		if(type == 2){
			llint lb = upper_bound(cvec.begin(), cvec.end(), P(z[id], inf)) - cvec.begin();
			llint ub = lower_bound(cvec.begin(), cvec.end(), P(w[id], 0)) - cvec.begin() - 1;
			//cout << l << " " << r << " " << m << " " << id << " " << lb << " " << ub << " " << seg.query(lb, ub) << " " << w[id] << endl;
			if(seg.query(lb, ub) > w[id]) ans[id] = true;
		}
	}
	calc(l, m), calc(m+1, r);
}

int main(void)
{
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
	for(int i = 1; i <= Q; i++) cin >> x[i] >> y[i] >> z[i] >> w[i];
	
	for(int i = 1; i <= n; i++) avec[a[i]].push_back(i);
	for(int i = 1; i <= Q; i++) xvec[x[i]].push_back(i);
	
	for(int i = 1; i <= n; i++) cvec.push_back(P(c[i], i));
	sort(cvec.begin(), cvec.end());
	for(int i = 0; i < cvec.size(); i++) cpos[cvec[i].second] = i;
	
	seg.init();
	
	calc(1, 100000);
	for(int i = 1; i <= Q; i++){
		if(ans[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}
accuracy: 0.2
time_ms: 570
memory_kb: 35128
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;
typedef pair<P, llint> E;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = -inf;
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = max(seg[i*2], seg[i*2+1]);
		}
	}

	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return -inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return max(lval, rval);
	}
	llint query(int a, int b)
	{
		if(a > b) return -inf;
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, Q;
llint a[100005], b[100005], c[100005], d[100005];
llint x[100005], y[100005], z[100005], w[100005];
bool ans[100005];

vector<llint> xvec[100005], avec[100005];
vector<P> cvec;
SegTree seg(17);
llint cpos[100005];

void calc(llint l, llint r)
{
	if(r-l+1 <= 1) return;
	llint m = (l+r)/2;
	
	vector<E> vec;
	for(int i = l; i <= m; i++){
		for(int j = 0; j < xvec[i].size(); j++){
			int id = xvec[i][j];
			vec.push_back(E(P(y[id], 2), id));
		}
	}
	for(int i = m+1; i <= r; i++){
		for(int j = 0; j < avec[i].size(); j++){
			int id = avec[i][j];
			vec.push_back(E(P(a[id], 3), id));
			vec.push_back(E(P(b[id], 1), id));
		}
	}
	sort(vec.begin(), vec.end());
	
	for(int i = 0; i < vec.size(); i++){
		int type = vec[i].first.second, id = vec[i].second;
		if(type == 1) seg.update(cpos[c[id]], -inf);
		if(type == 3) seg.update(cpos[c[id]], d[id]);
		if(type == 2){
			llint lb = upper_bound(cvec.begin(), cvec.end(), P(z[id], inf)) - cvec.begin();
			llint ub = lower_bound(cvec.begin(), cvec.end(), P(w[id], 0)) - cvec.begin() - 1;
			if(seg.query(lb, ub) > w[id]) ans[id] = true;
		}
	}
	calc(l, m), calc(m+1, r);
}

int main(void)
{
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
	for(int i = 1; i <= Q; i++) cin >> x[i] >> y[i] >> z[i] >> w[i];
	
	for(int i = 1; i <= n; i++) xvec[x[i]].push_back(i);
	for(int i = 1; i <= Q; i++) avec[a[i]].push_back(i);
	
	for(int i = 1; i <= n; i++) cvec.push_back(P(c[i], i));
	sort(cvec.begin(), cvec.end());
	for(int i = 0; i < cvec.size(); i++) cpos[cvec[i].second] = i;
	
	seg.init();
	
	calc(1, 100000);
	for(int i = 1; i <= Q; i++){
		if(ans[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}
accuracy: 0.2
time_ms: 570
memory_kb: 35256
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;
typedef pair<P, llint> E;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = -inf;
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = max(seg[i*2], seg[i*2+1]);
		}
	}

	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return -inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return max(lval, rval);
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, Q;
llint a[100005], b[100005], c[100005], d[100005];
llint x[100005], y[100005], z[100005], w[100005];
bool ans[100005];

vector<llint> xvec[100005], avec[100005];
vector<P> cvec;
SegTree seg(17);
llint cpos[100005];

void calc(llint l, llint r)
{
	if(r-l+1 <= 1) return;
	llint m = (l+r)/2;
	
	vector<E> vec;
	for(int i = l; i <= m; i++){
		for(int j = 0; j < xvec[i].size(); j++){
			int id = xvec[i][j];
			vec.push_back(E(P(y[id], 2), id));
		}
	}
	for(int i = m+1; i <= r; i++){
		for(int j = 0; j < avec[i].size(); j++){
			int id = avec[i][j];
			vec.push_back(E(P(a[id], 3), id));
			vec.push_back(E(P(b[id], 1), id));
		}
	}
	sort(vec.begin(), vec.end());
	
	for(int i = 0; i < vec.size(); i++){
		int type = vec[i].first.second, id = vec[i].second;
		if(type == 1) seg.update(cpos[c[id]], -inf);
		if(type == 3) seg.update(cpos[c[id]], d[id]);
		if(type == 2){
			llint lb = upper_bound(cvec.begin(), cvec.end(), P(z[id], inf)) - cvec.begin();
			llint ub = lower_bound(cvec.begin(), cvec.end(), P(w[id], 0)) - cvec.begin() - 1;
			if(seg.query(lb, ub) > w[id]) ans[id] = true;
		}
	}
	calc(l, m), calc(m+1, r);
}

int main(void)
{
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
	for(int i = 1; i <= Q; i++) cin >> x[i] >> y[i] >> z[i] >> w[i];
	
	for(int i = 1; i <= n; i++) xvec[x[i]].push_back(i);
	for(int i = 1; i <= Q; i++) avec[a[i]].push_back(i);
	
	for(int i = 1; i <= n; i++) cvec.push_back(P(c[i], i));
	sort(cvec.begin(), cvec.end());
	for(int i = 0; i < cvec.size(); i++) cpos[cvec[i].second] = i;
	
	seg.init();
	
	calc(1, 100000);
	for(int i = 1; i <= Q; i++){
		if(ans[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}
accuracy: 0.2
time_ms: 580
memory_kb: 35200
final_rank: 18

code_snippet: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

// @category セグメント木 (Segment Tree)
// @title セグメント木 (Segment Tree)
// 抽象 SegmentTree (0-indexed・一点更新・区間取得)
template <typename MonoidType>
struct SegmentTree {
    using Function = function< MonoidType(MonoidType, MonoidType) >;

    // node, identity element
    int n;
    vector<MonoidType> node;
    MonoidType E0;

    // update / combine function
    Function upd_f, cmb_f;

    void build(int m, vector<MonoidType> v = vector<MonoidType>()) {
        if(v != vector<MonoidType>()) m = v.size();
        n = 1; while(n < m) n *= 2;

        node = vector<MonoidType>(2*n-1, E0);
        if(v != vector<MonoidType>()) {
            for(int i=0; i<m; i++) {
                node[n-1+i] = v[i];
            }
            for(int i=n-2; i>=0; i--) {
                node[i] = cmb_f(node[2*i+1], node[2*i+2]);
            }
        }
    }

    // initialize
    SegmentTree() {}
    SegmentTree(int n_, MonoidType E0_,
                Function upd_f_, Function cmb_f_,
                vector<MonoidType> v = vector<MonoidType>()) :
        E0(E0_), upd_f(upd_f_), cmb_f(cmb_f_) {
        build(n_, v);
    }

    // update k-th element (applied value: x)
    void update(int k, MonoidType x) {
        k += n - 1;
        node[k] = upd_f(node[k], x);
        while(k > 0) {
            k = (k - 1) / 2;
            node[k] = cmb_f(node[2*k+1], node[2*k+2]);
        }
    }

    // range query for [a, b)
    // 非再帰のアイデア: http://d.hatena.ne.jp/komiyam/20131202/1385992406
    MonoidType query(int a, int b) {
        MonoidType vl = E0, vr = E0;
        for(int l=a+n, r=b+n; l<r; l>>=1, r>>=1) {
            if(l & 1) vl = cmb_f(vl, node[(l++)-1]);
            if(r & 1) vr = cmb_f(node[(--r)-1], vr);
        }
        return cmb_f(vl, vr);
    }
};

using Rect = tuple<int, int, int, int, int>;

int main() {
    int N, M; scanf("%d%d", &N, &M);
    vector<Rect> A(N), B(M);
    for(int i=0; i<N; i++) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        A[i] = make_tuple(a, b, c, d, i);
    }
    for(int i=0; i<M; i++) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        B[i] = make_tuple(a, b, c, d, i);
    }

    SegmentTree<int> seg(100010, -INF,
                         [](int a, int b) { return b; },
                         [](int a, int b) { return max(a, b); });
    
    vector< multiset<int> > cnt(100010);
    vector<int> ans(M);
    auto solve = [&](auto&& f, int L, int R,
                     const vector<Rect> &AR, const vector<Rect>&BR) -> void {
        int mid = (L + R) / 2;
        vector<Rect> NLA, NLB, NRA, NRB;
        for(auto e : AR) {
            int a, b, c, d, k; tie(a, b, c, d, k) = e;
            if(L <= a and a < mid) NLA.emplace_back(e);
            if(mid <= a and a < R) NRA.emplace_back(e);
        }
        for(auto e : BR) {
            int a, b, c, d, k; tie(a, b, c, d, k) = e;
            if(L <= a and a < mid) NLB.emplace_back(e);
            if(mid <= a and a < R) NRB.emplace_back(e);
        }

        // priority: del, query, add
        vector< tuple<int, int, int> > queries;
        for(auto e : NLB) {
            int a, b, c, d, k; tie(a, b, c, d, k) = e;
            queries.emplace_back(b, 1, k);
        }
        for(auto e : NRA) {
            int a, b, c, d, k; tie(a, b, c, d, k) = e;
            queries.emplace_back(a, 2, k);
            queries.emplace_back(b, 0, k);
        }

        sort(queries.begin(), queries.end());
        for(auto q : queries) {
            int v, t, k; tie(v, t, k) = q;
            if(t == 0) {
                int a, b, c, d; tie(a, b, c, d, std::ignore) = A[k];
                cnt[c].erase(cnt[c].find(d));
                int val = (cnt[c].size() ? *(--cnt[c].end()) : -INF);
                seg.update(c, val);
            }
            if(t == 1) {
                int a, b, c, d; tie(a, b, c, d, std::ignore) = B[k];
                ans[k] |= (seg.query(c+1, d) > d);
            }
            if(t == 2) {
                int a, b, c, d; tie(a, b, c, d, std::ignore) = A[k];
                cnt[c].emplace(d);
                int val = *(--cnt[c].end());
                seg.update(c, val);
            }
        }

        if(R - L > 1) {
            f(f, L, mid, NLA, NLB);
            f(f, mid, R, NRA, NRB);
        }
    };

    solve(solve, 0, 100010, A, B);
    for(int i=0; i<M; i++) printf("%s\n", ans[i] ? "Yes" : "No");
    return 0;
}
accuracy: 1
time_ms: 590
memory_kb: 111872
final_rank: 5

code_snippet: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

// @category セグメント木 (Segment Tree)
// @title セグメント木 (Segment Tree)
// 抽象 SegmentTree (0-indexed・一点更新・区間取得)
template <typename MonoidType>
struct SegmentTree {
    using Function = function< MonoidType(MonoidType, MonoidType) >;

    // node, identity element
    int n;
    vector<MonoidType> node;
    MonoidType E0;

    // update / combine function
    Function upd_f, cmb_f;

    void build(int m, vector<MonoidType> v = vector<MonoidType>()) {
        if(v != vector<MonoidType>()) m = v.size();
        n = 1; while(n < m) n *= 2;

        node = vector<MonoidType>(2*n-1, E0);
        if(v != vector<MonoidType>()) {
            for(int i=0; i<m; i++) {
                node[n-1+i] = v[i];
            }
            for(int i=n-2; i>=0; i--) {
                node[i] = cmb_f(node[2*i+1], node[2*i+2]);
            }
        }
    }

    // initialize
    SegmentTree() {}
    SegmentTree(int n_, MonoidType E0_,
                Function upd_f_, Function cmb_f_,
                vector<MonoidType> v = vector<MonoidType>()) :
        E0(E0_), upd_f(upd_f_), cmb_f(cmb_f_) {
        build(n_, v);
    }

    // update k-th element (applied value: x)
    void update(int k, MonoidType x) {
        k += n - 1;
        node[k] = upd_f(node[k], x);
        while(k > 0) {
            k = (k - 1) / 2;
            node[k] = cmb_f(node[2*k+1], node[2*k+2]);
        }
    }

    // range query for [a, b)
    // 非再帰のアイデア: http://d.hatena.ne.jp/komiyam/20131202/1385992406
    MonoidType query(int a, int b) {
        MonoidType vl = E0, vr = E0;
        for(int l=a+n, r=b+n; l<r; l>>=1, r>>=1) {
            if(l & 1) vl = cmb_f(vl, node[(l++)-1]);
            if(r & 1) vr = cmb_f(node[(--r)-1], vr);
        }
        return cmb_f(vl, vr);
    }
};

using Rect = tuple<int, int, int, int, int>;

int main() {
    int N, M; scanf("%d%d", &N, &M);
    vector<Rect> A(N), B(M);
    for(int i=0; i<N; i++) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        A[i] = make_tuple(a, b, c, d, i);
    }
    for(int i=0; i<M; i++) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        B[i] = make_tuple(a, b, c, d, i);
    }

    SegmentTree<int> seg(100010, -INF,
                         [](int a, int b) { return b; },
                         [](int a, int b) { return max(a, b); });
    
    vector< multiset<int> > cnt(100010);
    vector<int> ans(M);
    auto solve = [&](auto&& f, int L, int R,
                     const vector<Rect> &AR, const vector<Rect>&BR) -> void {
        int mid = (L + R) / 2;
        vector<Rect> NLA, NLB, NRA, NRB;
        for(auto e : AR) {
            int a, b, c, d, k; tie(a, b, c, d, k) = e;
            if(L <= a and a < mid) NLA.emplace_back(e);
            if(mid <= a and a < R) NRA.emplace_back(e);
        }
        for(auto e : BR) {
            int a, b, c, d, k; tie(a, b, c, d, k) = e;
            if(L <= a and a < mid) NLB.emplace_back(e);
            if(mid <= a and a < R) NRB.emplace_back(e);
        }

        // priority: del, query, add
        vector< tuple<int, int, int> > queries;
        for(auto e : NLB) {
            int a, b, c, d, k; tie(a, b, c, d, k) = e;
            queries.emplace_back(b, 1, k);
        }
        for(auto e : NRA) {
            int a, b, c, d, k; tie(a, b, c, d, k) = e;
            queries.emplace_back(a, 2, k);
            queries.emplace_back(b, 0, k);
        }

        sort(queries.begin(), queries.end());
        for(auto q : queries) {
            int v, t, k; tie(v, t, k) = q;
            if(t == 0) {
                int a, b, c, d; tie(a, b, c, d, std::ignore) = A[k];
                cnt[c].erase(cnt[c].find(d));
                int val = (cnt[c].size() ? *(--cnt[c].end()) : -INF);
                seg.update(c, val);
            }
            if(t == 1) {
                int a, b, c, d; tie(a, b, c, d, std::ignore) = B[k];
                ans[k] |= (seg.query(c, d+1) > d);
            }
            if(t == 2) {
                int a, b, c, d; tie(a, b, c, d, std::ignore) = A[k];
                cnt[c].emplace(d);
                int val = *(--cnt[c].end());
                seg.update(c, val);
            }
        }

        if(R - L > 1) {
            f(f, L, mid, NLA, NLB);
            f(f, mid, R, NRA, NRB);
        }
    };

    solve(solve, 0, 100010, A, B);
    for(int i=0; i<M; i++) printf("%s\n", ans[i] ? "Yes" : "No");
    return 0;
}
accuracy: 0.2
time_ms: 530
memory_kb: 46044
final_rank: 17

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

using ll=long long;
//#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

#define mp make_pair
#define mt make_tuple
#define one(x) memset(x,-1,sizeof(x))
#define zero(x) memset(x,0,sizeof(x))
#ifdef LOCAL
void dmpr(ostream&os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ";
	dmpr(os,args...);
}
#define dmp2(...) dmpr(cerr,"Line:",__LINE__,##__VA_ARGS__)
#else
#define dmp2(...) void(0)
#endif

using uint=unsigned;
using ull=unsigned long long;

template<class t,size_t n>
ostream& operator<<(ostream&os,const array<t,n>&a){
	return os<<vc<t>(all(a));
}

template<int i,class T>
void print_tuple(ostream&,const T&){
}

template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
	if(i)os<<",";
	os<<get<i>(t);
	print_tuple<i+1,T,Args...>(os,t);
}

template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
	os<<"{";
	print_tuple<0,tuple<Args...>,Args...>(os,t);
	return os<<"}";
}

void print(ll x,int suc=1){
	cout<<x;
	if(suc==1)
		cout<<"\n";
	if(suc==2)
		cout<<" ";
}

ll read(){
	ll i;
	cin>>i;
	return i;
}

vi readvi(int n,int off=0){
	vi v(n);
	rep(i,n)v[i]=read()+off;
	return v;
}

template<class T>
void print(const vector<T>&v,int suc=1){
	rep(i,v.size())
		print(v[i],i==int(v.size())-1?suc:2);
}

string readString(){
	string s;
	cin>>s;
	return s;
}

template<class T>
T sq(const T& t){
	return t*t;
}

//#define CAPITAL
void yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<"\n";
	#endif
	if(ex)exit(0);
}
void no(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<"\n";
	#endif
	if(ex)exit(0);
}
void possible(bool ex=true){
	#ifdef CAPITAL
	cout<<"POSSIBLE"<<endl;
	#else
	cout<<"Possible"<<endl;
	#endif
	if(ex)exit(0);
}
void impossible(bool ex=true){
	#ifdef CAPITAL
	cout<<"IMPOSSIBLE"<<endl;
	#else
	cout<<"Impossible"<<endl;
	#endif
	if(ex)exit(0);
}

constexpr ll ten(int n){
	return n==0?1:ten(n-1)*10;
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

int topbit(signed t){
	return t==0?-1:31-__builtin_clz(t);
}
int topbit(ll t){
	return t==0?-1:63-__builtin_clzll(t);
}
int botbit(signed a){
	return a==0?32:__builtin_ctz(a);
}
int botbit(ll a){
	return a==0?64:__builtin_ctzll(a);
}
int popcount(signed t){
	return __builtin_popcount(t);
}
int popcount(ll t){
	return __builtin_popcountll(t);
}
bool ispow2(int i){
	return i&&(i&-i)==i;
}
int mask(int i){
	return (int(1)<<i)-1;
}

bool inc(int a,int b,int c){
	return a<=b&&b<=c;
}

template<class t> void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

ll rand_int(ll l, ll r) { //[l, r]
	#ifdef LOCAL
	static mt19937_64 gen;
	#else
    static random_device rd;
    static mt19937_64 gen(rd());
    #endif
    return uniform_int_distribution<ll>(l, r)(gen);
}

template<class t>
int lwb(const vc<t>&v,const t&a){
	return lower_bound(all(v),a)-v.bg;
}

//CF Global3 H
//ARC073 F
//point update
template<class T,class F>
struct SegTree{
	vc<T> buf;
	int s;
	const F f;
	const T g;
	SegTree(F ff,T gg):f(ff),g(gg){}
	void init(const vc<T>& d){
		int n=d.size();
		s=1;
		while(s<n)s*=2;
		buf.resize(s*2,g);
		rep(i,n)
			buf[i+s]=d[i];
		gnr(i,1,s)
			u(i);
	}
	SegTree(const vc<T>& d,F ff,T gg):f(ff),g(gg){
		init(d);
	}
	void u(int i){
		buf[i]=f(buf[i*2],buf[i*2+1]);
	}
	void set(int i,T t){
		i+=s;
		buf[i]=t;
		while(i>>=1)u(i);
	}
	void upd(int i,T t){
		i+=s;
		buf[i]=f(buf[i],t);
		while(i>>=1)u(i);
	}
	T get(int b,int e,int l,int r,int i){
		if(e<=l||r<=b)return g;
		if(b<=l&&r<=e)return buf[i];
		int m=(l+r)/2;
		return f(get(b,e,l,m,i*2),get(b,e,m,r,i*2+1));
	}
	T get(int b,int e){
		return get(b,e,0,s,1);
	}
};

template<class t,class F>
struct Point1D{
	SegTree<t,F> seg;
	vi pos;
	const t g;
	Point1D(F ff,t gg):seg(ff,gg),g(gg){}
	void addp(int p){
		pos.pb(p);
	}
	void init(){
		mkuni(pos);
		seg.init(vc<t>(pos.size(),g));
	}
	int idx(int p){
		return lwb(pos,p);
	}
	//void addv(int p,t v){
	void updv(int p,t v){
		seg.upd(idx(p),v);
	}
	t get(int b,int e){
		return seg.get(idx(b),idx(e));
	}
};

template<class t,class F>
struct Point2D{
	vc<Point1D<t,F>> buf;
	vi pos,xs,ys;
	const F f;
	const t g;
	int s;
	Point2D(F ff,t gg):f(ff),g(gg){}
	void addp(int x,int y){
		xs.pb(x);
		ys.pb(y);
	}
	int idx(int p){
		return lwb(pos,p);
	}
	void init(){
		pos=xs;
		mkuni(pos);
		s=1;
		while(s<(int)pos.size())s*=2;
		//buf.resize(s*2,Point1D<t,F>(f,g));
		rep(i,s*2)buf.emplace_back(f,g);
		rep(i,xs.size()){
			int j=lwb(pos,xs[i])+s;
			while(j>=1){
				buf[j].addp(ys[i]);
				j>>=1;
			}
		}
		for(auto&b:buf)b.init();
	}
	void updv(int x,int y,t v){
		int j=idx(x)+s;
		while(j>=1){
			buf[j].updv(y,v);
			j>>=1;
		}
	}
	t get(int b,int e,int p,int q,int l,int r,int i){
		if(e<=l||r<=b)return g;
		if(b<=l&&r<=e)return buf[i].get(p,q);
		int m=(l+r)/2;
		return f(get(b,e,p,q,l,m,i*2),get(b,e,p,q,m,r,i*2+1));
	}
	//[x1,x2)*[y1,y2)
	t get(int x1,int x2,int y1,int y2){
		return get(idx(x1),idx(x2),y1,y2,0,s,1);
	}
};

struct rect{
	int a,b,c,d;
	void init(){
		cin>>a>>b>>c>>d;
	}
};

struct query{
	int y,t,i;
	bool operator<(const query&q)const{
		if(y!=q.y)return y>q.y;
		return t<q.t;
	}
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n,q;cin>>n>>q;
	
	vc<rect> x(n),y(q);
	auto imax=[&](int a,int b){
		return max(a,b);
	};
	vc<query> qs;
	Point2D<int,decltype(imax)> p2(imax,-inf);
	rep(i,n){
		x[i].init();
		p2.addp(x[i].a,x[i].c);
		qs.pb({x[i].d,1,i});
	}
	rep(i,q){
		y[i].init();
		qs.pb({y[i].d,0,i});
	}
	p2.init();
	vi ans(q);
	sort(all(qs));
	for(auto z:qs){
		int i=z.i;
		if(z.t==0){
			int mx=p2.get(y[i].a+1,y[i].b,y[i].c+1,y[i].d);
			dmp(mx);
			ans[i]=y[i].b<mx;
		}else{
			p2.updv(x[i].a,x[i].c,x[i].b);
		}
	}
	rep(i,q)
		if(ans[i])
			yes(0);
		else
			no(0);
}
accuracy: 1
time_ms: 570
memory_kb: 29472
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  int n,q;
  cin>>n>>q;
  struct Point{
    int a,b,c,d;
    Point(int a,int b,int c,int d):
      a(a),b(b),c(c),d(d){}
  };

  auto cmpX=[&](Point p,Point q){return p.a<q.a;};
  auto cmpY=[&](Point p,Point q){return p.c<q.c;};

  const int BS1 = 512;
  const int BS2 = 32;
  assert(BS1 % BS2 == 0);

  vector<Point> ps;
  for(int i=0;i<n;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    ps.emplace_back(a,b,c,d);
  }

  while(ps.size()%BS1)
    ps.emplace_back(0,0,0,0);

  n=ps.size();
  sort(ps.begin(),ps.end(),cmpX);

  using P = pair<int, int>;
  vector< vector<P> > qs(n/BS2);

  vector<int> ma(n,1e6),Ma(n,0);
  vector<int> mc(n,1e6),Mc(n,0);
  for(int i=0;i<n;i+=BS1){

    for(int j=0;j<BS1;j++){
      chmin(ma[i],ps[i+j].a);
      chmax(Ma[i],ps[i+j].a);
    }

    sort(ps.begin()+i,ps.begin()+i+BS1,cmpY);
    for(int j=0;j<BS1;j+=BS2){
      auto &vp=qs[(i+j)/BS2];
      for(int k=0;k<BS2;k++){
        int z=i+j+k;
        vp.emplace_back(ps[z].b,ps[z].d);
        chmin(mc[i],ps[z].c);
        chmax(Mc[i],ps[z].c);
      }

      vp.emplace_back(-1,1e6);
      vp.emplace_back(1e6,-1);
      sort(vp.begin(),vp.end());
      vector<P> vq;
      for(auto p:vp)
        if(vq.empty()||vq.back().second>p.second)
          vq.emplace_back(p);
      vp=vq;
    }
  }


  for(int t=0;t<q;t++){
    int x,y,z,w;
    cin>>x>>y>>z>>w;

    auto check=
      [&](int k){
        return x<ps[k].a && ps[k].a<y && y<ps[k].b && z<ps[k].c && ps[k].c<w && w<ps[k].d;
      };

    int flg=0;
    for(int i=0;i<n;i+=BS1){
      if(flg) break;
      if(Ma[i]<=x) continue;
      if(y<=ma[i]) continue;

      if(x<ma[i]&&Ma[i]<y){
        for(int j=0;j<BS1;j+=BS2){
          if(Mc[i]<=z) continue;
          if(w<=mc[i]) continue;
          if(z<mc[i]&&Mc[i]<w){
            auto &vp=qs[(i+j)/BS2];
            flg|=w<lower_bound(vp.begin(),vp.end(),P(y,1e6))->second;
            continue;
          }
          for(int k=0;k<BS2;k++) flg|=check(i+j+k);
        }
        continue;
      }
      for(int j=0;j<BS1;j++) flg|=check(i+j);
    }

    const int DEBUG = 0;
    if(DEBUG){
      int flg2=0;
      for(int i=0;i<n;i++) flg2|=check(i);
      if(flg!=flg2) cerr<<flg<<" "<<flg2<<endl;
      assert(flg == flg2);
    }
    cout<<(flg?"Yes":"No")<<"\n";
  }
  cout<<flush;
  return 0;
}
accuracy: 1
time_ms: 1090
memory_kb: 7496
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  int n,q;
  cin>>n>>q;
  struct Point{
    int a,b,c,d;
    Point(int a,int b,int c,int d):
      a(a),b(b),c(c),d(d){}
  };

  auto cmpX=[&](Point p,Point q){return p.a<q.a;};
  auto cmpY=[&](Point p,Point q){return p.c<q.c;};

  const int BS1 = 256;
  const int BS2 = 16;
  assert(BS1 % BS2 == 0);

  vector<Point> ps;
  for(int i=0;i<n;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    ps.emplace_back(a,b,c,d);
  }

  while(ps.size()%BS1)
    ps.emplace_back(0,0,0,0);

  n=ps.size();
  sort(ps.begin(),ps.end(),cmpX);

  using P = pair<int, int>;
  vector< vector<P> > qs(n/BS2);

  vector<int> ma(n,1e6),Ma(n,0);
  vector<int> mc(n,1e6),Mc(n,0);
  for(int i=0;i<n;i+=BS1){

    for(int j=0;j<BS1;j++){
      chmin(ma[i],ps[i+j].a);
      chmax(Ma[i],ps[i+j].a);
    }

    sort(ps.begin()+i,ps.begin()+i+BS1,cmpY);
    for(int j=0;j<BS1;j+=BS2){
      auto &vp=qs[(i+j)/BS2];
      for(int k=0;k<BS2;k++){
        int z=i+j+k;
        vp.emplace_back(ps[z].b,ps[z].d);
        chmin(mc[i],ps[z].c);
        chmax(Mc[i],ps[z].c);
      }

      vp.emplace_back(-1,1e6);
      vp.emplace_back(1e6,-1);
      sort(vp.begin(),vp.end());
      vector<P> vq;
      for(auto p:vp)
        if(vq.empty()||vq.back().second>p.second)
          vq.emplace_back(p);
      vp=vq;
    }
  }


  for(int t=0;t<q;t++){
    int x,y,z,w;
    cin>>x>>y>>z>>w;

    auto check=
      [&](int k){
        return x<ps[k].a && ps[k].a<y && y<ps[k].b && z<ps[k].c && ps[k].c<w && w<ps[k].d;
      };

    int flg=0;
    for(int i=0;i<n;i+=BS1){
      if(flg) break;
      if(Ma[i]<=x) continue;
      if(y<=ma[i]) continue;

      if(x<ma[i]&&Ma[i]<y){
        for(int j=0;j<BS1;j+=BS2){
          if(Mc[i]<=w) continue;
          if(z<=mc[i]) continue;
          if(x<ma[i]&&Ma[i]<y){
            auto &vp=qs[(i+j)/BS2];
            flg|=w<lower_bound(vp.begin(),vp.end(),P(y,1e6))->second;
            continue;
          }
          for(int k=0;k<BS2;k++) flg|=check(i+j+k);
        }
        continue;
      }
      for(int j=0;j<BS1;j++) flg|=check(i+j);
    }
    cout<<(flg?"Yes":"No")<<"\n";
  }
  cout<<flush;
  return 0;
}
accuracy: 0.2
time_ms: 240
memory_kb: 7852
final_rank: 10

code_snippet: #include <iostream>
using namespace std;
#pragma warning (disable: 4996)

const int MAX_N = 3000000;
const int MAX_Z = 17;

struct Coordinate {
	int k1, k2, k3, k4;
};

class SegmentTree {
public:
	int sz = 1;
	int val[MAX_N];
	int chil[MAX_N][16];

	void init() {
		for (int i = 0; i < MAX_N; i++) {
			val[i] = 0;
			for (int j = 0; j < 16; j++) chil[i][j] = -1;
		}
	}

	void build(Coordinate t) {
		Coordinate cl = { 0, 0, 0, 0 };
		Coordinate cr = { (1 << MAX_Z), (1 << MAX_Z), (1 << MAX_Z), (1 << MAX_Z) };

		int cx = 0;
		for (int i = MAX_Z - 1; i >= 0; i--) {
			val[cx]++;

			Coordinate cm;
			cm.k1 = (cl.k1 + cr.k1) / 2;
			cm.k2 = (cl.k2 + cr.k2) / 2;
			cm.k3 = (cl.k3 + cr.k3) / 2;
			cm.k4 = (cl.k4 + cr.k4) / 2;

			int v = 0;
			if (t.k1 >= cm.k1) { v += 1; cl.k1 = cm.k1; } else cr.k1 = cm.k1;
			if (t.k2 >= cm.k2) { v += 2; cl.k2 = cm.k2; } else cr.k2 = cm.k2;
			if (t.k3 >= cm.k3) { v += 4; cl.k3 = cm.k3; } else cr.k3 = cm.k3;
			if (t.k4 >= cm.k4) { v += 8; cl.k4 = cm.k4; } else cr.k4 = cm.k4;

			if (chil[cx][v] == -1) { chil[cx][v] = sz; sz++; }
			cx = chil[cx][v];
		}
		val[cx]++;
	}

	int getans_(Coordinate l, Coordinate r, Coordinate a, Coordinate b, int u) {
		if (r.k1 < a.k1 || b.k1 < l.k1) return 0;
		if (r.k2 < a.k2 || b.k2 < l.k2) return 0;
		if (r.k3 < a.k3 || b.k3 < l.k3) return 0;
		if (r.k4 < a.k4 || b.k4 < l.k4) return 0;

		int cntv = 0;
		if (l.k1 <= a.k1 && b.k1 <= r.k1) cntv++;
		if (l.k2 <= a.k2 && b.k2 <= r.k2) cntv++;
		if (l.k3 <= a.k3 && b.k3 <= r.k3) cntv++;
		if (l.k4 <= a.k4 && b.k4 <= r.k4) cntv++;
		if (cntv == 4) return 1;

		for (int t = 0; t < 16; t++) {
			if (chil[u][t] == -1) continue;

			Coordinate ca, cb;
			if ((t / 1) % 2 == 0) { ca.k1 = a.k1; cb.k1 = ((a.k1 + b.k1) >> 1); }
			else { ca.k1 = ((a.k1 + b.k1) >> 1); cb.k1 = b.k1; }
			if ((t / 2) % 2 == 0) { ca.k2 = a.k2; cb.k2 = ((a.k2 + b.k2) >> 1); }
			else { ca.k2 = ((a.k2 + b.k2) >> 1); cb.k2 = b.k2; }
			if ((t / 4) % 2 == 0) { ca.k3 = a.k3; cb.k3 = ((a.k3 + b.k3) >> 1); }
			else { ca.k3 = ((a.k3 + b.k3) >> 1); cb.k3 = b.k3; }
			if ((t / 8) % 2 == 0) { ca.k4 = a.k4; cb.k4 = ((a.k4 + b.k4) >> 1); }
			else { ca.k4 = ((a.k4 + b.k4) >> 1); cb.k4 = b.k4; }

			int D = getans_(l, r, ca, cb, chil[u][t]);
			if (D == 1) return 1;
		}
		return 0;
	}
	int getans(Coordinate l, Coordinate r) {
		return getans_(l, r, Coordinate{ 0, 0, 0, 0 }, Coordinate{ (1 << MAX_Z), (1 << MAX_Z), (1 << MAX_Z), (1 << MAX_Z) }, 0);
	}
};

int N, A[1 << 18], B[1 << 18], C[1 << 18], D[1 << 18];
int Q, X[1 << 18], Y[1 << 18], Z[1 << 18], W[1 << 18];
SegmentTree V;

int main() {
	scanf("%d%d", &N, &Q);
	for (int i = 1; i <= N; i++) scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
	for (int i = 1; i <= Q; i++) scanf("%d%d%d%d", &X[i], &Y[i], &Z[i], &W[i]);

	V.init();
	for (int i = 1; i <= N; i++) {
		Coordinate Z1;
		Z1.k1 = A[i]; Z1.k2 = B[i];
		Z1.k3 = C[i]; Z1.k4 = D[i];
		V.build(Z1);
	}
	for (int i = 1; i <= Q; i++) {
		Coordinate Z1, Z2;
		Z1.k1 = X[i] + 1; Z1.k2 = Y[i] + 1; Z1.k3 = Z[i] + 1; Z1.k4 = W[i] + 1;
		Z2.k1 = Y[i]; Z2.k2 = (1 << MAX_Z); Z2.k3 = W[i]; Z2.k4 = (1 << MAX_Z);

		int E = V.getans(Z1, Z2);
		if (E == 1) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 205528
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

template<class T>
class Segtree{
	int n;
	vector<T>dat;
	T INIT;
	T E;
	function<T(T,T)>F;
public:
	Segtree(int n_,T INIT,T E,function<T(T,T)>F):INIT(INIT),E(E),F(F){
		n=1;while(n<n_)n<<=1;
		dat=vector<T>(2*n,INIT);
	}
	void set(int k,T x){
		k+=n;
		dat[k]=x;
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	T query(int l,int r){
		T resl=E,resr=E;
		for(l+=n,r+=n;l<r;l>>=1,r>>=1){
			if(l&1)resl=F(resl,dat[l++]);
			if(r&1)resr=F(dat[--r],resr);
		}
		return F(resl,resr);
	}
};

struct st{
	int ty;//0->tuple 1->query
	int a,b,c,d;
	int id;
};

vector<st>vs;

int ans[200000];

void solve(int l,int r){//[l,r)
	if(r-l<=1)return;
	int md=(l+r)/2;
	solve(l,md);
	solve(md,r);
	vector<st>qs;
	vector<int>s,e;
	for(int i=l;i<md;i++){
		if(vs[i].ty==1)qs.push_back(vs[i]);
	}
	map<int,int>mp;
	vector<int>cs;
	for(int i=md;i<r;i++){
		if(vs[i].ty==0){
			s.push_back(i);
			e.push_back(i);
			cs.push_back(vs[i].c);
			vs[i].id=mp[vs[i].c];
			mp[vs[i].c]++;
		}
	}
	if(s.empty())return;
	sort(qs.begin(),qs.end(),[](st&a,st&b){return a.b<b.b;});
	sort(e.begin(),e.end(),[&](int a,int b){return vs[a].b<vs[b].b;});
	sort(cs.begin(),cs.end());
	Segtree<int>seg(cs.size(),0,0,[](int a,int b){return max(a,b);});
	int c1=0,c2=0;
	for(auto&p:qs){
		if(ans[p.id])continue;
		while(c1<s.size()&&vs[s[c1]].a<p.b){
			int k=s[c1];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.set(idx,vs[k].d);
			c1++;
		}
		while(c2<e.size()&&vs[e[c2]].b<=p.b){
			int k=e[c2];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.set(idx,0);
			c2++;
		}
		int L=upper_bound(cs.begin(),cs.end(),p.c)-cs.begin();
		int R=lower_bound(cs.begin(),cs.end(),p.d)-cs.begin();
		if(p.d<seg.query(L,R))ans[p.id]=1;
	}
}

int main(){
	int n,q;cin>>n>>q;
	assert(1<=n&&n<=100000);
	assert(1<=q&&q<=100000);
	rep(i,n){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		assert(1<=s.a&&s.a<s.b&&s.b<=100000);
		assert(1<=s.c&&s.c<s.d&&s.d<=100000);
		s.ty=0;
		vs.push_back(s);
	}
	rep(i,q){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		assert(1<=s.a&&s.a<s.b&&s.b<=100000);
		assert(1<=s.c&&s.c<s.d&&s.d<=100000);
		s.ty=1;
		s.id=i;
		vs.push_back(s);
	}
	sort(vs.begin(),vs.end(),[](st&a,st&b){
		if(a.a==b.a)return a.ty<b.ty;
		return a.a<b.a;
	});
	solve(0,vs.size());
	rep(i,q){
		if(ans[i])puts("Yes");
		else puts("No");
	}
}
accuracy: 1
time_ms: 380
memory_kb: 14140
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

template<class T>
class Segtree{
	int n;
	vector<T>dat;
	T INIT;
	T E;
	function<T(T,T)>F;
public:
	Segtree(int n_,T INIT,T E,function<T(T,T)>F):INIT(INIT),E(E),F(F){
		n=1;while(n<n_)n<<=1;
		dat=vector<T>(2*n,INIT);
	}
	void set(int k,T x){
		k+=n;
		dat[k]=x;
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	T query(int l,int r){
		T resl=E,resr=E;
		for(l+=n,r+=n;l<r;l>>=1,r>>=1){
			if(l&1)resl=F(resl,dat[l++]);
			if(r&1)resr=F(dat[--r],resr);
		}
		return F(resl,resr);
	}
};

struct st{
	int ty;//0->tuple 1->query
	int a,b,c,d;
	int id;
};

vector<st>vs;

int ans[200000];

void solve(int l,int r){//[l,r)
	if(r-l<=1)return;
	int md=(l+r)/2;
	solve(l,md);
	solve(md,r);
	vector<st>qs;
	vector<int>s,e;
	for(int i=l;i<md;i++){
		if(vs[i].ty==1)qs.push_back(vs[i]);
	}
	map<int,int>mp;
	vector<int>cs;
	for(int i=md;i<r;i++){
		if(vs[i].ty==0){
			s.push_back(i);
			e.push_back(i);
			cs.push_back(vs[i].c);
			vs[i].id=mp[vs[i].c];
			mp[vs[i].c]++;
		}
	}
	if(s.empty())return;
	sort(qs.begin(),qs.end(),[](st&a,st&b){return a.b<b.b;});
	sort(e.begin(),e.end(),[&](int a,int b){return vs[a].b<vs[b].b;});
	sort(cs.begin(),cs.end());
	Segtree<int>seg(cs.size(),0,0,[](int a,int b){return max(a,b);});
	int c1=0,c2=0;
	for(auto&p:qs){
		if(ans[p.id])continue;
		while(c1<s.size()&&vs[s[c1]].a<p.b){
			int k=s[c1];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.set(idx,vs[k].d);
			c1++;
		}
		while(c2<e.size()&&vs[e[c2]].b<=p.b){
			int k=e[c2];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.set(idx,0);
			c2++;
		}
		int L=upper_bound(cs.begin(),cs.end(),p.c)-cs.begin();
		int R=lower_bound(cs.begin(),cs.end(),p.d)-cs.begin();
		if(p.d<seg.query(L,R))ans[p.id]=1;
	}
}

int main(){
	int n,q;cin>>n>>q;
	rep(i,n){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		s.ty=0;
		vs.push_back(s);
	}
	rep(i,q){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		s.ty=1;
		s.id=i;
		vs.push_back(s);
	}
	sort(vs.begin(),vs.end(),[](st&a,st&b){
		if(a.a==b.a)return a.ty<b.ty;
		return a.a<b.a;
	});
	solve(0,vs.size());
	rep(i,q){
		if(ans[i])puts("Yes");
		else puts("No");
	}
}
accuracy: 1
time_ms: 380
memory_kb: 14148
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

template<class T>
class Segtree{
	int n;
	vector<T>dat;
	T INIT;
	T E;
	function<T(T,T)>F;
public:
	Segtree(int n_,T INIT,T E,function<T(T,T)>F):INIT(INIT),E(E),F(F){
		n=1;while(n<n_)n<<=1;
		dat=vector<T>(2*n,INIT);
	}
	void set(int k,T x){
		k+=n;
		dat[k]=x;
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	T query(int l,int r){
		T resl=E,resr=E;
		for(l+=n,r+=n;l<r;l>>=1,r>>=1){
			if(l&1)resl=F(resl,dat[l++]);
			if(r&1)resr=F(dat[--r],resr);
		}
		return F(resl,resr);
	}
};

struct st{
	int ty;//0->tuple 1->query
	int a,b,c,d;
	int id;
};

vector<st>vs;

int ans[200000];

void solve(int l,int r){//[l,r)
	if(r-l<=1)return;
	int md=(l+r)/2;
	solve(l,md);
	solve(md,r);
	vector<st>qs;
	vector<int>s,e;
	for(int i=l;i<md;i++){
		if(vs[i].ty==1)qs.push_back(vs[i]);
	}
	map<int,int>mp;
	vector<int>cs;
	for(int i=md;i<r;i++){
		if(vs[i].ty==0){
			s.push_back(i);
			e.push_back(i);
			cs.push_back(vs[i].c);
			vs[i].id=mp[vs[i].c];
			mp[vs[i].c]++;
		}
	}
	if(s.empty())return;
	sort(qs.begin(),qs.end(),[](st&a,st&b){return a.b<b.b;});
	sort(e.begin(),e.end(),[&](int a,int b){return vs[a].b<vs[b].b;});
	sort(cs.begin(),cs.end());
	Segtree<int>seg(cs.size(),0,0,[](int a,int b){return max(a,b);});
	int c1=0,c2=0;
	for(auto&p:qs){
		if(ans[p.id])continue;
		while(c1<s.size()&&vs[s[c1]].a<p.b){
			int k=s[c1];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.set(idx,vs[k].d);
			c1++;
		}
		while(c2<e.size()&&vs[e[c2]].b<=p.b){
			int k=e[c2];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.set(idx,0);
			c2++;
		}
		int L=upper_bound(cs.begin(),cs.end(),p.c)-cs.begin();
		int R=lower_bound(cs.begin(),cs.end(),p.d)-cs.begin();
		if(p.d<seg.query(L,R))ans[p.id]=1;
	}
}

int main(){
	int n,q;cin>>n>>q;
	rep(i,n){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		assert(s.a<s.b);
		assert(s.c<s.d);
		s.ty=0;
		vs.push_back(s);
	}
	rep(i,q){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		assert(s.a<s.b);
		assert(s.c<s.d);
		s.ty=1;
		s.id=i;
		vs.push_back(s);
	}
	sort(vs.begin(),vs.end(),[](st&a,st&b){
		return a.a<b.a;
	});
	solve(0,vs.size());
	rep(i,q){
		if(ans[i])puts("Yes");
		else puts("No");
	}
}
accuracy: 0.2
time_ms: 260
memory_kb: 10520
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

template<class T>
class Segtree{
	int n;
	vector<T>dat;
	T INIT;
	T E;
	function<T(T,T)>F;
public:
	Segtree(int n_,T INIT,T E,function<T(T,T)>F):INIT(INIT),E(E),F(F){
		n=1;while(n<n_)n<<=1;
		dat=vector<T>(2*n,INIT);
	}
	void set(int k,T x){
		k+=n;
		dat[k]=x;
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	void update(int k,T x){
		k+=n;
		dat[k]=F(dat[k],x);
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	T query(int l,int r){
		T resl=E,resr=E;
		for(l+=n,r+=n;l<r;l>>=1,r>>=1){
			if(l&1)resl=F(resl,dat[l++]);
			if(r&1)resr=F(dat[--r],resr);
		}
		return F(resl,resr);
	}
};

struct st{
	int ty;//0->tuple 1->query
	int a,b,c,d;
	int id;
};

vector<st>vs;

int ans[200000];

void solve(int l,int r){//[l,r)
	if(r-l<=1)return;
	int md=(l+r)/2;
	solve(l,md);
	solve(md,r);
	vector<st>qs;
	vector<int>s,e;
	for(int i=l;i<md;i++){
		if(vs[i].ty==1)qs.push_back(vs[i]);
	}
	map<int,int>mp;
	vector<int>cs;
	for(int i=md;i<r;i++){
		if(vs[i].ty==0){
			s.push_back(i);
			e.push_back(i);
			cs.push_back(vs[i].c);
			vs[i].id=mp[vs[i].c];
			mp[vs[i].c]++;
		}
	}
	if(s.empty())return;
	sort(qs.begin(),qs.end(),[](st&a,st&b){return a.b<b.b;});
	sort(e.begin(),e.end(),[&](int a,int b){return vs[a].b<vs[b].b;});
	sort(cs.begin(),cs.end());
	Segtree<int>seg(cs.size(),INT_MIN,INT_MIN,[](int a,int b){return max(a,b);});
	int c1=0,c2=0;
	for(auto&p:qs){
		if(ans[p.id])continue;
		while(c1<s.size()&&vs[s[c1]].a<p.b){
			int k=s[c1];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.set(idx,vs[k].d);
			c1++;
		}
		while(c2<e.size()&&vs[e[c2]].b<=p.b){
			int k=e[c2];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.set(idx,INT_MIN);
			c2++;
		}
		int L=upper_bound(cs.begin(),cs.end(),p.c)-cs.begin();
		int R=lower_bound(cs.begin(),cs.end(),p.d)-cs.begin();
		if(p.d<seg.query(L,R))ans[p.id]=1;
	}
}

int main(){
	int n,q;cin>>n>>q;
	rep(i,n){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		s.ty=0;
		vs.push_back(s);
	}
	rep(i,q){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		s.ty=1;
		s.id=i;
		vs.push_back(s);
	}
	sort(vs.begin(),vs.end(),[](st&a,st&b){
		return a.a<b.a;
	});
	solve(0,vs.size());
	rep(i,q){
		if(ans[i])puts("Yes");
		else puts("No");
	}
}
accuracy: 0.2
time_ms: 270
memory_kb: 10568
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

template<class T>
class Segtree{
	int n;
	vector<T>dat;
	T INIT;
	T E;
	function<T(T,T)>F;
public:
	Segtree(int n_,T INIT,T E,function<T(T,T)>F):INIT(INIT),E(E),F(F){
		n=1;while(n<n_)n<<=1;
		dat=vector<T>(2*n,INIT);
	}
	void set(int k,T x){
		k+=n;
		dat[k]=x;
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	void update(int k,T x){
		k+=n;
		dat[k]=F(dat[k],x);
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	T query(int l,int r){
		T resl=E,resr=E;
		for(l+=n,r+=n;l<r;l>>=1,r>>=1){
			if(l&1)resl=F(resl,dat[l++]);
			if(r&1)resr=F(dat[--r],resr);
		}
		return F(resl,resr);
	}
};

struct st{
	int ty;//0->tuple 1->query
	int a,b,c,d;
	int id;
};

vector<st>vs;

int ans[200000];

void solve(int l,int r){//[l,r)
	if(r-l<=1)return;
	int md=(l+r)/2;
	solve(l,md);
	solve(md,r);
	vector<st>qs;
	vector<int>s,e;
	for(int i=l;i<md;i++){
		if(vs[i].ty==1)qs.push_back(vs[i]);
	}
	map<int,int>mp;
	vector<int>cs;
	for(int i=md;i<r;i++){
		if(vs[i].ty==0){
			s.push_back(i);
			e.push_back(i);
			cs.push_back(vs[i].c);
			vs[i].id=mp[vs[i].c]++;
		}
	}
	if(s.empty())return;
	sort(qs.begin(),qs.end(),[](st&a,st&b){return a.b<b.b;});
	sort(e.begin(),e.end(),[&](int a,int b){return vs[a].b<vs[b].b;});
	sort(cs.begin(),cs.end());
	Segtree<int>seg(cs.size(),INT_MIN,INT_MIN,[](int a,int b){return max(a,b);});
	int c1=0,c2=0;
	for(auto&p:qs){
		if(ans[p.id])continue;
		while(c1<s.size()&&vs[s[c1]].a<p.b){
			int k=s[c1];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.update(idx,vs[k].d);
			c1++;
		}
		while(c2<e.size()&&vs[e[c2]].b<=p.b){
			int k=e[c2];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.update(idx,INT_MIN);
			c2++;
		}
		int L=upper_bound(cs.begin(),cs.end(),p.c)-cs.begin();
		int R=lower_bound(cs.begin(),cs.end(),p.d)-cs.begin();
		if(p.d<seg.query(L,R))ans[p.id]=1;
	}
}

int main(){
	int n,q;cin>>n>>q;
	rep(i,n){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		s.ty=0;
		vs.push_back(s);
	}
	rep(i,q){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		s.ty=1;
		s.id=i;
		vs.push_back(s);
	}
	sort(vs.begin(),vs.end(),[](st&a,st&b){
		return a.a<b.a;
	});
	solve(0,vs.size());
	rep(i,q){
		if(ans[i])puts("Yes");
		else puts("No");
	}
}
accuracy: 0.2
time_ms: 240
memory_kb: 10524
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

template<class T>
class Segtree{
	int n;
	vector<T>dat;
	T INIT;
	T E;
	function<T(T,T)>F;
public:
	Segtree(int n_,T INIT,T E,function<T(T,T)>F):INIT(INIT),E(E),F(F){
		n=1;while(n<n_)n<<=1;
		dat=vector<T>(2*n,INIT);
	}
	void set(int k,T x){
		k+=n;
		dat[k]=x;
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	void update(int k,T x){
		k+=n;
		dat[k]=F(dat[k],x);
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	T query(int l,int r){
		T resl=E,resr=E;
		for(l+=n,r+=n;l<r;l>>=1,r>>=1){
			if(l&1)resl=F(resl,dat[l++]);
			if(r&1)resr=F(dat[--r],resr);
		}
		return F(resl,resr);
	}
};

struct st{
	int ty;//0->tuple 1->query
	int a,b,c,d;
	int id;
};

vector<st>vs;

int ans[200000];

void solve(int l,int r){//[l,r)
	if(r-l<=1)return;
	int md=(l+r)/2;
	solve(l,md);
	solve(md,r);
	vector<st>qs;
	vector<int>s,e;
	for(int i=l;i<md;i++){
		if(vs[i].ty==1)qs.push_back(vs[i]);
	}
	map<int,int>mp;
	vector<int>cs;
	for(int i=md;i<r;i++){
		if(vs[i].ty==0){
			s.push_back(i);
			e.push_back(i);
			cs.push_back(vs[i].c);
			vs[i].id=mp[vs[i].c]++;
		}
	}
	if(s.empty())return;
	sort(qs.begin(),qs.end(),[](st&a,st&b){return a.b<b.b;});
	sort(e.begin(),e.end(),[&](int a,int b){return vs[a].b<vs[b].b;});
	sort(cs.begin(),cs.end());
	Segtree<int>seg(cs.size(),INT_MIN,INT_MIN,[](int a,int b){return max(a,b);});
	int c1=0,c2=0;
	for(auto&p:qs){
		if(ans[p.id])continue;
		while(c1<s.size()&&vs[s[c1]].a<p.b){
			int k=s[c1];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.update(idx,vs[k].d);
			c1++;
		}
		while(c2<e.size()&&vs[e[c2]].b<=p.b){
			int k=s[c2];
			int idx=lower_bound(cs.begin(),cs.end(),vs[k].c)-cs.begin()+vs[k].id;
			seg.update(idx,INT_MIN);
			c2++;
		}
		int L=upper_bound(cs.begin(),cs.end(),p.c)-cs.begin();
		int R=lower_bound(cs.begin(),cs.end(),p.d)-cs.begin();
		if(p.d<seg.query(L,R))ans[p.id]=1;
	}
}

int main(){
	int n,q;cin>>n>>q;
	rep(i,n){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		s.ty=0;
		vs.push_back(s);
	}
	rep(i,q){
		st s;scanf("%d%d%d%d",&s.a,&s.b,&s.c,&s.d);
		s.ty=1;
		s.id=i;
		vs.push_back(s);
	}
	sort(vs.begin(),vs.end(),[](st&a,st&b){
		return a.a<b.a;
	});
	solve(0,vs.size());
	rep(i,q){
		if(ans[i])puts("Yes");
		else puts("No");
	}
}
accuracy: 0.2
time_ms: 250
memory_kb: 10648
final_rank: 12