QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104128#6403. Master of PolygonmaroonrkTL 2963ms40100kbC++2020.6kb2023-05-09 01:35:432023-05-09 01:35:44

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-09 01:35:44]
  • 评测
  • 测评结果:TL
  • 用时:2963ms
  • 内存:40100kb
  • [2023-05-09 01:35:43]
  • 提交

answer

#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#endif

#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
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

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__,##__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<<"}";
}

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;
}

pi readpi(int off=0){
	int a,b;cin>>a>>b;
	return pi(a+off,b+off);
}

template<class t>
void print_single(t x,int suc=1){
	cout<<x;
	if(suc==1)
		cout<<"\n";
	if(suc==2)
		cout<<" ";
}

template<class t,class u>
void print_single(const pair<t,u>&p,int suc=1){
	print_single(p.a,2);
	print_single(p.b,suc);
}

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

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

template<class T,size_t N>
void print_single(const array<T,N>&v,int suc=1){
	rep(i,N)
		print_single(v[i],i==int(N)-1?suc:2);
}

template<class T>
void print(const T&t){
	print_single(t);
}

template<class T,class ...Args>
void print(const T&t,const Args&...args){
	print_single(t,2);
	print(args...);
}

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

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

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

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 topbit(ull 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 botbit(ull a){
	return a==0?64:__builtin_ctzll(a);
}
int popcount(signed t){
	return __builtin_popcount(t);
}
int popcount(ll t){
	return __builtin_popcountll(t);
}
int popcount(ull t){
	return __builtin_popcountll(t);
}
int bitparity(ll t){
	return __builtin_parityll(t);
}
bool ispow2(int i){
	return i&&(i&-i)==i;
}
ll mask(int i){
	return (ll(1)<<i)-1;
}
ull umask(int i){
	return (ull(1)<<i)-1;
}
ll minp2(ll n){
	if(n<=1)return 1;
	else return ll(1)<<(topbit(n-1)+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 mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
	#endif*/
	return uniform_int_distribution<ll>(l, r)(gen);
}

ll rand_int(ll k){ //[0,k)
	return rand_int(0,k-1);
}

template<class t>
void myshuffle(vc<t>&a){
	rep(i,si(a))swap(a[i],a[rand_int(0,i)]);
}

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

vvc<int> readGraph(int n,int m){
	vvc<int> g(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		//sc.read(a,b);
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	return g;
}

vvc<int> readTree(int n){
	return readGraph(n,n-1);
}

vc<ll> presum(const vi&a){
	vc<ll> s(si(a)+1);
	rep(i,si(a))s[i+1]=s[i]+a[i];
	return s;
}
//BIT で数列を管理するときに使う (CF850C)
template<class t>
vc<t> predif(vc<t> a){
	gnr(i,1,si(a))a[i]-=a[i-1];
	return a;
}
template<class t>
vvc<ll> imos(const vvc<t>&a){
	int n=si(a),m=si(a[0]);
	vvc<ll> b(n+1,vc<ll>(m+1));
	rep(i,n)rep(j,m)
		b[i+1][j+1]=b[i+1][j]+b[i][j+1]-b[i][j]+a[i][j];
	return b;
}

//verify してないや
void transvvc(int&n,int&m){
	swap(n,m);
}
template<class t,class... Args>
void transvvc(int&n,int&m,vvc<t>&a,Args&...args){
	assert(si(a)==n);
	vvc<t> b(m,vi(n));
	rep(i,n){
		assert(si(a[i])==m);
		rep(j,m)b[j][i]=a[i][j];
	}
	a.swap(b);
	transvvc(n,m,args...);
}
//CF854E
void rotvvc(int&n,int&m){
	swap(n,m);
}
template<class t,class... Args>
void rotvvc(int&n,int&m,vvc<t>&a,Args&...args){
	assert(si(a)==n);
	vvc<t> b(m,vi(n));
	rep(i,n){
		assert(si(a[i])==m);
		rep(j,m)b[m-1-j][i]=a[i][j];
	}
	a.swap(b);
	rotvvc(n,m,args...);
}

//ソートして i 番目が idx[i]
//CF850C
template<class t>
vi sortidx(const vc<t>&a){
	int n=si(a);
	vi idx(n);iota(all(idx),0);
	sort(all(idx),[&](int i,int j){return a[i]<a[j];});
	return idx;
}
//vs[i]=a[idx[i]]
//例えば sortidx で得た idx を使えば単にソート列になって返ってくる
//CF850C
template<class t>
vc<t> a_idx(const vc<t>&a,const vi&idx){
	int n=si(a);
	assert(si(idx)==n);
	vc<t> vs(n);
	rep(i,n)vs[i]=a[idx[i]];
	return vs;
}
//CF850C
vi invperm(const vi&p){
	int n=si(p);
	vi q(n);
	rep(i,n)q[p[i]]=i;
	return q;
}

template<class t,class s=t>
s SUM(const vc<t>&a){
	return accumulate(all(a),s(0));
}

template<class t>
t MAX(const vc<t>&a){
	return *max_element(all(a));
}

template<class t>
t MIN(const vc<t>&a){
	return *min_element(all(a));
}

template<class t,class u>
pair<t,u> operator+(const pair<t,u>&a,const pair<t,u>&b){
	return mp(a.a+b.a,a.b+b.b);
}

vi vid(int n){
	vi res(n);iota(all(res),0);
	return res;
}

template<class S>
S getrev(S s){
	reverse(all(s));
	return s;
}

pi operator+(pi a,pi b){return pi(a.a+b.a,a.b+b.b);}

template<class t>
t gpp(vc<t>&vs){
	assert(si(vs));
	t res=move(vs.back());
	vs.pop_back();
	return res;
}

//copied from yosupo's library
//ptARTLY VERIFIED

//USACO 2022 January ptlatinum C

//#define GEOF

#ifdef GEOF
using ld=long double;
//using ld=double;
const ld PI=acos(ld(-1));
#else
using ld=ll;
#endif
const ld eps=1e-9;
int sgn(ld a){return a<-eps?-1:(a>eps?1:0);}
int sgn(ld a,ld b){return sgn(a-b);}
/*
using pt=complex<ld>;
#define x real()
#define y imag()
*/
struct pt {
    ld x,y;
    //pt(ld _x = ld(0), ld _y = ld(0)) : x(_x), y(_y) {}
    pt():x(0),y(0){}
    pt(ld xx,ld yy):x(xx),y(yy){}
    pt operator+(const pt& r) const { return {x + r.x, y + r.y}; }
    pt operator-(const pt& r) const { return {x - r.x, y - r.y}; }
    pt operator*(const pt& r) const {
        return {x * r.x - y * r.y, x * r.y + y * r.x};
    }
    pt inv()const{
		ld d=norm();
		return {x/d,-y/d};
	}
    pt operator/(const pt&r)const{
		return operator*(r.inv());
	}

    pt operator*(const ld& r) const { return {x * r, y * r}; }
    pt operator/(const ld& r) const { return {x / r, y / r}; }

    pt& operator+=(const pt& r) { return *this = *this + r; }
    pt& operator-=(const pt& r) { return *this = *this - r; }
    pt& operator*=(const pt& r) { return *this = *this * r; }
    pt& operator/=(const pt& r) { return *this = *this / r; }
    pt& operator*=(const ld& r) { return *this = *this * r; }
    pt& operator/=(const ld& r) { return *this = *this / r; }

    pt operator-() const { return {-x, -y}; }

	static int cmp(const pt&a,const pt&b){
		int v=sgn(a.x,b.x);
		return v?v:sgn(a.y,b.y);
	}
    bool operator<(const pt& r) const {
        return cmp(*this,r)<0;
    }
    bool operator<=(const pt& r) const {
        return cmp(*this,r)<=0;
    }
    bool operator>(const pt& r) const {
        return cmp(*this,r)>0;
    }
    bool operator==(const pt& r) const { return sgn((*this - r).rabs()) == 0; }
    bool operator!=(const pt& r) const { return !(*this == r); }

    ld norm() const { return x * x + y * y; }
    ld rabs() const { return max(std::abs(x), std::abs(y)); }  // robust abs
    pair<ld, ld> to_pair() const { return {x, y}; }
    #ifdef GEOF
    ld abs() const { return sqrt(norm()); }
    ld arg() const { return atan2(y, x); }
    static pt polar(ld le, ld th) { return {le * cos(th), le * sin(th)}; }
	#endif
};
istream& operator>>(istream& is, pt& p){
	return is>>p.x>>p.y;
}
ostream& operator<<(ostream& os, const pt& p) {
    return os << "pt(" << p.x << ", " << p.y << ")";
}
ld norm(const pt&a){
	return a.norm();
}
#ifdef GEOF
ld abs(const pt&a){
	return sqrt(norm(a));
}
//XXII Opencup Gpt of Ural K
pt normalized(const pt&a){
	return a/abs(a);
}
ld arg(const pt&a){return a.arg();}
//normalize to [-PI,PI)
//Contest 2: ptKU Contest 1, ptTZ Summer 2022 Day 4
ld normarg(ld a){
	ld res=fmod(a+PI,2*PI);
	if(res<0)res+=PI;
	else res-=PI;
	return res;
}
//AOJ1183
//arg between ab
//assume given lengths are valid
ld arg(ld a,ld b,ld c){
	return acos(min(max((a*a+b*b-c*c)/(2*a*b),ld(-1)),ld(1)));
}
#endif
ld norm(const pt&a,const pt&b){
	return (a-b).norm();
}
ld dot(const pt&a,const pt&b){return a.x*b.x+a.y*b.y;}
ld crs(const pt& a,const pt& b){return a.x*b.y-a.y*b.x;}
ld crs(const pt& a,const pt& b,const pt& c){return crs(b-a,c-a);}
int ccw(const pt& a,const pt& b){return sgn(crs(a,b));}
int ccw(const pt& a,const pt& b,const pt& c){return ccw(b-a,c-a);}
//(-pi,0](0,pi]
int argtype(const pt&a){
	if(sgn(a.y)==0)return a.x<0?1:0;
	return a.y<0?0:1;
}
int argcmp(const pt&a,const pt&b){
	int at=argtype(a),bt=argtype(b);
	if(at!=bt)return at<bt?-1:1;
	return -ccw(a,b);
};
bool argless(const pt&a,const pt&b){return argcmp(a,b)<0;}
//(-2)[a,-1](0)[b,1](2)
int bet(pt a,pt b,pt c){
	pt d=b-a;
	ld e=dot(d,c-a);
	if(sgn(e)<=0)return sgn(e)-1;
	return sgn(e-norm(d))+1;
}
//AOJ0153
//三角形 abc に d が含まれるか?0-no,1-edge,2-in
int cont(pt a,pt b,pt c,pt d){
	if(ccw(a,b,c)==-1) swap(b,c);
	return min({ccw(a,b,d),ccw(b,c,d),ccw(c,a,d)})+1;
}
//(a,b) を結ぶ直線を考え,x 座標との交点の y 座標を求める
//(分子,分母)を返す
pair<ld,ld> xcut(const pt&a,const pt&b,ld x){
	return mp(a.y*(b.x-x)-b.y*(a.x-x),b.x-a.x);
}
//XXII Opencup Gpt of Ural K
pt rot90(pt a){
	return pt(-a.y,a.x);
}
#ifdef GEOF
ld xcutval(const pt&a,const pt&b,ld x){
	auto [p,q]=xcut(a,b,x);
	return p/q;
}
//AOJ1183
//Xmas2010 E
//-+ の 順で返す
//a の符号により,small/large が決まる
int qeq(ld a,ld b,ld c,ld&d,ld&e){
	if(sgn(a)==0){
		if(sgn(b)==0)return 0;
		d=-c/b;
		return 1;
	}
	ld f=b*b-4*a*c;
	if(sgn(f)<0)return 0;
	ld g=sqrt(max(f,ld(0)));
	d=(-b-g)/(2*a);
	e=(-b+g)/(2*a);
	return sgn(f)+1;
}
#else
pt normdir(pt a){
	if(a==pt(0,0))return a;
	int g=gcd(a.x,a.y);
	return pt(a.x/g,a.y/g);
}
#endif

ld area2(const vc<pt>&ps){
	ld res=0;
	rep(i,si(ps))res+=crs(ps[i],ps[(i+1)%si(ps)]);
	return res;
}

//UCUP 2023-3 F
template<class F>
void segeasy(int s,int l,int r,F f){
	for(l+=s,r+=s;l<r;l>>=1,r>>=1){
		if(l&1)f(l);
		if(r&1)f(r-1);
		l++; //ceil l
	}
}

//The 1st Universal Cup. Stage 15: Hangzhou J
struct F{
	ll a,b;
	F():a(0),b(1){}
	F(ll aa,ll bb):a(aa),b(bb){}
	F(pair<ll,ll> ab):F(ab.a,ab.b){}
	static int cmp(const F&a,const F&b){
		assert(a.b>=0);
		assert(b.b>=0);
		if(a.b==0&&b.b==0){
			assert(a.a!=0);
			assert(b.a!=0);
			return int(a.a>0)-int(b.a>0);
		}
		using T=__int128;
		T c=(T)a.a*b.b;
		T d=(T)b.a*a.b;
		return c<d?-1:c==d?0:1;
	}
	F operator-()const{return F{-a,b};}
	bool operator<(const F&r)const{
		return cmp(*this,r)<0;
	}
	bool operator>(const F&r)const{
		return cmp(*this,r)>0;
	}
	bool operator>=(const F&r)const{
		return cmp(*this,r)>=0;
	}
	bool operator==(const F&r)const{
		return cmp(*this,r)==0;
	}
	bool operator!=(const F&r)const{
		return cmp(*this,r)!=0;
	}
};
const F Finf{1,0};

//max hull
//有理数で全てを計算する
//The 1st Universal Cup. Stage 15: Hangzhou J

//Author: Simon Lindholm
//https://github.com/kth-competitive-programming/kactl/blob/master/content/data-structures/LineContainer.h
struct Line {
	mutable ll a,b;
	mutable F p;
	bool operator<(const Line& o) const { return a < o.a; }
	bool operator<(F x) const { return p<x;}
};
struct LineContainer:multiset<Line,less<>>{
	F div(ll a,ll b){return b<0?F{-a,-b}:F{a,b};}
	bool isect(iterator x, iterator y) {
		if (y == end()) { x->p = Finf; return false; }
		if (x->a == y->a) x->p = x->b > y->b ? Finf : -Finf;
		else x->p = div(y->b - x->b, x->a - y->a);
		return x->p>=y->p;
	}
	void add(ll a, ll b) {
		auto z = insert({a, b, F()}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}
	//x の分母が非負でないと壊れるだろうね
	//例えば (a,b) を add して,(pa+qb) の max を取りたい,みたいなクエリを考える
	//q>=0 ならば p/q をqueryすることで解決
	ll query(F x){
		assert(x.b>=0);
		//assert(!empty());
		if(empty())return -inf;
		auto l = *lower_bound(x);
		return l.a * x.a + l.b * x.b;
	}
};

//(x,y)->(x+y*eps,y) と変形してあると思い込む
//2 つの線分が占める x 座標の範囲に正の共通部分があるとする
//The 1st Universal Cup. Stage 15: Hangzhou J
struct S{
	//多分線分同士が端点以外で交わらないというケースだけ動くコード
	//線分に接するみたいな状況が発生すると話が変わってきてしまう
	pt a,b;
	S(){}
	S(const pt&aa,const pt&bb):a(min(aa,bb)),b(max(aa,bb)){assert(a<b);}
	bool operator<(const S&r)const{
		if(a==r.a)return ccw(a,b,r.b)>0;
		else if(a<r.a)return ccw(a,b,r.a)>0;
		else return ccw(r.a,r.b,a)<0;
	}
	F evaly(pt x)const{
		assert(a<=x&&x<=b);
		if(a.x==b.x)return F{x.y,1};
		else return xcut(a,b,x.x);
	}
	//値が 4 乗程度になりがち
	static int cmp(const S&a,const S&b,pt x){
		return F::cmp(a.evaly(x),b.evaly(x));
	}
	bool operator<(const pair<S,pt>&r)const{
		return cmp(*this,r.a,r.b)<0;
	}
};

bool dbg=false;
const int nmax=10;
const int qmax=10;
const int vmax=10;

void slv(){
	int n,q;
	if(dbg){
		n=rand_int(3,nmax);
		q=qmax;
	}else{
		cin>>n>>q;
	}
	vc<pt> ps(n);
	if(dbg){
		
	}else{
		rep(i,n)cin>>ps[i];
	}
	rotate(ps.bg,min_element(all(ps)),ps.ed);
	auto xy=ps;sort(all(xy));
	pt xymin=xy[0],xymax=xy[n-1];
	
	vc<S> qs(q);
	rep(i,q){
		pt a,b;
		if(dbg){
			do{
				a.x=rand_int(0,vmax);
				a.y=rand_int(0,vmax);
				b.x=rand_int(0,vmax);
				b.y=rand_int(0,vmax);
			}while(a==b);
		}else{
			cin>>a>>b;
		}
		qs[i]=S(a,b);
	}
	vi ans(q);
	rep(i,q){
		auto&[a,b]=qs[i];
		if(bis(xy,a)||bis(xy,b))ans[i]=1;
	}
	rep(i,q)if(ans[i]==0){
		auto [a,b]=qs[i];
		xy.pb(max(xymin,min(a,xymax)));
		xy.pb(max(xymin,min(b,xymax)));
	}
	mkuni(xy);
	int s=si(xy)-1;
	
	set<S,less<>> global;
	
	struct Q{
		F v;
		int i;
		bool operator<(const Q&r)const{
			if(v!=r.v)return v<r.v;
			else return i<r.i;
		}
	};
	vc<Q> w[2][2];
	
	auto getseg=[&](int i){
		pt a=ps[i],b=ps[(i+1)%n];
		if(a>b)swap(a,b);
		return S(a,b);
	};
	
	auto dfs=[&](auto self,int l,int r,vi pid,vi qid)->void{
		//pid の各区間は [xy[l],xy[r]] と正の交わりを持つ
		//qid の各区間は [xy[l],xy[r]] と正の交わりを持つ
		vc<decltype(global)::iterator> itrs;
		rep(i,2)rep(j,2)w[i][j].clear();
		for(int i=0;i<si(pid);){
			auto [a,b]=getseg(pid[i]);
			if(a<=xy[l]&&xy[r]<=b){
				auto [itr,ok]=global.emplace(a,b);
				itrs.pb(itr);
				assert(ok);
				i++;
			}else{
				int j=i+1;
				while(j<si(pid)){
					auto [c,d]=getseg(pid[j]);
					if(c<=xy[l]||xy[r]<=d)break;
					j++;
				}
				assert(j<si(pid));
				F lmin=Finf,lmax=-Finf;
				F rmin=Finf,rmax=-Finf;
				auto upd=[&](S t){
					if(t.a<=xy[l]){
						assert(t.b<xy[r]);
						auto v=t.evaly(xy[l]);
						chmin(lmin,v);
						chmax(lmax,v);
					}else{
						assert(xy[r]<=t.b);
						auto v=t.evaly(xy[r]);
						chmin(rmin,v);
						chmax(rmax,v);
					}
				};
				upd(getseg(pid[i]));
				upd(getseg(pid[j]));
				rng(k,i+1,j+1)w[0][0].pb({lmin,pid[k]});
				rng(k,i+1,j+1)w[0][1].pb({lmax,pid[k]});
				rng(k,i+1,j+1)w[1][0].pb({rmin,pid[k]});
				rng(k,i+1,j+1)w[1][1].pb({rmax,pid[k]});
				i=j+1;
			}
		}
		for(auto i:qid)if(ans[i]==0){
			auto [a,b]=qs[i];
			if(a<=xy[l]&&xy[r]<=b){
				auto j=global.lower_bound(mp(qs[i],xy[l]));
				if(j!=global.ed&&S::cmp(*j,qs[i],xy[l])==0){
					ans[i]=1;
					continue;
				}
				auto k=global.lower_bound(mp(qs[i],xy[r]));
				if(k!=global.ed&&S::cmp(*k,qs[i],xy[r])==0){
					ans[i]=1;
					continue;
				}
				if(j!=k){
					ans[i]=1;
				}
			}
		}
		rep(lr,2)rep(ud,2){
			for(auto i:qid)if(ans[i]==0){
				auto [a,b]=qs[i];
				if(a<=xy[l]&&xy[r]<=b){
					auto v=qs[i].evaly(lr==0?xy[l]:xy[r]);
					w[lr][ud].pb({v,inf+i});
				}
			}
			if(ud)for(auto&[v,i]:w[lr][ud])v.a=-v.a;
			sort(all(w[lr][ud]));
			LineContainer lc;
			F pre=-Finf;
			for(auto [v,i]:w[lr][ud]){
				if(i<inf){
					pt a=ps[i];
					if(ud)a.y=-a.y;
					lc.add(a.x,a.y);
					pre=v;
				}else{
					i-=inf;
					if(pre==v)ans[i]=1;
					else{
						auto [a,b]=qs[i];
						if(ud){
							a.y=-a.y;
							b.y=-b.y;
						}
						pt dir=rot90(b-a);
						ll val=lc.query(F(dir.x,dir.y));
						if(dot(a,dir)<=val)ans[i]=1;
					}
				}
			}
		}
		if(r-l>1){
			vi pl,pr,ql,qr;
			int m=(l+r)/2;
			for(auto i:pid){
				auto [a,b]=getseg(i);
				if(a<=xy[l]&&xy[r]<=b)continue;
				if(a<xy[m])pl.pb(i);
				if(xy[m]<b)pr.pb(i);
			}
			for(auto i:qid)if(ans[i]==0){
				auto [a,b]=qs[i];
				if(a<=xy[l]&&xy[r]<=b)continue;
				if(a<xy[m])ql.pb(i);
				if(xy[m]<b)qr.pb(i);
			}
			self(self,l,m,pl,ql);
			self(self,m,r,pr,qr);
		}
		for(auto itr:itrs)global.erase(itr);
	};
	dfs(dfs,0,s,vid(n),vid(q));
	if(dbg){
		
	}else{
		rep(i,q){
			if(ans[i])YES(0);
			else NO(0);
		}
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	if(dbg){
	}else{
	//int t;cin>>t;rep(_,t)
		slv();
	}
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3468kb

input:

4 6
1 1
4 1
4 4
1 4
0 2 2 0
0 1 1 1
0 0 5 5
2 2 4 2
2 2 3 2
5 1 0 2

output:

YES
YES
YES
YES
NO
YES

result:

ok 6 token(s): yes count is 5, no count is 1

Test #2:

score: 0
Accepted
time: 1194ms
memory: 35032kb

input:

20 200000
8838 9219
12190 11292
15953 7581
16690 6159
21104 5484
8978 1076
4354 1065
1261 676
12684 14159
15469 22416
13493 28027
15531 26837
18253 26053
26444 24253
22160 19958
24879 12856
28793 22156
25300 10245
14749 15078
12946 13942
26544 28338 18806 21279
5592 29200 20935 25253
28189 17513 215...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES...

result:

ok 200000 token(s): yes count is 156067, no count is 43933

Test #3:

score: 0
Accepted
time: 1136ms
memory: 32608kb

input:

500 200000
17729 7936
17684 8099
17925 10195
17441 9150
17314 9604
17008 8764
17003 7525
16501 4085
16247 5851
16768 625
16492 706
15995 4316
16287 976
16032 629
15217 133
15692 4260
16153 6940
15550 5717
15493 4823
15085 4477
14465 4830
13595 4960
13721 3490
13309 2776
11167 3053
14319 2156
14626 2...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
Y...

result:

ok 200000 token(s): yes count is 197031, no count is 2969

Test #4:

score: 0
Accepted
time: 1119ms
memory: 30492kb

input:

2000 200000
15746 1958
15965 1785
16322 2203
16779 3060
15774 2055
15869 2486
16141 3025
14987 1567
16314 3508
14816 1823
13841 1058
15595 3183
15716 4094
15939 4023
16426 4179
16507 5225
17035 6211
17233 5343
18059 5915
17140 5103
17154 4324
17471 4562
18065 5767
20733 10646
21651 12444
18707 6969
...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 200000 token(s): yes count is 199151, no count is 849

Test #5:

score: 0
Accepted
time: 990ms
memory: 25788kb

input:

2000 200000
11439 4221
11601 4531
11351 4595
10165 4725
11049 4209
9643 4623
8884 4596
8598 4376
10987 3767
10577 3606
10678 3417
10159 3481
10288 3302
11157 2781
10513 2652
10601 2489
10785 2201
9881 2932
10877 1775
9578 3034
9083 3337
8118 4188
8911 3253
10649 1785
6624 3607
6002 3749
10788 1539
8...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 200000 token(s): yes count is 1564, no count is 198436

Test #6:

score: 0
Accepted
time: 1090ms
memory: 25252kb

input:

2000 200000
25931 29637
25732 29388
25090 29397
24676 29660
24268 29454
24712 28969
24252 27672
23976 28067
24211 27138
24428 27732
24389 27010
24062 26426
24278 25689
24727 26596
25281 28154
25062 26750
24927 26324
24625 25457
25456 26307
25444 25561
26008 27471
26065 27717
26065 27194
25255 24568
...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 200000 token(s): yes count is 5859, no count is 194141

Test #7:

score: 0
Accepted
time: 1335ms
memory: 24384kb

input:

2000 200000
14066 4014
14235 4742
15201 5329
15389 5460
11381 3722
12856 4511
8264 2372
13039 4278
11684 3711
12888 4180
11849 3607
11431 3373
9979 2823
9099 2534
9055 2434
9393 2382
9867 2512
10315 2558
8175 1662
6480 184
5437 92
4413 100
5548 790
4362 471
4463 552
4817 748
6715 1673
5807 1562
7942...

output:

NO
YES
YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
YES
NO
YES
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
...

result:

ok 200000 token(s): yes count is 55692, no count is 144308

Test #8:

score: 0
Accepted
time: 1122ms
memory: 26180kb

input:

2000 200000
14977 2004
14689 1703
15835 1810
16896 1690
16802 1617
16193 869
15027 1025
14890 398
15977 29
17024 621
16998 991
17114 745
18865 277
18293 764
18306 941
19319 12
17810 1554
19311 271
17748 1881
15553 3843
17271 2971
18157 1924
19839 300
19482 727
19186 1301
19603 836
19522 1061
19765 1...

output:

YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
...

result:

ok 200000 token(s): yes count is 171136, no count is 28864

Test #9:

score: 0
Accepted
time: 1384ms
memory: 21968kb

input:

99966 1000
25033 23639
25334 23745
25777 23856
25534 23761
24893 23589
24648 23517
24596 23501
24535 23479
24356 23416
24269 23406
24131 23319
24905 23572
24978 23588
24418 23387
23595 23085
24070 23293
23843 23200
23484 23078
23596 23125
23438 23066
23142 22915
24265 23317
23323 22980
23624 23088
2...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 1000 token(s): yes count is 1000, no count is 0

Test #10:

score: 0
Accepted
time: 1359ms
memory: 23040kb

input:

99969 1000
19235 2200
19307 2137
19620 1920
19590 1908
19486 1919
19280 2087
19260 2029
19226 2197
19147 2281
19135 2254
19095 2304
19207 2101
18981 2354
18936 2288
18943 2166
18851 2224
18697 2428
19149 2332
18976 2371
18948 2403
19134 2347
19220 2323
19196 2374
19128 2467
19084 2485
19018 2464
190...

output:

NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
N...

result:

ok 1000 token(s): yes count is 173, no count is 827

Test #11:

score: 0
Accepted
time: 1344ms
memory: 22168kb

input:

99976 1000
23538 24587
23600 24898
23569 24997
23628 25053
23693 25259
23691 25126
23674 25068
23623 24923
23664 25002
23713 25142
23659 24925
23558 24571
23523 24358
23569 24559
23578 24562
23637 24783
23621 24703
23685 24932
23735 25098
23768 25199
23802 25254
23768 25186
23774 25165
23645 24685
2...

output:

YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
NO
YES
YES
YES
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
NO
YES...

result:

ok 1000 token(s): yes count is 666, no count is 334

Test #12:

score: 0
Accepted
time: 2947ms
memory: 36940kb

input:

199886 1000
14938 9857
14804 10006
14968 9807
14708 10115
14761 10098
14678 10167
14648 10192
14715 10150
14497 10337
14635 10227
14596 10269
14648 10256
14774 10175
14682 10266
14490 10424
14602 10339
14754 10214
14490 10489
14360 10622
14157 10755
14299 10632
14431 10511
14245 10670
14429 10473
14...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 1000 token(s): yes count is 1000, no count is 0

Test #13:

score: 0
Accepted
time: 2930ms
memory: 40100kb

input:

199901 1000
1983 26999
2038 26992
2067 26988
2231 26970
2022 26966
2763 26923
2133 26996
2353 26976
2258 26995
2211 27022
2129 27045
2138 27046
2532 27004
2630 26988
3195 26898
3060 26912
3210 26895
3069 26904
2936 26918
2839 26924
2998 26888
2696 26891
2461 26909
2257 26930
1640 26991
1708 26971
18...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

ok 1000 token(s): yes count is 88, no count is 912

Test #14:

score: 0
Accepted
time: 2904ms
memory: 39736kb

input:

199898 1000
18799 13687
18845 13550
18777 13722
18754 13747
18726 13809
18674 13927
18698 13858
18740 13747
18818 13555
18664 13906
18651 13907
18649 13898
18605 13894
18656 13746
18693 13650
18784 13527
18811 13447
18775 13570
18818 13471
18851 13382
18907 13296
18924 13316
18943 13240
18829 13393
...

output:

NO
YES
NO
NO
NO
YES
NO
YES
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
...

result:

ok 1000 token(s): yes count is 235, no count is 765

Test #15:

score: 0
Accepted
time: 2928ms
memory: 39004kb

input:

199886 1000
10118 8021
10120 8003
10112 8046
10126 8048
10157 8041
10255 8007
10140 8106
10114 8118
10137 8118
10284 8037
10259 8097
10381 8066
10302 8091
10209 8127
10185 8149
10199 8146
10314 8117
10340 8108
10261 8229
10328 8182
10333 8267
10377 8257
10465 8176
10416 8235
10421 8256
10400 8332
10...

output:

NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES...

result:

ok 1000 token(s): yes count is 762, no count is 238

Test #16:

score: 0
Accepted
time: 2963ms
memory: 37264kb

input:

199879 1000
18589 2979
18584 2916
18708 2953
18498 2855
18498 2848
18472 2840
18436 2819
18649 2859
18521 2809
18573 2808
18386 2799
18442 2784
18486 2785
18648 2774
18360 2745
18649 2770
18730 2789
18716 2804
18731 2927
18751 2963
18855 2956
18826 2904
18833 2895
18848 2902
18851 2916
18922 2944
18...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 1000 token(s): yes count is 987, no count is 13

Test #17:

score: -100
Time Limit Exceeded

input:

199874 200000
8778 8537
8541 8516
8372 8496
7893 8430
7794 8429
7968 8456
7837 8443
7844 8452
8024 8493
8016 8501
8137 8518
7682 8492
7633 8489
7684 8508
7633 8520
8523 8538
8449 8539
7714 8536
7660 8547
8781 8557
7918 8557
8942 8561
9037 8578
9079 8577
9031 8586
9310 8621
9280 8625
9224 8619
8927 8...

output:


result: