Problem:
Problem H: Zombie Hunter
Problem
がっちょ君は人気のゲーム、Zombie Hunterに熱中している。このゲームには、頭、胴、腕、腰、足専用の5種類の防具があり、がっちょ君が操作するプレイヤーキャラクター(PC)は、体の各部に対応する防具をそれぞれ最大1つまで装備することができる。
また、各防具には重さと防御力が設定されており、PCの装備している防具の重さの合計が
A
以上
B
以下であり、かつ防御力の合計も
A
以上
B
以下であるとき、そのPCはスキルを発動することができる。
がっちょ君は
N
個の防具を所持している。装備する防具を適切に選ぶことで、PCがスキルを発動することができるかを調べて欲しい。
Input
入力は以下の形式で与えられる。
N
A
B
t
1
x
1
y
1
t
2
x
2
y
2
...
t
N
x
N
y
N
入力はすべて整数で与えられる。
1行目にがっちょ君が所有している防具の数
N
, スキルの発動条件に用いられる２つの整数
A
と
B
が与えられる。
2行目から続く
N
行に、
N
個の防具の情報が与えられる。
t
i
,
x
i
,
y
i
はそれぞれ
i
番目の防具の種類、重さ、防御力を表す。
防具の種類
t
i
の値はそれぞれ、1のとき頭の防具、2のとき胴の防具、3のとき腕の防具、4のとき腰の防具、5のとき足の防具であることを示す。
Constraints
入力は以下の条件を満たす。
1 ≤
N
≤ 500
1 ≤
A
≤
B
≤ 10
12
1 ≤
t
i
≤ 5
−10
12
≤
x
i
,
y
i
≤ 10
12
Output
スキルを発動することができる場合は”Yes”、できない場合は”No”を1行に出力せよ。
Sample Input 1
7 10 11
1 1 0
1 0 1
2 2 2
3 3 5
4 1 3
5 1 3
5 5 -1
Sample Output 1
Yes
頭に(0,1)
胴に(2,2)
腕に(3,5)
腰に(1,3)
足に(5,-1)
の防具を装備すると、重さの和が 0+2+3+1+5 = 11、守備力の和が 1+2+5+3+1 = 10 となり、両方の値がA以上でかつB以下となるのでスキルを発動させることができる。
Sample Input 2
7 10 10
1 1 0
1 0 1
2 2 2
3 3 5
4 1 3
5 1 3
5 5 -1
Sample Output 2
No

Submitted solutions:

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

int n; ll a, b;
void solve() {
	vector<LP> v[5];
	rep(i, 5)v[i].push_back({ 0,0 });
	cin >> n >> a >> b;
	vector<LP> le, ri;
	rep(i, n) {
		int t; cin >> t; t--;
		ll x, y; cin >> x >> y;
		v[t].push_back({ x,y });
	}
	rep(i, v[0].size()) {
		rep(j, v[1].size()) {
			LP nex = { 0,0 };
			nex.first = v[0][i].first + v[1][j].first;
			nex.second = v[0][i].second + v[1][j].second;
			le.push_back(nex);
		}
	}
	rep(i, v[2].size()) {
		rep(j, v[3].size()) {
			rep(k, v[4].size()) {
				LP nex = { 0,0 };
				nex.first = v[2][i].first + v[3][j].first + v[4][k].first;
				nex.second = v[2][i].second + v[3][j].second + v[4][k].second;
				ri.push_back(nex);
			}
		}
	}
	sort(le.begin(), le.end());
	sort(ri.begin(), ri.end());
	ll x = le[0].first;
	multiset<ll> st;
	//[l,r)
	int l = (int)ri.size(), r = ri.size();
	rep(i, ri.size()) {
		ll sum = ri[i].first + le[0].first;
		if (sum >= a && sum <= b) {
			st.insert(ri[i].second);
		}
		if (ri[i].first >= a - le[0].first) {
			l = min(l, i);
		}
		if (ri[i].first > b - le[0].first) {
			r = min(r, i);
		}
	}
	{
		ll cl = a - le[0].second, cr = b - le[0].second;
		if (st.count(cl)) {
			cout << "Yes" << endl; return;
		}
		st.insert(cl);
		auto itr = st.find(cl);
		itr++;
		if (itr != st.end()) {
			ll z = *itr;
			if (z <= cr) {
				cout << "Yes" << endl; return;
			}
		}
		st.erase(st.find(cl));
	}
	rep1(i, (int)le.size()-1) {
		while (l > 0 && le[i].first + ri[l-1].first >= a) {
			l--;
			st.insert(ri[l].second);
		}
		while (r > 0 && le[i].first + ri[r-1].first > b) {
			r--;
			st.erase(st.find(ri[r].second));
		}
		ll cl = a - le[i].second, cr = b - le[i].second;
		if (st.count(cl)) {
			cout << "Yes" << endl; return;
		}
		st.insert(cl); 
		auto itr = st.find(cl);
		itr++;
		if (itr != st.end()) {
			ll z = *itr;
			if (z <= cr) {
				cout << "Yes" << endl; return;
			}
		}
		st.erase(st.find(cl));
	}
	cout << "No" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	solve();
	//stop
		return 0;
}
accuracy: 1
time_ms: 390
memory_kb: 67420
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long int lli;
bool comp(const vector<pair<lli, lli> > &a, const vector<pair<lli, lli> > &b){
    return a.size() < b.size();
}

