QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#386604 | #8550. All the Way Left | ucup-team087# | AC ✓ | 335ms | 4064kb | C++20 | 21.6kb | 2024-04-11 18:34:08 | 2024-04-11 18:34:09 |
Judging History
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
bool dbg=false;
#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>;
using vvi=vc<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));
}
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);
}
string rand_string(int n,char lw,char up){
string s(n,'?');
rep(i,n)s[i]=rand_int(lw,up);
return s;
}
int current_run_id,run_batch_size=1000;
int calc_random_limit(){
return current_run_id/run_batch_size+1;
}
template<class t>
void generate_single(t&a){
a=rand_int(1,calc_random_limit());
}
void generate_single(string&a){
int n;generate_single(n);
a=rand_string(n,'a','b');
}
template<class t,class u>
void generate_single(pair<t,u>&a){
generate_single(a.a);
generate_single(a.b);
}
//https://trap.jp/post/1224/
template<class... Args>
void input(Args&... a){
if(dbg){
(generate_single(a),...);
}else{
(cin >> ... >> a);
}
}
#define INT(...) int __VA_ARGS__;input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;input(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;input(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;input(__VA_ARGS__)
#define overload3(a,b,c,d,...) d
#define VI2(name,size) vi name(size);rep(i_##name,size)input(name[i_##name]);
#define VI3(name,size,offset) vi name(size);rep(i_##name,size)input(name[i_##name]),name[i_##name]+=offset;
#define VI(...) overload3(__VA_ARGS__,VI3,VI2)(__VA_ARGS__)
#define VPI(name,size) vc<pi> name(size);rep(i_##name,size)input(name[i_##name]);
#define VVI(name,sizeN,sizeM) vvi name(sizeN,vi(sizeM));\
rep(i_##name,sizeN)rep(j_##name,sizeM)input(name[i_##name][j_##name]);
#define VVT(type,name,sizeN,sizeM) vvc<type> name(sizeN,vc<type>(sizeM));
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){
if(dbg)cout<<endl;
else 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...);
}
template<class T>
void printvv(const vvc<T>&vs){
for(const auto&row:vs)print(row);
}
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 S> void mkuni(S&v){
sort(all(v));
v.erase(unique(all(v)),v.ed);
}
template<class t> bool isuni(vc<t> v){
int s=si(v);
mkuni(v);
return si(v)==s;
}
template<class t>
void myshuffle(vc<t>&a){
rep(i,si(a))swap(a[i],a[rand_int(0,i)]);
}
template<class S,class u>
int lwb(const S&v,const u&a){
return lower_bound(all(v),a)-v.bg;
}
template<class t,class u>
bool bis(const vc<t>&v,const u&a){
return binary_search(all(v),a);
}
//VERIFY: yosupo
//KUPC2017J
//AOJDSL1A
//without rank
struct unionfind{
vi p,s;
int c;
unionfind(int n):p(n,-1),s(n,1),c(n){}
void clear(){
fill(all(p),-1);
fill(all(s),1);
c=si(p);
}
int find(int a){
return p[a]==-1?a:(p[a]=find(p[a]));
}
//set b to a child of a
bool unite(int a,int b){
a=find(a);
b=find(b);
if(a==b)return false;
p[b]=a;
s[a]+=s[b];
c--;
return true;
}
bool same(int a,int b){
return find(a)==find(b);
}
int sz(int a){
return s[find(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){
if(dbg){
vvc<int> t(n);
unionfind uf(n);
while(uf.c>1){
int a=rand_int(n);
int b=rand_int(n);
if(uf.unite(a,b)){
t[a].pb(b);
t[b].pb(a);
}
}
return t;
}else{
return readGraph(n,n-1);
}
}
void printTree(const vvc<int> t){
int n=si(t);
int degsum=0;
rep(i,n)degsum+=si(t[i]);
if(degsum==n-1){
//directed
rep(i,si(t))for(auto j:t[i]){
print(i+1,j+1);
}
}else if(degsum==2*(n-1)){
//undirected
rep(i,si(t))for(auto j:t[i])if(i<j){
print(i+1,j+1);
}
}else{
assert(false);
}
}
template<class t>
vc<t> presum(const vc<t>&a){
vc<t> s(si(a)+1);
rep(i,si(a))s[i+1]=s[i]+a[i];
return s;
}
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,size_t K,class s=t>
s SUM(const array<t,K>&a){
return accumulate(all(a),s(0));
}
template<class t>
t MAX(const vc<t>&a){
return *max_element(all(a));
}
template<class t>
pair<t,int> MAXi(const vc<t>&a){
auto itr=max_element(all(a));
return mp(*itr,itr-a.bg);
}
template<class A>
auto MIN(const A&a){
return *min_element(all(a));
}
template<class t>
pair<t,int> MINi(const vc<t>&a){
auto itr=min_element(all(a));
return mp(*itr,itr-a.bg);
}
vi vid(int n){
vi res(n);iota(all(res),0);
return res;
}
template<class S>
void soin(S&s){
sort(all(s));
}
template<class S,class F>
void soin(S&s,F&&f){
sort(all(s),forward<F>(f));
}
template<class S>
S soout(S s){
soin(s);
return s;
}
template<class S>
void rein(S&s){
reverse(all(s));
}
template<class S>
S reout(S s){
rein(s);
return s;
}
template<class t,class u>
pair<t,u>&operator+=(pair<t,u>&a,pair<t,u> b){
a.a+=b.a;a.b+=b.b;return a;}
template<class t,class u>
pair<t,u>&operator-=(pair<t,u>&a,pair<t,u> b){
a.a-=b.a;a.b-=b.b;return a;}
template<class t,class u>
pair<t,u> operator+(pair<t,u> a,pair<t,u> b){return mp(a.a+b.a,a.b+b.b);}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a,pair<t,u> b){return mp(a.a-b.a,a.b-b.b);}
template<class t,class u,class v>
pair<t,u>&operator*=(pair<t,u>&a,v b){
a.a*=b;a.b*=b;return a;}
template<class t,class u,class v>
pair<t,u> operator*(pair<t,u> a,v b){return a*=b;}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a){return mp(-a.a,-a.b);}
namespace std{
template<class t,class u>
istream&operator>>(istream&is,pair<t,u>&a){
return is>>a.a>>a.b;
}
}
template<class t>
t gpp(vc<t>&vs){
assert(si(vs));
t res=move(vs.back());
vs.pop_back();
return res;
}
template<class t,class u>
void pb(vc<t>&a,const vc<u>&b){
a.insert(a.ed,all(b));
}
template<class t,class...Args>
vc<t> cat(vc<t> a,Args&&...b){
(pb(a,forward<Args>(b)),...);
return a;
}
template<class t,class u>
vc<t>& operator+=(vc<t>&a,u x){
for(auto&v:a)v+=x;
return a;
}
template<class t,class u>
vc<t> operator+(vc<t> a,u x){
return a+=x;
}
template<class t>
vc<t> operator+(const vc<t>&a,const vc<t>&b){
vc<t> c(max(si(a),si(b)));
rep(i,si(a))c[i]+=a[i];
rep(i,si(b))c[i]+=b[i];
return c;
}
template<class t,class u>
vc<t>& operator-=(vc<t>&a,u x){
for(auto&v:a)v-=x;
return a;
}
template<class t,class u>
vc<t>& operator-(vc<t> a,u x){
return a-=x;
}
template<class t,class u>
vc<t>& operator*=(vc<t>&a,u x){
for(auto&v:a)v*=x;
return a;
}
template<class t,class u>
vc<t>& operator*(vc<t> a,u x){
return a*=x;
}
template<class t,class u>
void remval(vc<t>&a,const u&v){
a.erase(remove(all(a),v),a.ed);
}
//消した要素の個数を返してくれる
//UCUP 2-8-F
template<class t,class F>
int remif(vc<t>&a,F f){
auto itr=remove_if(all(a),f);
int res=a.ed-itr;
a.erase(itr,a.ed);
return res;
}
template<class VS,class u>
void fila(VS&vs,const u&a){
fill(all(vs),a);
}
template<class t,class u>
int findid(const vc<t>&vs,const u&a){
auto itr=find(all(vs),a);
if(itr==vs.ed)return -1;
else return itr-vs.bg;
}
template<class t>
void rtt(vc<t>&vs,int i){
rotate(vs.bg,vs.bg+i,vs.ed);
}
//Multiuni2023-8 C
//f(lw)=false,...,f(n-1)=false,f(n)=true,...,f(up)=true,
//のときに n を返す
template<class F>
int find_min_true(int lw,int up,F f){
while(up-lw>1){
const int mid=(lw+up)/2;
if(f(mid))up=mid;
else lw=mid;
}
return up;
}
//f(lw)=true,f(up)=false
template<class F>
int find_max_true(int lw,int up,F f){
while(up-lw>1){
const int mid=(lw+up)/2;
if(f(mid))lw=mid;
else up=mid;
}
return lw;
}
template<class t> using pqmin=priority_queue<t,vc<t>,greater<t>>;
template<class t> using pqmax=priority_queue<t>;
using T=tuple<int,int,int>;
//copied from yosupo's library
//PARTLY 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();
}
ld rabs(const pt&a){
return a.rabs();
}
#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;
}
//normalize to [0,2*PI)
//Multiuni2023-10-E
ld normarg_nonnegative(ld a){
ld res=fmod(a,2*PI);
if(res<0)res+=2*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)));
}
//UCUP 2-20-D
ld heron(ld a,ld b,ld c){
ld s=(a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
#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;}
//c の位置を聞く関数です,b じゃないです
//(-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;
}
//stress-test してません
vc<pt> lower_convex(const vc<pt>&ps,bool onedge){
vc<pt> res;
assert(is_sorted(all(ps)));
for(auto p:ps){
int s;
while((s=si(res))>=2){
if(ccw(res[s-2],res[s-1],p)<=(onedge?-1:0))res.pop_back();
else break;
}
res.pb(p);
}
return res;
}
vc<pt> upper_convex(const vc<pt>&ps,bool onedge){
vc<pt> res;
assert(is_sorted(all(ps)));
for(auto p:ps){
int s;
while((s=si(res))>=2){
if(ccw(res[s-2],res[s-1],p)>=(onedge?1:0))res.pop_back();
else break;
}
res.pb(p);
}
return res;
}
vc<pt> convex(vc<pt> ps,bool onedge){
mkuni(ps);
auto lw=lower_convex(ps,onedge);
auto up=upper_convex(ps,onedge);
lw.pop_back();
rein(up);
up.pop_back();
pb(lw,up);
return lw;
}
void slv(){
INT(n);
vc<pt> ps(n);
rep(i,n)input(ps[i].x,ps[i].y);
if(n==1)return print(1);
auto c=convex(ps,true);
if(area2(c)==0)return print(2);
vc<pt> in;
for(auto p:ps)if(findid(c,p)==-1)in.pb(p);
auto work=[&](pt z){
vc<pt> ls;
for(auto p:in){
if(p!=z)ls.pb(p-z);
}
soin(ls,argless);
int res=0;
rep(i,si(ls)){
if(i==0||argless(ls[i-1],ls[i]))res++;
}
return res;
};
int ans=si(c);
for(auto z:c)ans+=work(z);
dmp(ans);
int tot=0;
for(auto z:in)tot+=work(z);
//assert(tot%2==0);
//tot/=2;
ans+=tot;
print(ans);
}
signed main(signed argc,char*argv[]){
if(argc>1&&strcmp(argv[1],"D")==0)dbg=true;
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
if(dbg){
while(1){
if(current_run_id%run_batch_size==0){
cerr<<"Current Run "<<current_run_id<<endl;
}
slv();
current_run_id++;
}
}else{
int t;cin>>t;rep(_,t)
slv();
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3912kb
input:
3 4 1 1 3 1 2 2 2 3 3 1 1 1 2 1 3 6 1 1 2 1 2 2 2 3 3 2 4 2
output:
6 2 13
result:
ok 3 number(s): "6 2 13"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
15 1 1 1 2 1 1 1 2 3 1 1 1 2 1 3 3 1 1 1 2 2 2 5 1 1 1 3 2 2 3 1 3 3 6 1 1 1 3 2 2 3 2 4 1 4 3 6 1 3 2 1 2 2 2 3 2 4 3 2 6 1 1 5 1 3 5 2 2 4 2 3 3 7 1 1 5 1 2 2 3 2 4 2 3 3 3 4 6 2 10 8 9 2 3 2 5 3 5 2 6 10 1 10 7 6 8 4 3 8 6 9 3 7 6 8 8 5 10 9 8 8 8 1 1 2 3 2 4 1 6 5 3 5 4 6 1 6 6 8 1 1 2 3 3 3 4 2...
output:
1 2 2 3 8 14 12 16 22 10 54 32 28 10 14
result:
ok 15 numbers
Test #3:
score: 0
Accepted
time: 11ms
memory: 3920kb
input:
10000 7 999999994 1000000000 999999998 999999997 999999999 999999994 999999998 999999994 999999996 999999998 1000000000 999999994 1000000000 999999997 6 999999998 5 999999998 6 999999994 5 999999994 1 999999998 4 999999995 5 7 2 2 3 6 7 5 3 5 2 4 7 4 6 2 3 77279810 642022026 309119240 107003671 4636...
output:
17 10 12 3 2 4 2 21 5 12 2 1 4 3 17 1 3 16 2 5 10 1 4 1 4 8 1 17 4 12 2 2 16 3 4 6 3 17 2 5 2 3 4 21 5 4 6 4 17 2 10 12 2 10 5 4 1 1 4 2 8 15 5 10 10 4 12 2 4 2 12 1 4 1 10 1 4 14 2 2 5 8 1 17 1 3 8 2 2 16 13 4 10 2 12 12 1 2 21 2 5 8 3 12 2 17 3 4 17 10 1 12 1 5 8 8 10 1 8 8 4 3 4 5 12 5 1 1 4 2 2 ...
result:
ok 10000 numbers
Test #4:
score: 0
Accepted
time: 23ms
memory: 3580kb
input:
10000 10 1000000000 999999996 999999992 999999996 999999993 1000000000 999999996 999999998 999999992 999999991 999999996 999999999 999999993 999999993 999999991 999999995 999999995 999999997 999999998 999999997 9 999999995 1000000000 999999993 999999992 999999999 1000000000 999999998 999999999 99999...
output:
47 16 29 34 28 14 36 26 14 26 15 34 8 16 32 38 2 44 3 19 14 4 6 33 10 10 12 12 17 8 25 8 33 14 30 11 10 19 40 34 33 41 6 5 22 10 17 16 6 16 2 41 29 33 20 26 10 21 2 32 26 47 33 3 31 12 30 16 14 24 10 12 22 17 40 6 23 26 23 17 28 3 16 4 36 46 12 3 48 21 6 14 39 40 29 23 33 34 12 9 6 10 12 32 34 3 28 ...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 122ms
memory: 3616kb
input:
10000 20 10 472423976 2 859313061 15 542767446 2 894484796 7 577939181 2 577939181 10 929656531 4 683454386 8 507595711 1 788969591 15 718626121 15 964828266 1 507595711 4 964828266 3 507595711 15 472423976 12 718626121 15 648282651 8 648282651 11 753797856 20 19 999999999 12 999999995 8 999999996 2...
output:
195 197 238 225 192 211 234 249 242 211 225 261 240 230 209 209 183 214 183 225 240 242 141 241 191 245 170 232 259 191 194 242 222 229 189 210 216 250 234 202 225 243 185 195 237 249 240 176 172 211 203 232 203 209 235 212 218 246 199 196 223 210 207 230 211 178 204 227 245 228 191 190 187 226 206 ...
result:
ok 10000 numbers
Test #6:
score: 0
Accepted
time: 127ms
memory: 3932kb
input:
10000 20 999999990 999999987 999999993 999999991 999999991 999999996 999999997 999999991 999999997 999999999 999999986 999999990 999999989 999999993 999999988 999999992 999999986 999999998 999999993 999999989 1000000000 999999994 999999995 999999988 999999991 999999989 999999994 999999994 999999996 ...
output:
250 208 219 215 216 224 160 224 185 209 186 231 205 210 209 248 189 198 224 233 221 232 216 213 221 230 203 213 208 242 201 227 254 210 206 246 239 246 172 213 223 205 218 232 194 228 230 208 247 209 238 245 224 251 234 214 221 256 231 245 240 228 158 213 242 231 192 232 221 208 190 232 208 247 229 ...
result:
ok 10000 numbers
Test #7:
score: 0
Accepted
time: 248ms
memory: 3780kb
input:
6 423 871052589 696370203 590606822 96125207 424963175 275218135 401552023 62808380 458556639 213160485 955603590 401616993 117520530 336079323 391036678 62821894 739838559 290358804 850343513 195705313 352952487 42119649 437338877 866366388 803885262 795778899 279023855 479705056 213974465 14674106...
output:
114514 1919810 1199282 974 26 1
result:
ok 6 numbers
Test #8:
score: 0
Accepted
time: 170ms
memory: 3744kb
input:
16 486 34060622 598468879 128647540 757780661 668466425 88271354 261524546 867470097 778177586 166231958 47339886 371835886 360942672 75140367 653090531 80941869 576631367 900830133 222375990 156853949 720877739 828175248 338270557 85134793 108934265 736556394 895297321 597692835 347786961 901398783...
output:
486 7442 6974 6402 113282 112138 121422 129176 272936 246268 273992 219769 265227 271284 229925 240937
result:
ok 16 numbers
Test #9:
score: 0
Accepted
time: 2ms
memory: 3824kb
input:
1 2000 368963 449991602 71690645 226469653 116119489 746924303 14456657 563523216 591696265 879438989 116209515 163496764 836456898 655094478 241619408 855832580 408694125 7058835 858105702 606589269 461893647 907489045 881686694 476771541 10299543 372869886 546580179 23973978 139944331 772781268 28...
output:
2000
result:
ok 1 number(s): "2000"
Test #10:
score: 0
Accepted
time: 3ms
memory: 3860kb
input:
1 2000 744286402 946400742 987763934 558344530 230642709 255584833 988354826 529569285 613631408 79006321 909007166 283642901 871800686 234872909 146697513 660667263 535381193 990122896 433983054 96440320 935182589 327092675 295229766 874996034 943116516 729567432 841158498 871565488 955381041 69966...
output:
29972
result:
ok 1 number(s): "29972"
Test #11:
score: 0
Accepted
time: 3ms
memory: 3836kb
input:
1 2000 769001450 754042265 25824918 578315923 195176522 830526044 660198770 102506141 176341551 814219275 361352592 56309147 860529759 319890700 143425404 781406087 826853273 258071284 452236374 42034217 857754231 612265458 870615679 346554880 366416325 54982850 132539126 199271969 320819767 6934938...
output:
29971
result:
ok 1 number(s): "29971"
Test #12:
score: 0
Accepted
time: 3ms
memory: 4024kb
input:
1 2000 92720650 320701832 868133136 724198785 701884285 873543357 132356020 684571482 523287572 31342492 396060735 44855451 949796867 494382726 833231382 768226875 943663059 423388738 896856813 680016197 505995366 30299910 520044988 913510433 254035248 816180553 586865276 42481991 156803847 21672662...
output:
39952
result:
ok 1 number(s): "39952"
Test #13:
score: 0
Accepted
time: 153ms
memory: 4016kb
input:
1 2000 921789228 394167112 67185499 569719790 684705345 738829782 360866636 555114318 846959948 713988184 113410674 337530338 935834181 437688129 251894406 879810056 97433362 685968840 899809289 344067418 832269999 246885813 381274629 252518169 826624109 240601626 495034793 888656585 313389757 52178...
output:
2007992
result:
ok 1 number(s): "2007992"
Test #14:
score: 0
Accepted
time: 153ms
memory: 3820kb
input:
1 2000 968352104 382682494 169810362 227039536 717966561 160707606 441686790 182476923 960722652 351321012 194467730 375514261 365912762 393135748 68576498 440778225 200672368 240077910 397172893 114006499 233424163 565208946 841069449 748138623 564685706 288340610 716483745 416169983 512789522 2061...
output:
1991245
result:
ok 1 number(s): "1991245"
Test #15:
score: 0
Accepted
time: 148ms
memory: 4032kb
input:
1 2000 339176530 362568555 954193274 419874680 511252289 988095198 90577325 572931848 521801976 138222296 235718442 856540834 689641989 940798368 163398420 342947025 908225644 338858057 931756216 559295464 596071112 194491827 892126869 413782835 334449675 192351238 199298090 299769065 957948062 6450...
output:
1992324
result:
ok 1 number(s): "1992324"
Test #16:
score: 0
Accepted
time: 149ms
memory: 3984kb
input:
1 2000 68023959 545355429 670976741 740016128 756274710 590394389 95885493 595690247 871395167 275123465 98557357 323741788 173795686 765626033 636750940 898363001 369796607 443301889 85748860 596231201 609909361 502550923 168226277 758782771 924672923 384159791 944148082 531941372 111732960 6502023...
output:
1984618
result:
ok 1 number(s): "1984618"
Test #17:
score: 0
Accepted
time: 335ms
memory: 3828kb
input:
1 2000 472317399 448095139 470057957 630422151 640572269 820742041 486621970 364956001 331756721 458127349 562088574 699893181 484360656 420118046 632196877 918382826 269387963 389598905 547430457 816036894 694837907 511061315 696696481 622416483 280660508 154457223 537659096 840781651 563474056 473...
output:
3974024
result:
ok 1 number(s): "3974024"
Test #18:
score: 0
Accepted
time: 327ms
memory: 3824kb
input:
1 2000 129892852 719880988 184919537 744105353 587102697 605473274 626545113 393257114 31249917 443389504 380359906 519791025 15047745 453844828 219382764 706338434 420710714 93495564 498185131 959746121 539399219 546379388 468794808 287432388 269897958 886528743 481025128 602157701 469331767 410256...
output:
3961204
result:
ok 1 number(s): "3961204"
Test #19:
score: 0
Accepted
time: 320ms
memory: 3828kb
input:
1 2000 510934899 547459563 519773921 365901465 496833202 515167890 654302266 231507260 733500503 460686130 432606988 77262088 25742008 636637521 134014773 686685517 379041620 252939972 681864072 251338397 855737338 246632327 309623668 229200708 692820865 277464076 288511703 248016522 286589348 51658...
output:
3964062
result:
ok 1 number(s): "3964062"
Test #20:
score: 0
Accepted
time: 329ms
memory: 4028kb
input:
1 2000 576715016 547277070 523392466 802721752 291730288 525334491 250099054 367469786 579560721 503865147 501420548 121382497 171360657 415872990 799343254 503750072 855064541 339988698 213016439 769254586 688291370 403587977 730744033 763739908 455349062 271922867 388474585 366824606 395462272 579...
output:
3950522
result:
ok 1 number(s): "3950522"
Test #21:
score: 0
Accepted
time: 329ms
memory: 3720kb
input:
1 2000 753399490 201420747 622181549 316348181 483137284 427471103 505501632 411398075 288945757 424009445 779719655 127660483 535994596 268390059 802466895 146833111 278458488 408398286 706788106 206012131 295405397 508692108 406905279 348331770 295353809 617182872 504337995 296574757 697746154 174...
output:
3992006
result:
ok 1 number(s): "3992006"
Test #22:
score: 0
Accepted
time: 328ms
memory: 4064kb
input:
1 2000 592736101 387284482 296073032 334186116 297857412 337555925 571732208 422401938 537700347 361036768 717213209 359576899 604927787 419384975 428138181 430955572 755558311 368389007 319563812 359681733 581471767 439734361 513676681 306659848 240266587 292815356 598054066 420025744 186430824 263...
output:
3991252
result:
ok 1 number(s): "3991252"
Test #23:
score: 0
Accepted
time: 329ms
memory: 3824kb
input:
1 2000 254482463 216326928 259688225 367860109 96889623 353950264 809227232 836951665 345354028 141005819 204570694 193377866 495650122 618254587 315571658 154789888 303782568 237636907 681975339 717893197 610887176 663410028 352777025 298763925 385694796 206052374 340672163 388607943 568842186 6266...
output:
3989972
result:
ok 1 number(s): "3989972"
Test #24:
score: 0
Accepted
time: 332ms
memory: 4060kb
input:
1 2000 662922115 221115958 587015717 182861841 732973227 202525759 610031685 182122157 600636621 175085573 356522102 591899596 675852703 207364274 374792496 523848515 541017593 394706666 639387965 189373958 717822245 235655806 604403003 326462818 495811759 360263663 576264288 181772296 418013709 605...
output:
3983682
result:
ok 1 number(s): "3983682"
Extra Test:
score: 0
Extra Test Passed