int main(){
    int n;
    lli a,b;
    cin >> n >> a >> b;
    vector<vector<pair<lli, lli> > > wv(5);
    for(int i=0; i<n; i++){
        lli t,x,y;
        cin >> t >> x >> y;
        t--;
        wv[t].push_back(make_pair(x, y));
    }
    sort(wv.begin(), wv.end(), comp);
    for(int i=0; i<5; i++){
        wv[i].push_back(make_pair(0, 0));
    }

    vector<pair<lli, lli> > en1, en2;
    for(int i=0; i<(int)wv[0].size(); i++){
        for(int j=0; j<(int)wv[1].size(); j++){
            for(int k=0; k<(int)wv[2].size(); k++){
                lli w = wv[0][i].first +wv[1][j].first +wv[2][k].first;
                lli v = wv[0][i].second +wv[1][j].second +wv[2][k].second;
                en1.push_back(make_pair(w, v));
            }
        }
    }
    for(int i=0; i<(int)wv[3].size(); i++){
        for(int j=0; j<(int)wv[4].size(); j++){
            lli w = wv[3][i].first +wv[4][j].first;
            lli v = wv[3][i].second +wv[4][j].second;
            en2.push_back(make_pair(w, v));
        }
    }
    sort(en1.begin(), en1.end());
    sort(en2.begin(), en2.end());

    bool yes = false;
    multiset<lli> validrange;
    int end = en2.size()-1;
    int begin = end; //逆半開
    for(int i=0; i<(int)en1.size(); i++){
        while(begin >= 0 && en2[begin].first +en1[i].first >= a){
            validrange.insert(en2[begin].second);
            begin--;
        }
        while(end > begin && en2[end].first +en1[i].first > b){
            validrange.erase(validrange.find(en2[end].second));
            end--;
        }
        auto itr = validrange.lower_bound(a -en1[i].second);
        if(itr != validrange.end() && *itr +en1[i].second <= b){
            yes = true;
            break;
        }
    }

    if(yes){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 19480
final_rank: 2

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(ll arg_weight,ll arg_value){
		weight = arg_weight;
		value = arg_value;
	}
	bool operator<(const struct Info &arg) const{
		return weight < arg.weight;
	}
	ll weight,value;
};

int N;
ll A,B;
vector<Info> V[5],G[2];

int main(){

	scanf("%d %lld %lld",&N,&A,&B);

	int type;
	ll x,y;

	for(int i = 0; i < 5; i++)V[i].push_back(Info(0,0)); //装備なし

	for(int loop = 0; loop < N; loop++){
		scanf("%d %lld %lld",&type,&x,&y);
		type--;
		V[type].push_back(Info(x,y));
	}

	for(int i = 0; i < V[0].size(); i++){
		for(int k = 0; k < V[1].size(); k++){
			G[0].push_back(Info(V[0][i].weight+V[1][k].weight,V[0][i].value+V[1][k].value));
		}
	}

	for(int a = 0; a < V[2].size(); a++){
		for(int b = 0; b < V[3].size(); b++){
			for(int c = 0; c < V[4].size(); c++){
				G[1].push_back(Info(V[2][a].weight+V[3][b].weight+V[4][c].weight,V[2][a].value+V[3][b].value+V[4][c].value));
			}
		}
	}

	sort(G[0].begin(),G[0].end());
	sort(G[1].begin(),G[1].end());

	int add_index = G[1].size()-1,del_index = G[1].size()-1;

	map<ll,int> count;
	set<ll> SET;

	for(int i = 0; i < G[0].size(); i++){

		while(add_index >= 0 && G[0][i].weight+G[1][add_index].weight >= A){
			SET.insert(G[1][add_index].value);
			count[G[1][add_index].value]++;
			add_index--;
		}

		while(del_index > add_index && G[0][i].weight+G[1][del_index].weight > B){
			count[G[1][del_index].value]--;
			if(count[G[1][del_index].value] == 0)SET.erase(G[1][del_index].value);
			del_index--;
		}

		if(SET.lower_bound(A-G[0][i].value) != SET.upper_bound(B-G[0][i].value)){
			printf("Yes\n");
			return 0;
		}
	}

	printf("No\n");

	return 0;
}
accuracy: 1
time_ms: 1100
memory_kb: 131800
final_rank: 14

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;




int main() {	
	int N;long long int A,B;cin>>N>>A>>B;
	vector<vector<pair<long long int,long long int>>>vs(5,vector<pair<long long int,long long int>>(1,make_pair(0,0)));
	for (int i = 0; i < N; ++i) {
		int t;
		long long int x,y;cin>>t>>x>>y;t--;
		vs[t].push_back(make_pair(x,y));
	}
	sort(vs.begin(), vs.end(), [](const vector<pair<long long int,long long int>>&l, const vector<pair<long long int,long long int>>&r) {return l.size() < r.size(); });
	vector<pair<long long int,long long int>>l;
	vector<pair<long long int,long long int>>r;
	for (auto v1 : vs[0]) {
		for (auto v2 : vs[1]) {
			for (auto v3 : vs[2]) {
				l.emplace_back(v3.first+v1.first+v2.first,v1.second+v2.second+v3.second);
			}
		}
	}
	for (auto v1 : vs[3]) {
		for (auto v2 : vs[4]) {
			r.emplace_back( v1.first + v2.first, v1.second + v2.second );
		}
	}
	sort(l.begin(),l.end());
	sort(r.begin(),r.end(),greater<pair<long long int,long long int>>());
	auto rt=r.begin();
	auto lt=r.begin();
	map<long long int,int>nb;
	bool ok=false;
	for (auto n:l) {
		while (rt != r.end()) {
			if (rt == r.end())break;
			if (rt->first + n.first >=A) {
				nb[rt->second]++;
				rt++;
			}else{
				break;
			}
		}
		while (lt !=r.end()) {
			if (lt == r.end())break;
			if (lt->first + n.first >B) {
				nb[lt->second]--;
				if(nb[lt->second]==0)nb.erase(lt->second);
				lt++;
			}else{
				break;
			}
		}
		auto at=nb.lower_bound(A-n.second);
		auto bt=nb.upper_bound(B-n.second);
		if(at!=bt)ok=true;
	}
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 19720
final_rank: 6

code_snippet: #include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n;
int n_;
P cnt[6];
ll a,b;
vector<P> xy[5];
vector<P> one;
vector<P> two;
vector<ll> Bval;
int dat[1<<22];

void add(int k,int a){
	k+=n_-1;
	dat[k]+=a;
	while(k>0){
		k=(k-1)/2;
		dat[k]=dat[k*2+1]+dat[k*2+2];
	}
}

int query(int a,int b,int k=0,int l=0,int r=n_){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	int vl=query(a,b,k*2+1,l,(l+r)/2);
	int vr=query(a,b,k*2+2,(l+r)/2,r);
	return vl+vr;
}

int main(void){
	scanf("%d%lld%lld",&n,&a,&b);
	for(int i=0;i<n;i++){
		ll x,y;
		int t;
		scanf("%d%lld%lld",&t,&x,&y);
		t--;
		xy[t].push_back(P(x,y));
		cnt[t].first++;
	}
	for(int i=0;i<5;i++){
		cnt[i].second=i;
		xy[i].push_back(P(0,0));
	}
	sort(cnt,cnt+5);
	for(int i=0;i<xy[cnt[0].second].size();i++){
		for(int j=0;j<xy[cnt[1].second].size();j++){
			for(int k=0;k<xy[cnt[2].second].size();k++){
				ll xx=xy[cnt[0].second][i].first+xy[cnt[1].second][j].first+xy[cnt[2].second][k].first;
				ll yy=xy[cnt[0].second][i].second+xy[cnt[1].second][j].second+xy[cnt[2].second][k].second;
				one.push_back(P(xx,yy));
				Bval.push_back(yy);
			}
		}
	}
	sort(one.begin(),one.end());
	reverse(one.begin(),one.end());
	sort(Bval.begin(),Bval.end());
	Bval.erase(unique(Bval.begin(),Bval.end()),Bval.end());
	for(int i=0;i<one.size();i++){
		one[i].second=lower_bound(Bval.begin(),Bval.end(),one[i].second)-Bval.begin();
	}
	for(int i=0;i<xy[cnt[3].second].size();i++){
		for(int j=0;j<xy[cnt[4].second].size();j++){
			ll xx=xy[cnt[3].second][i].first+xy[cnt[4].second][j].first;
			ll yy=xy[cnt[3].second][i].second+xy[cnt[4].second][j].second;
			two.push_back(P(xx,yy));
		}
	}
	sort(two.begin(),two.end());
	n_=1;
	while(n_<one.size())n_*=2;
	int l=0,r=0;
	bool flag=false;
	for(int i=0;i<two.size();i++){
		while(l<one.size() && one[l].first+two[i].first>=a){
			add(one[l].second,1);
			l++;
		}
		while(l>r && one[r].first+two[i].first>b){
			add(one[r].second,-1);
			r++;
		}
		int al=lower_bound(Bval.begin(),Bval.end(),a-two[i].second)-Bval.begin();
		int ar=upper_bound(Bval.begin(),Bval.end(),b-two[i].second)-Bval.begin();
		if(query(al,ar)>0)flag=true;
	}
	printf("%s\n",flag?"Yes":"No");
	return 0;
}
accuracy: 1
time_ms: 340
memory_kb: 43340
final_rank: 7

code_snippet: #include<bits/stdc++.h>
  
using namespace std;
  
typedef long long int64;
  
map< int64, int > data;
  
int64 sum(int64 k)
{
  k += 1e13;
  int ret = 0;
  for(; k > 0; k -= k & -k) {
    if(!data.count(k)) continue;
    ret += data[k];
  }
  return (ret);
}
  
void push(int64 k, int x)
{
  k += 1e13;
  for(; k < 1e14; k += k & -k) data[k] += x;
}
  
int main()
{
  int64 N, A, B;
  vector< pair< int64, int64 > > T[5];
  
  cin >> N >> A >> B;
  for(int i = 0; i < N; i++) {
    int64 a, b, c;
    cin >> a >> b >> c;
    T[--a].emplace_back(b, c);
  }
  
  for(int i = 0; i < 5; i++) {
    T[i].emplace_back(0LL, 0LL);
  }
  
  map< int64, vector< pair< int64, int > > > add;
  map< int64, vector< int64 > > que;
  map< int64, vector< pair< int64, int > > > del;
  
  for(auto &s : T[0]) {
    for(auto &t : T[1]) {
      for(auto &q : T[2]) {
        int64 a = s.first + t.first + q.first;
        int64 b = s.second + t.second + q.second;
        que[a].emplace_back(b);
      }
    }
  }
  
  for(auto &s : T[3]) {
    for(auto &t : T[4]) {
      int64 a = s.first + t.first;
      int64 b = s.second + t.second;
      pair< int64, int64 > latte = {A - a, B - a};
      pair< int64, int64 > malta = {A - b, B - b};
      if(latte.first > latte.second) continue;
      if(malta.first > malta.second) continue;
      add[latte.first].emplace_back(malta.first, +1);
      add[latte.first].emplace_back(malta.second + 1, -1);
      del[latte.second].emplace_back(malta.first, -1);
      del[latte.second].emplace_back(malta.second + 1, +1);
    }
  }
  
  auto ptr = que.begin();
  auto latte = add.begin(), malta = del.begin();
  
  
  while(ptr != que.end()) {
    while(latte != add.end() && latte->first <= ptr->first) {
      for(auto &v : latte->second) {
        push(v.first, v.second);
      }
      ++latte;
    }
    while(malta != del.end() && malta->first < ptr->first) {
      for(auto &v : malta->second) push(v.first, v.second);
      ++malta;
    }
    for(auto &v : ptr->second) {
      if(sum(v) != 0) {
        cout << "Yes" << endl;
        return (0);
      }
    }
    while(malta != del.end() && malta->first <= ptr->first) {
      for(auto &v : malta->second) push(v.first, v.second);
      ++malta;
    }
    ++ptr;
  }
  
  cout << "No" << endl;
}
accuracy: 1
time_ms: 990
memory_kb: 130748
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int N;
ll tmin,tmax;
vector<P> G[5];

int main(){
  cin>>N>>tmin>>tmax;
  
  for(int i=0;i<N;i++){
    int type;
    ll x,y;
    cin>>type>>x>>y;
    type--;
    G[type].push_back( P(x,y) );
  }
  for(int i=0;i<5;i++)G[i].push_back( P(0,0) );
  
  for(int i=0;i<3;i++){
    int target=i;
    for(int j=i+1;j<5;j++){
      if( G[target].size() > G[j].size() ){
        target=j;
      }
    }
    if(i!=target){
      vector<P> tmp;
      tmp=G[i];
      G[i]=G[target];
      G[target]=tmp;
    }
  }

  ll Asize= G[0].size() * G[1].size()  * G[2].size();
  //  if(Asize>500000)return 0;
  ll Bsize= G[3].size() * G[4].size();
  
  vector<P> A ( Asize );
  vector<P> B ( Bsize );

  int cc;
  cc=0;
  for(int i=0;i<(int)G[0].size();i++){
    P X=G[0][i];
    for(int j=0;j<(int)G[1].size();j++){
      P Y=G[1][j];
      for(int k=0;k<(int)G[2].size();k++){
        P Z=G[2][k]; 
        A[cc++]=P( X.first+Y.first+Z.first , X.second+Y.second+Z.second );
      }
    }
  }
  cc=0;
  for(int i=0;i<(int)G[3].size();i++){
    P X=G[3][i];
    for(int j=0;j<(int)G[4].size();j++){
      P Y=G[4][j];
      B[cc++]=P( X.first+Y.first , X.second+Y.second );
    }
  }
  
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());

  int l=B.size() ,r= B.size();
  
  map<ll,int> count;
  set<ll> st;
  for(int i=0;i<(int)A.size();i++){
    ll x=A[i].first;
    ll y=A[i].second;
    
    while(l-1>=0 && x + B[l-1].first >= tmin ){
      ll key=B[l-1].second;
      st.insert(key);
      count[ key ]++;
      l--;
    }
    
    while(r>l && x + B[r-1].first > tmax ){
      ll key=B[r-1].second;
      count[ key ]--;
      if( count[ key ] == 0 )  st.erase( key );
      r--;
    }

    if( st.lower_bound(tmin-y) != st.upper_bound(tmax-y) ){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;
  return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 20148
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

using ll = long long;

struct Node {
    int loc;
    int l, r;
    Node() { loc = l = r = -1; }
    Node(int loc, int l, int r) : loc{loc}, l{l}, r{r} {} 
};

struct Point {
    ll x, y;
    Point() {}
    Point(ll x, ll y) : x{x}, y{y} {}

    bool operator < (const Point& p) const {
        return x != p.x ? x < p.x : y < p.y;
    }
};

struct KDTree2D {
    vector<Point> p;
    vector<Node> T;
    int np = 0;
    
    void init() { T.resize(p.size()); }
    
    int make(int l, int r, int depth)
    {
        if (l >= r) return -1;
        
        int mid = (l + r) / 2;
        int curr = np++;
        
        if (depth % 2 == 0) {
            sort(p.begin() + l, p.begin() + r, [](const Point& a, const Point& b) { return a.x < b.x; });
        } else {
            sort(p.begin() + l, p.begin() + r, [](const Point& a, const Point& b) { return a.y < b.y; });
        }
        T[curr] = {mid, make(l, mid, depth + 1), make(mid + 1, r, depth + 1)};        
        return curr;
    }

    void add(Point v)
    {
        p.emplace_back(v.x, v.y);
    }    

    bool find(int k, ll sx, ll sy, ll tx, ll ty, int depth)
    {
        ll x = p[T[k].loc].x;
        ll y = p[T[k].loc].y;
        
        if (sx <= x && x <= tx && sy <= y && y <= ty) {
            return 1;
        }

        if (!(sx <= x && x <= tx && sy <= y && y <= ty) && depth >= 10) {
            return 0;
        }
        
        bool res = 0;
        if (depth % 2 == 0) {
            if (T[k].l != -1 && sx <= x) {
                res |= find(T[k].l, sx, sy, tx, ty, depth + 1);
            }

            if (T[k].r != -1 && x <= tx) {
                res |= find(T[k].r, sx, sy, tx, ty, depth + 1);
            }
        } else {
            if (T[k].l != -1 && sy <= y) {
                res |= find(T[k].l, sx, sy, tx, ty, depth + 1);
            }

            if (T[k].r != -1 && y <= ty) {
                res |= find(T[k].r, sx, sy, tx, ty, depth + 1);
            }
        }
        return res;
    }
};

Point sum(const Point& a, const Point& b)
{
    return Point{a.x + b.x, a.y + b.y};
}

bool find(KDTree2D& kd, int root, ll l, ll r, ll dx, ll dy)
{
    ll sx = l - dx, tx = r - dx;
    ll sy = l - dy, ty = r - dy;
    return kd.find(root, sx, sy, tx, ty, 0);
}

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    vector<vector<Point>> p{5};
    for (int i = 0; i < N; i++) {
        ll t, x, y;
        cin >> t >> x >> y;
        p[t - 1].emplace_back(x, y);        
    }
    
    for (int i = 0; i < 5; i++) {
        p[i].emplace_back(0, 0);
    }    
    
    sort(p.begin(), p.end(),
         [](const vector<Point>& a, const vector<Point>& b) { return a.size() > b.size(); });
    
    KDTree2D kd;
    for (Point& v0 : p[0]) {
        for (Point& v1 : p[1]) {            
            kd.add(sum(v0, v1));           
        }
    }
    
    kd.init();
    int root = kd.make(0, kd.p.size(), 0);
    cout << ([&]() {
        for (Point& v2 : p[2]) {
            for (Point& v3 : p[3]) {
                for (Point& v4 : p[4]) {
                    Point s = sum(sum(v2, v3), v4);
                    if (find(kd, root, A, B, s.x, s.y)) {
                        return 1;
                    }
                }            
            }    
        }
        return 0;
    }() ? "Yes" : "No") << endl;
    return 0;
}
accuracy: 1
time_ms: 1230
memory_kb: 3268
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>

using ll = long long;

struct Node {
    int loc;
    int l, r;
    Node() { loc = l = r = -1; }
    Node(int loc, int l, int r) : loc{loc}, l{l}, r{r} {} 
};

struct Point {
    ll x, y;
    Point() {}
    Point(ll x, ll y) : x{x}, y{y} {}

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }
};

struct KDTree2D {
    std::vector<Point> p;
    std::vector<Node> T;
    int np = 0;
    
    void init() { T.resize(p.size()); }
    
    int make(int l, int r, int depth)
    {
        if (l >= r) return -1;
        
        int mid = (l + r) / 2;
        int curr = np++;
        
        if (depth % 2 == 0) {
            std::sort(p.begin() + l, p.begin() + r,
                      [](const Point& a, const Point& b) {
                          return a.x < b.x;
                      });
        } else {
            std::sort(p.begin() + l, p.begin() + r,
                      [](const Point& a, const Point& b) {
                          return a.y < b.y;
                      });
        }
        T[curr] = {mid, make(l, mid, depth + 1), make(mid + 1, r, depth + 1)};        
        return curr;
    }

    void add(Point v)
    {
        p.emplace_back(v.x, v.y);
    }    

    bool find(int k, ll sx, ll sy, ll tx, ll ty, int depth)
    {
        ll x = p[T[k].loc].x;
        ll y = p[T[k].loc].y;
        
        if (sx <= x && x <= tx && sy <= y && y <= ty) {
            return 1;
        }
        
        ll res = 0;
        if (depth % 2 == 0) {
            if (T[k].l != -1 && sx <= x) {
                res |= find(T[k].l, sx, sy, tx, ty, depth + 1);
            }

            if (T[k].r != -1 && x <= tx) {
                res |= find(T[k].r, sx, sy, tx, ty, depth + 1);
            }
        } else {
            if (T[k].l != -1 && sy <= y) {
                res |= find(T[k].l, sx, sy, tx, ty, depth + 1);
            }

            if (T[k].r != -1 && y <= ty) {
                res |= find(T[k].r, sx, sy, tx, ty, depth + 1);
            }
        }        
        return res;
    }
};

Point sum(const Point &a, const Point &b)
{
    return Point{a.x + b.x, a.y + b.y};
}

bool find(KDTree2D &kd, int root, ll l, ll r, ll dx = 0, ll dy = 0)
{
    ll sx = l - dx, tx = r - dx;
    ll sy = l - dy, ty = r - dy;
    return kd.find(root, sx, sy, tx, ty, 0);
}

int main()
{
    ll N, A, B;
    std::cin >> N >> A >> B;
    std::vector<std::vector<Point>> p{5};
    for (int i = 0; i < N; i++) {
        ll t, x, y;
        std::cin >> t >> x >> y;
        p[t - 1].emplace_back(x, y);        
    }
    
    for (int i = 0; i < 5; i++) {
        p[i].emplace_back(0, 0);
    }    
    
    sort(p.begin(), p.end(),
         [](const std::vector<Point> &a, const std::vector<Point> &b) {
             return a.size() > b.size();
         });
    
    KDTree2D kd;
    for (Point& v0 : p[0]) {
        for (Point& v1 : p[1]) {            
            kd.add(sum(v0, v1));           
        }
    }
    
    kd.init();
    int root = kd.make(0, kd.p.size(), 0);
    bool res = 0;    
    for (Point& v2 : p[2]) {
        for (Point& v3 : p[3]) {
            for (Point& v4 : p[4]) {
                Point s = sum(sum(v2, v3), v4);
                res |= find(kd, root, A, B, s.x, s.y); 
            }            
        }    
    }    
    std::cout << (res ? "Yes" : "No") << std::endl;
    return 0;
}
accuracy: 1
time_ms: 2060
memory_kb: 3240
final_rank: 10

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef pair<LL,LL> P;    
int main(){
    int N;
    cin>>N;
    LL X,Y;
    cin>>X>>Y;
    vector<vector<P>> xy(5,vector<P>(1,P(0,0)));
    REP(i,N){
        int t;LL x,y;
        cin>>t>>x>>y;
        xy[t-1].pb(P(x,y));
    }
    vector<P> A,B;
    for(auto &a:xy[0])
        for(auto &b:xy[1])
            for(auto &c:xy[2])A.pb(P(a.fi+b.fi+c.fi,a.se+b.se+c.se));
    for(auto &d:xy[3])
        for(auto &e:xy[4])B.pb(P(d.fi+e.fi,d.se+e.se));
    sort(ALL(A));
    sort(ALL(B));
    reverse(ALL(B));
    
    int M=B.size();
    multiset<LL> exist;
    int bg=0,ed=0;
    for(auto &a:A){
        while(ed<M&&a.fi+B[ed].fi>=X){
            exist.insert(B[ed].se);
            ed++;
        }
        while(bg<ed&&a.fi+B[bg].fi>Y){
            auto it = exist.find(B[bg].se);
            exist.erase(it);
            bg++;
        }
        auto it = exist.lower_bound(X-a.se);
        if(it!=exist.end()&&a.se+*it<=Y){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 19468
final_rank: 3

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e18;

class SegT{
private:
  VL dat[2 * (1 << 17) - 1]; // = 131072
  int NN;

  void merge(VL& dst, const VL& s1, const VL& s2){
	for(int i1=0,i2=0;i1<SZ(s1)||i2<SZ(s2);){
	  if(i1 == SZ(s1)){
		dst.push_back(s2[i2++]);
	  }
	  else if(i2 == SZ(s2)){
		dst.push_back(s1[i1++]);
	  }
	  else{
		if(s1[i1] < s2[i2])
		  dst.push_back(s1[i1++]);
		else
		  dst.push_back(s2[i2++]);
	  }
	}
  }
  
public:
  SegT(int n_, VVL& xs){
	NN = 1;
	while(NN < n_) NN <<= 1;
	for(int i=0;i<n_;++i){
	  dat[NN-1+i] = xs[i];
	  SORT(dat[NN-1+i]);
	}
	for(int i=NN-2;i>=0;--i){
	  merge(dat[i], dat[i*2+1], dat[i*2+2]);
	}
  }

  bool query(int a, int b, LL lb, LL ub, int k, int l, int r){
	if(r <= a || b <= l) return false;

	if(a <= l && r <= b){
	  auto it = lower_bound(ALL(dat[k]), lb);
	  return it != end(dat[k]) && *it <= ub;
	}
	else{
	  if(query(a, b, lb, ub, k*2+1, l, (l+r)/2))
		return true;
	  return query(a, b, lb, ub, k*2+2, (l+r)/2, r);
	}
  }
  int query(int a, int b, LL lb, LL ub){
	return query(a, b, lb, ub, 0, 0, NN);
  }
};


LL N, A, B;
vector<PLL> xs[5];

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N >> A >> B;
  REP(i,N){
	LL t, a, b;
	cin >> t >> a >> b;
	xs[t-1].EB(a,b);
  }
  
  set<PLL> S, T, tmp;
  S.insert(MP(0,0));
  REP(i,3){
	tmp = S;
	for(auto&& p: S)
	  for(auto&& x: xs[i]){
		tmp.insert(MP(x.FF+p.FF, x.SS+p.SS));
	  }
	S = tmp;
  }
  T.insert(MP(0,0));
  FOR(i,3,5){
	tmp = T;
	for(auto&& p: T)
	  for(auto&& x: xs[i]){
		tmp.insert(MP(x.FF+p.FF, x.SS+p.SS));
	  }
	T = tmp;
  }
  tmp.clear();

  vector<LL> xx;
  for(auto&& p: T)
	xx.PB(p.FF);
  xx.PB(-INF);
  xx.PB(INF);
  SORT(xx);
  xx.erase(unique(ALL(xx)), end(xx));

  int M = SZ(xx);
  map<LL,int> idx;
  REP(i,M) idx[xx[i]] = i;
  
  VVL dat(M);
  for(auto&& p: T)
	dat[idx[p.FF]].PB(p.SS);

  SegT seg(M, dat);
  for(auto&& p: S){
	int lx = idx.lower_bound(A-p.FF)->SS;
	int rx = idx.upper_bound(B-p.FF)->SS;
	if(seg.query(lx, rx, A-p.SS, B-p.SS)){
	  cout << "Yes" << endl;
	  return 0;
	}
  }
  cout << "No" << endl;

  return 0;
}
accuracy: 1
time_ms: 880
memory_kb: 138124
final_rank: 11

code_snippet: #include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int64;
 
map< int64, int > data;
 
int64 sum(int64 k)
{
  k += 1e13;
  int ret = 0;
  for(; k > 0; k -= k & -k) {
    if(!data.count(k)) continue;
    ret += data[k];
  }
  return (ret);
}
 
void push(int64 k, int x)
{
  k += 1e13;
  for(; k < 1e14; k += k & -k) data[k] += x;
}
 
int main()
{
  int64 N, A, B;
  vector< pair< int64, int64 > > T[5];
 
  cin >> N >> A >> B;
  for(int i = 0; i < N; i++) {
    int64 a, b, c;
    cin >> a >> b >> c;
    T[--a].emplace_back(b, c);
  }
 
  for(int i = 0; i < 5; i++) {
    T[i].emplace_back(0LL, 0LL);
  }
 
  map< int64, vector< pair< int64, int > > > add;
  map< int64, vector< int64 > > que;
  map< int64, vector< pair< int64, int > > > del;
 
  for(auto &s : T[0]) {
    for(auto &t : T[1]) {
      for(auto &q : T[2]) {
        int64 a = s.first + t.first + q.first;
        int64 b = s.second + t.second + q.second;
        que[a].emplace_back(b);
      }
    }
  }
 
  for(auto &s : T[3]) {
    for(auto &t : T[4]) {
      int64 a = s.first + t.first;
      int64 b = s.second + t.second;
      pair< int64, int64 > latte = {A - a, B - a};
      pair< int64, int64 > malta = {A - b, B - b};
      if(latte.first > latte.second) continue;
      if(malta.first > malta.second) continue;
      add[latte.first].emplace_back(malta.first, +1);
      add[latte.first].emplace_back(malta.second + 1, -1);
      del[latte.second].emplace_back(malta.first, -1);
      del[latte.second].emplace_back(malta.second + 1, +1);
    }
  }
 
  auto ptr = que.begin();
  auto latte = add.begin(), malta = del.begin();
 
 
  while(ptr != que.end()) {
    while(latte != add.end() && latte->first <= ptr->first) {
      for(auto &v : latte->second) {
        push(v.first, v.second);
      }
      ++latte;
    }
    while(malta != del.end() && malta->first < ptr->first) {
      for(auto &v : malta->second) push(v.first, v.second);
      ++malta;
    }
    for(auto &v : ptr->second) {
      if(sum(v) != 0) {
        cout << "Yes" << endl;
        return (0);
      }
    }
    while(malta != del.end() && malta->first <= ptr->first) {
      for(auto &v : malta->second) push(v.first, v.second);
      ++malta;
    }
    ++ptr;
  }
 
  cout << "No" << endl;
}
accuracy: 1
time_ms: 990
memory_kb: 130772
final_rank: 13

code_snippet: #include<bits/stdc++.h>

using namespace std;

typedef long long int64;

map< int64, int > data;

int64 sum(int64 k)
{
  k += 1e13;
  int ret = 0;
  for(; k > 0; k -= k & -k) {
    if(!data.count(k)) continue;
    ret += data[k];
  }
  return (ret);
}

void push(int64 k, int x)
{
  k += 1e13;
  for(; k < 1e14; k += k & -k) data[k] += x;
}

int main()
{
  int64 N, A, B;
  vector< pair< int64, int64 > > T[5];

  cin >> N >> A >> B;
  for(int i = 0; i < N; i++) {
    int64 a, b, c;
    cin >> a >> b >> c;
    T[--a].emplace_back(b, c);
  }

  for(int i = 0; i < 5; i++) {
    T[i].emplace_back(0LL, 0LL);
  }

  map< int64, vector< pair< int64, int > > > add;
  map< int64, vector< int64 > > que;
  map< int64, vector< pair< int64, int > > > del;

  for(auto &s : T[0]) {
    for(auto &t : T[1]) {
      for(auto &q : T[2]) {
        int64 a = s.first + t.first + q.first;
        int64 b = s.second + t.second + q.second;
        que[a].emplace_back(b);
      }
    }
  }

  for(auto &s : T[3]) {
    for(auto &t : T[4]) {
      int64 a = s.first + t.first;
      int64 b = s.second + t.second;
      pair< int64, int64 > latte = {A - a, B - a};
      pair< int64, int64 > malta = {A - b, B - b};
      if(latte.first > latte.second) continue;
      if(malta.first > malta.second) continue;
      add[latte.first].emplace_back(malta.first, +1);
      add[latte.first].emplace_back(malta.second + 1, -1);
      del[latte.second].emplace_back(malta.first, -1);
      del[latte.second].emplace_back(malta.second + 1, +1);
    }
  }

  auto ptr = que.begin();
  auto latte = add.begin(), malta = del.begin();


  while(ptr != que.end()) {
    while(latte != add.end() && latte->first <= ptr->first) {
      for(auto &v : latte->second) {
        push(v.first, v.second);
      }
      ++latte;
    }
    for(auto &v : ptr->second) {
      if(sum(v) != 0) {
        cout << "Yes" << endl;
        return (0);
      }
    }
    while(malta != del.end() && malta->first <= ptr->first) {
      for(auto &v : malta->second) push(v.first, v.second);
      ++malta;
    }
    ++ptr;
  }

  cout << "No" << endl;
}
accuracy: 0.7446808510638298
time_ms: 890
memory_kb: 130744
final_rank: 18

code_snippet: #include<bits/stdc++.h>

using namespace std;

typedef long long int64;

map< int64, int > data;

int64 sum(int64 k)
{
  k += 3e12;
  int ret = 0;
  for(; k > 0; k -= k & -k) {
    if(!data.count(k)) continue;
    ret += data[k];
  }
  return (ret);
}

void push(int64 k, int x)
{
  k += 3e12;
  for(; k < 1e13; k += k & -k) data[k] += x;
}

int main()
{
  int64 N, A, B;
  vector< pair< int64, int64 > > T[5];

  cin >> N >> A >> B;
  for(int i = 0; i < N; i++) {
    int64 a, b, c;
    cin >> a >> b >> c;
    T[--a].emplace_back(b, c);
  }

  for(int i = 0; i < 5; i++) {
    T[i].emplace_back(0LL, 0LL);
  }

  map< int64, vector< pair< int64, int > > > add;
  map< int64, vector< int64 > > que;
  map< int64, vector< pair< int64, int > > > del;

  for(auto &s : T[0]) {
    for(auto &t : T[1]) {
      for(auto &q : T[2]) {
        int64 a = s.first + t.first + q.first;
        int64 b = s.second + t.second + q.second;
        que[a].emplace_back(b);
      }
    }
  }

  for(auto &s : T[3]) {
    for(auto &t : T[4]) {
      int64 a = s.first + t.first;
      int64 b = s.second + t.second;
      pair< int64, int64 > latte = {A - a, B - a};
      pair< int64, int64 > malta = {A - b, B - b};
      if(latte.first > latte.second) continue;
      if(malta.first > malta.second) continue;
      add[latte.first].emplace_back(malta.first, +1);
      add[latte.first].emplace_back(malta.second + 1, -1);
      del[latte.second].emplace_back(malta.first, -1);
      del[latte.second].emplace_back(malta.second + 1, +1);
    }
  }

  auto ptr = que.begin();
  auto latte = add.begin(), malta = del.begin();


  while(ptr != que.end()) {
    while(latte != add.end() && latte->first <= ptr->first) {
      for(auto &v : latte->second) {
        push(v.first, v.second);
      }
      ++latte;
    }
    for(auto &v : ptr->second) {
      if(sum(v) != 0) {
        cout << "Yes" << endl;
        return (0);
      }
    }
    while(malta != del.end() && malta->first <= ptr->first) {
      for(auto &v : malta->second) push(v.first, v.second);
      ++malta;
    }
    ++ptr;
  }

  cout << "No" << endl;
}
accuracy: 0.7446808510638298
time_ms: 880
memory_kb: 130604
final_rank: 17

code_snippet: #include<iostream>
#include<sstream>
#include<vector>
#include<deque>
#include<cstdio>
#include<map>
#include<set>
#include<cassert>
#include<algorithm>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;
typedef long long ll;

#define MAX 600
typedef pair<ll,ll> ii;
int N;
ll A,B,x[MAX],y[MAX];
int t[MAX];

vector<ii> vec[6];

int main() {
  cin >> N >> A >> B;
  rep(i,N) {
    cin >> t[i] >> x[i] >> y[i];
    --t[i];
    vec[t[i]].push_back(ii(x[i],y[i]));
  }
  set<ii> S;
  rep(i,3) vec[i].push_back(ii(0,0));
  rep(i,(int)vec[0].size()) {
    ii v1 = vec[0][i];
    rep(j,(int)vec[1].size()) {
      ii v2 = vec[1][j];
      rep(k,(int)vec[2].size()) {
	ii v3 = vec[2][k];
	ii v = ii(v1.first+v2.first+v3.first,
		  v1.second+v2.second+v3.second);
	S.insert(v);
      }
    }
  }

  vector<ii> T;
 rep(i,2) vec[3+i].push_back(ii(0,0));
 rep(i,(int)vec[3].size()) {
   ii v1 = vec[3][i];
   rep(j,(int)vec[4].size()) {
      ii v2 = vec[4][j];
      ii v = ii(v1.first+v2.first,
		v1.second+v2.second);
      T.push_back(v);
    }
  }
 sort(T.begin(),T.end());
 T.erase(unique(T.begin(),T.end()),T.end());
 while( S.empty() );
 while( T.empty() );
 for(auto v : S) {
   int ptr = lower_bound(T.begin(),T.end(),v) - T.end();
   REP(i,ptr,(int)T.size()) {
     if( v.first+T[i].first < A ) continue;
     if( v.first+T[i].first > B ) continue;
     if( A <= v.second + T[i].second && v.second + T[i].second <= B ) {
       puts("Yes");
       return 0;
     }
   }
 }
 puts("No");
 return 0;
}
accuracy: 0.3191489361702128
time_ms: 280
memory_kb: 45660
final_rank: 20

code_snippet: #include<iostream>
#include<sstream>
#include<vector>
#include<deque>
#include<cstdio>
#include<map>
#include<set>
#include<cassert>
#include<algorithm>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;
typedef long long ll;

#define MAX 600
typedef pair<ll,ll> ii;
int N;
ll A,B,x[MAX],y[MAX];
int t[MAX];

vector<ii> vec[6];

int main() {
  cin >> N >> A >> B;
  rep(i,N) {
    cin >> t[i] >> x[i] >> y[i];
    --t[i];
    vec[t[i]].push_back(ii(x[i],y[i]));
  }
  set<ii> S;
  rep(i,3) vec[i].push_back(ii(0,0));
  rep(i,(int)vec[0].size()) {
    ii v1 = vec[0][i];
    rep(j,(int)vec[1].size()) {
      ii v2 = vec[1][j];
      rep(k,(int)vec[2].size()) {
	ii v3 = vec[2][k];
	ii v = ii(v1.first+v2.first+v3.first,
		  v1.second+v2.second+v3.second);
	S.insert(v);
      }
    }
  }

  vector<ii> T;
 rep(i,2) vec[3+i].push_back(ii(0,0));
 rep(i,(int)vec[3].size()) {
   ii v1 = vec[3][i];
   rep(j,(int)vec[4].size()) {
      ii v2 = vec[4][j];
      ii v = ii(v1.first+v2.first,
		v1.second+v2.second);
      T.push_back(v);
    }
  }
 sort(T.begin(),T.end());
 T.erase(unique(T.begin(),T.end()),T.end());
 for(auto v : S) {
   int ptr = lower_bound(T.begin(),T.end(),v) - T.end();
   REP(i,ptr,(int)T.size()) {
     if( v.first+T[i].first < A ) continue;
     if( v.first+T[i].first > B ) continue;
     if( A <= v.second + T[i].second && v.second + T[i].second <= B ) {
       puts("Yes");
       return 0;
     }
   }
 }
 puts("No");
 return 0;
}
accuracy: 0.3191489361702128
time_ms: 270
memory_kb: 45564
final_rank: 19

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n;
ll aa,bb;
vector<pll> bugu[5];

const int N = 1<<15;
set<ll> seg[2*N];

bool query(int l,int r,ll ymn,ll ymx,int a,int b,int k){
  if(r<=a || b<=l)return false;
  if(l<=a && b<=r){
    ll v = *(seg[k].lower_bound(ymn));
    return ymn <= v && v <= ymx;
  }else{
    int m = (a+b)/2;
    return query(l,r,ymn,ymx,a,m,2*k+1) || query(l,r,ymn,ymx,m,b,2*k+2);
  }
}

const ll INF = 1e18;

int main(){
  scanf("%d%lld%lld",&n,&aa,&bb);
  REP(i,n){
    int t;ll x,y;scanf("%d%lld%lld",&t,&x,&y);
    --t;
    bugu[t].push_back(pll(x,y));
  }
  sort(bugu,bugu+5,[&](vector<pll> a,vector<pll> b){return a.size() > b.size();});
  REP(i,5)bugu[i].push_back(pll(0,0));

  // rekkyo
  vector<pll> mp;
  set<ll> xs;
  REP(i,bugu[3].size())REP(j,bugu[4].size()){
    ll x=0, y=0;
    x+=bugu[3][i].first;  y+=bugu[3][i].second;
    x+=bugu[4][j].first;  y+=bugu[4][j].second;
    mp.push_back(pll(x,y));
    xs.insert(x);
  }
  xs.insert(INF);
  xs.insert(-INF);
  // zaatu
  map<ll,int> ids;
  {
    int it = 0;
    for(ll x : xs){
      ids[x] = it++;
    }
  }
  // construct set on segment tree
  REP(i,N){
    seg[i+N-1].insert(INF);
    seg[i+N-1].insert(-INF);
  }
  for(pll P : mp){
    ll x = ids[P.first];
    ll y = P.second;
    seg[x+N-1].insert(y);
  }
  FOR(i,0,N-1){
    int lch = 2*i+1;
    int rch = 2*i+2;
    for(ll y : seg[lch]){
      seg[i].insert(y);
    }
    for(ll y : seg[rch]){
      seg[i].insert(y);
    }
  }

  // query
  REP(i,bugu[0].size())REP(j,bugu[1].size())REP(k,bugu[2].size()){
    ll x=0, y=0;
    x+=bugu[0][i].first;  y+=bugu[0][i].second;
    x+=bugu[1][j].first;  y+=bugu[1][j].second;
    x+=bugu[2][k].first;  y+=bugu[2][k].second;
    // a <= x + tx <= b
    // a <= y + ty <= b
    // a-x <= tx <= b-x
    // a-y <= ty <= b-y
    int leftx = ids.lower_bound(aa-x)->second;
    int rightx = ids.upper_bound(bb-x)->second;
    bool ok = query(leftx,rightx,aa-y,bb-y,0,N,0);
    if(ok){
      puts("Yes");
      return 0;
    }
  }
  puts("No");

  return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 12936
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll a,b;
vector<pll> bugu[5];

const int N = 1<<15;
set<ll> seg[2*N];

bool query(int l,int r,ll ymn,ll ymx,int a,int b,int k){
  if(r<=a || b<=l)return false;
  if(l<=a && b<=r){
    ll v = *(seg[k].lower_bound(ymn));
    return v <= ymx;
  }else{
    int m = (a+b)/2;
    return query(l,r,ymn,ymx,a,m,2*k+1) || query(l,r,ymn,ymx,m,b,2*k+2);
  }
}

int main(){
  scanf("%d%lld%lld",&n,&a,&b);
  REP(i,n){
    int t;ll x,y;scanf("%d%lld%lld",&t,&x,&y);
    --t;
    bugu[t].push_back(pll(x,y));
  }
  sort(bugu,bugu+5,[&](vector<pll> a,vector<pll> b){return a.size() > b.size();});
  REP(i,5)bugu[i].push_back(pll(0,0));

  // rekkyo
  vector<pll> mp;
  set<ll> xs;
  REP(i,bugu[3].size())REP(j,bugu[4].size()){
    ll x=0, y=0;
    x+=bugu[3][i].first;  y+=bugu[3][i].second;
    x+=bugu[4][j].first;  y+=bugu[4][j].second;
    mp.push_back(pll(x,y));
    xs.insert(x);
  }
  // zaatu
  map<ll,int> ids;
  {
    ids[-1e17] = 0;
    int it = 1;
    for(ll x : xs){
      ids[x] = it++;
    }
    ids[1e17] = it;
  }
  // construct set on segment tree
  REP(i,N){
    seg[i+N-1].insert(1e17);
    seg[i+N-1].insert(-1e17);
  }
  for(pll P : mp){
    ll x = ids[P.first];
    ll y = P.second;
    seg[x+N-1].insert(y);
  }
  FOR(i,0,N-1){
    int lch = 2*i+1;
    int rch = 2*i+2;
    for(ll y : seg[lch]){
      seg[i].insert(y);
    }
    for(ll y : seg[rch]){
      seg[i].insert(y);
    }
  }

  // query
  REP(i,bugu[0].size())REP(j,bugu[1].size())REP(k,bugu[2].size()){
    ll x=0, y=0;
    x+=bugu[0][i].first;  y+=bugu[0][i].second;
    x+=bugu[1][j].first;  y+=bugu[1][j].second;
    x+=bugu[2][k].first;  y+=bugu[2][k].second;
    // a <= x + tx <= b
    // a <= y + ty <= b
    // a-x <= tx <= b-x
    // a-y <= ty <= b-y
    int leftx = ids.lower_bound(a-x)->second;
    int rightx = ids.upper_bound(b-x)->second;
    bool ok = query(leftx,rightx,a-y,b-y,0,N,0);
    if(ok){
      puts("Yes");
      return 0;
    }
  }
  puts("No");

  return 0;
}
accuracy: 0.7446808510638298
time_ms: 320
memory_kb: 12936
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll a,b;
vector<pll> bugu[5];

const int N = 1<<14;
set<ll> seg[2*N];

bool query(int l,int r,ll ymn,ll ymx,int a,int b,int k){
  if(r<=a || b<=l)return false;
  if(l<=a && b<=r){
    ll v = *(seg[k].lower_bound(ymn));
    // if(v<=ymx){
      // for(ll s : seg[k]){
      //   DEBUG(s);
      // }
      // DEBUG(k);
      // DEBUG(v);
      // DEBUG(ymn);
      // DEBUG(ymx);
    // }
    return v <= ymx;
  }else{
    int m = (a+b)/2;
    return query(l,r,ymn,ymx,a,m,2*k+1) || query(l,r,ymn,ymx,m,b,2*k+2);
  }
}

int main(){
  scanf("%d%lld%lld",&n,&a,&b);
  REP(i,n){
    int t;ll x,y;scanf("%d%lld%lld",&t,&x,&y);
    --t;
    bugu[t].push_back(pll(x,y));
  }
  sort(bugu,bugu+5,[&](vector<pll> a,vector<pll> b){return a.size() > b.size();});

  // rekkyo
  vector<pll> mp;
  set<ll> xs;
  REP(i,bugu[3].size()+1)REP(j,bugu[4].size()+1){
    ll x=0, y=0;
    if(i<bugu[3].size()){
      x+=bugu[3][i].first;
      y+=bugu[3][i].second;
    }
    if(j<bugu[4].size()){
      x+=bugu[4][j].first;
      y+=bugu[4][j].second;
    }
    mp.push_back(pll(x,y));
    xs.insert(x);
  }
  // zaatu
  map<ll,int> ids;
  {
    ids[-1e17] = 0;
    int it = 1;
    for(ll x : xs){
      ids[x] = it++;
    }
    ids[1e17] = it;
  }
  // construct set on segment tree
  REP(i,N){
    seg[i+N-1].insert(1e17);
    seg[i+N-1].insert(-1e17);
  }
  for(pll P : mp){
    ll x = ids[P.first];
    ll y = P.second;
    seg[x+N-1].insert(y);
  }
  FOR(i,0,N-1){
    int lch = 2*i+1;
    int rch = 2*i+2;
    for(ll y : seg[lch]){
      seg[i].insert(y);
    }
    for(ll y : seg[rch]){
      seg[i].insert(y);
    }
  }

  // query
  REP(i,bugu[0].size()+1)REP(j,bugu[1].size()+1)REP(k,bugu[2].size()+1){
    ll x=0, y=0;
    if(i<bugu[0].size()){
      x+=bugu[0][i].first;
      y+=bugu[0][i].second;
    }
    if(j<bugu[1].size()){
      x+=bugu[1][j].first;
      y+=bugu[1][j].second;
    }
    if(k<bugu[2].size()){
      x+=bugu[2][k].first;
      y+=bugu[2][k].second;
    }
    // a <= x + tx <= b
    // a <= y + ty <= b
    // a-x <= tx <= b-x
    // a-y <= ty <= b-y
    int leftx = ids.lower_bound(a-x)->second;
    int rightx = ids.upper_bound(b-x)->second;
    bool ok = query(leftx,rightx,a-y,b-y,0,N,0);
    if(ok){
      puts("Yes");
      // DEBUG(i);DEBUG(j);DEBUG(k);DEBUG(x);DEBUG(y);
      // DEBUG(leftx);
      // DEBUG(rightx);
      // for(pll P : mp){
      //   DEBUG(P.first);
      //   DEBUG(P.second);
      // }
      return 0;
    }
  }
  puts("No");

  return 0;
}
accuracy: 0.7446808510638298
time_ms: 250
memory_kb: 9060
final_rank: 15

code_snippet: #if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int64_t N, MAX, MIN;
int32_t count[5] = {};
int64_t item[5][500][2] = {};
int32_t hash[5] = {0,1,2,3,4};

std::pair<int64_t, int64_t> patt_A[200 * 200 * 200];
auto patt_A_end = patt_A;
std::pair<int64_t, int64_t> patt_B[500*500];
auto patt_B_end = patt_B;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N>>MIN>>MAX;
	for (size_t t = 0; t < 5; t++)
	{
		item[t][count[t]][0] = 0;
		item[t][count[t]][1] = 0;
		++count[t];
	}
	for (int32_t i = 0; i < N; i++)
	{
		int64_t t, x, y;
		in >> t >> x >> y; --t;
		item[t][count[t]][0] = x;
		item[t][count[t]][1] = y;
		++count[t];
	}
	std::sort(hash, hash + 5, [](int i, int j) {return count[i] < count[j]; });

	for (int i = 0; i < count[hash[0]]; i++)
		for (int j = 0; j < count[hash[1]]; j++)
			for (int k = 0; k < count[hash[2]]; k++)
	{
		(*patt_A_end).first  = item[hash[0]][i][0] + item[hash[1]][j][0] + item[hash[2]][k][0];
		(*patt_A_end).second = item[hash[0]][i][1] + item[hash[1]][j][1] + item[hash[2]][k][1];
		++patt_A_end;
	}
	std::sort(patt_A, patt_A_end, std::greater<>{});
	for (int i = 0; i < count[hash[3]]; i++)
		for (int j = 0; j < count[hash[4]]; j++)
	{
		(*patt_B_end).first  = item[hash[3]][i][0] + item[hash[4]][j][0];
		(*patt_B_end).second = item[hash[3]][i][1] + item[hash[4]][j][1];
		++patt_B_end;
	}
	std::sort(patt_B, patt_B_end);

	std::multiset<int64_t> sets;
	auto B_beg_iter = patt_B, B_end_iter = patt_B;
	for (auto iter = patt_A; iter != patt_A_end; ++iter)
	{
		//push
		while (B_end_iter != patt_B_end && B_end_iter->first <= MAX - iter->first) {
			sets.insert(B_end_iter->second);
			++B_end_iter;
		}
		//pop
		while (B_beg_iter != B_end_iter &&B_beg_iter->first < MIN - iter->first) {
			sets.erase(sets.find(B_beg_iter->second));
			++B_beg_iter;
		}

		auto iter1 = sets.lower_bound(MIN - iter->second);
		if (iter1 != sets.end() && *iter1 + iter->second <= MAX) {
			out << "Yes" << endl;
			return 0;
		}
	}
	out << "No" << endl;

	return 0;
}
#endif
accuracy: 1
time_ms: 90
memory_kb: 19932
final_rank: 1