QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188890 | #5310. Painting | ExplodingKonjac | RE | 144ms | 8548kb | C++17 | 7.3kb | 2023-09-26 16:11:52 | 2023-09-26 16:11:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define OPENIOBUF
namespace FastIO
{
class FastIOBase
{
protected:
#ifdef OPENIOBUF
static const int BUFSIZE=1<<16;
char buf[BUFSIZE+1];
int buf_p=0;
#endif
FILE *target;
FastIOBase(FILE *f): target(f){}
~FastIOBase()=default;
public:
#ifdef OPENIOBUF
virtual void flush()=0;
#endif
};
class FastOutput final: public FastIOBase
{
private:
void __putc(char x)
{
#ifdef OPENIOBUF
if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
putc(x,target);
#endif
}
template<typename T>
void __write(T x)
{
char stk[64],*top=stk;
if(x<0) return __putc('-'),__write(-x);
do *(top++)=x%10,x/=10; while(x);
for(;top!=stk;__putc(*(--top)+'0'));
}
public:
FastOutput(FILE *f=stdout): FastIOBase(f) {}
#ifdef OPENIOBUF
~FastOutput() { flush(); }
void flush() { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
FastOutput &operator <<(char x)
{ return __putc(x),*this; }
FastOutput &operator <<(const char *s)
{ for(;*s;__putc(*(s++)));return *this; }
FastOutput &operator <<(const std::string &s)
{ return (*this)<<s.c_str(); }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastOutput&> operator <<(const T &x)
{ return __write(x),*this; }
template<typename ...T>
void writesp(const T &...x)
{ std::initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
template<typename ...T>
void writeln(const T &...x)
{ std::initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
template<typename Iter>
void writesp(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<' '; }
template<typename Iter>
void writeln(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;
class FastInput final: public FastIOBase
{
private:
bool __eof;
public:
FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
{ buf_p=BUFSIZE; }
void flush() { buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
bool eof()const { return buf[buf_p]==EOF; }
#else
{}
bool eof()const { return feof(target); }
#endif
char get()
{
if(__eof) return EOF;
#ifdef OPENIOBUF
if(buf_p==BUFSIZE) flush();
char ch=buf[buf_p++];
#else
char ch=getc(target);
#endif
return ~ch?ch:(__eof=true,EOF);
}
void unget(char c)
{
__eof=false;
#ifdef OPENIOBUF
buf_p--;
#else
ungetc(c,target);
#endif
}
explicit operator bool()const { return !__eof; }
FastInput &operator >>(char &x)
{ while(isspace(x=get()));return *this; }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastInput&> operator >>(T &x)
{
char ch,sym=0;x=0;
while(isspace(ch=get()));
if(__eof) return *this;
if(ch=='-') sym=1,ch=get();
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=get());
return unget(ch),sym?x=-x:x,*this;
}
FastInput &operator >>(char *s)
{
while(isspace(*s=get()));
if(__eof) return *this;
for(;!isspace(*s) && !__eof;*(++s)=get());
return unget(*s),*s='\0',*this;
}
FastInput &operator >>(std::string &s)
{
char str_buf[(1<<8)+1]={0},*p=str_buf;
char *const buf_end=str_buf+(1<<8);
while(isspace(*p=get()));
if(__eof) return *this;
for(s.clear(),p++;;p=str_buf)
{
for(;p!=buf_end && !isspace(*p=get()) && !__eof;p++);
if(p!=buf_end) break;
s.append(str_buf);
}
unget(*p),*p='\0',s.append(str_buf);
return *this;
}
template<typename ...T>
void read(T &...x)
{ std::initializer_list<int>{(this->operator>>(x),0)...}; }
template<typename Iter>
void read(Iter begin,Iter end)
{ while(begin!=end) (*this)>>*(begin++); }
}qin;
} // namespace FastIO
using FastIO::qin,FastIO::qout;
using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;
#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#define LOG(...) void()
#else
#define FILEIO(file)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
#endif
namespace Math
{
// A class for 2D vectors.
template<typename T>
struct Vector2d
{
#define DEF_OP1(op) \
Vector2d &operator op##=(const Vector2d &rhs) \
{ return x op##= rhs.x,y op##= rhs.y,*this; } \
Vector2d operator op(const Vector2d &rhs)const \
{ return Vector2d(*this)op##=rhs; }
T x,y;
Vector2d(): x(0),y(0){}
Vector2d(T _x,T _y): x(_x),y(_y){}
DEF_OP1(+) DEF_OP1(-) DEF_OP1(*) DEF_OP1(/)
Vector2d &operator *=(T scale)
{ return x*=scale,y*=scale,*this; }
friend Vector2d operator *(T scale,const Vector2d &u)
{ return Vector2d(u)*=scale; }
friend Vector2d operator *(const Vector2d &u,T scale)
{ return Vector2d(u)*=scale; }
friend auto cross(const Vector2d &u,const Vector2d &v)
{ return u.x*v.y-u.y*v.x; }
friend auto dot(const Vector2d &u,const Vector2d &v)
{ return u.x*v.x+u.y*v.y; }
friend auto abs(const Vector2d &u)
{ return hypot(u.x,u.y); }
friend auto abs2(const Vector2d &u)
{ return u.x*u.x+u.y*u.y; }
friend auto arg(const Vector2d &u)
{ return atan2(u.y,u.x); }
auto proj(const Vector2d &u)const
{ return (*this)*(dot(u,*this)/abs2(*this)); }
auto trunc(T r=1)const
{ T l=abs(*this);return sgn(l)?(*this)*(r/l):*this; }
auto rotate(T t)const
{ return Vector2d(x*cos(t)-y*sin(t),x*sin(t)+y*cos(t)); }
bool operator <(const Vector2d &rhs)const
{ return x!=rhs.x?x<rhs.x:y<rhs.y; }
bool operator ==(const Vector2d &rhs)const
{ return FEQ(x,rhs.x) && FEQ(y,rhs.y); }
bool operator !=(const Vector2d &rhs)const
{ return FNE(x,rhs.x) || FNE(y,rhs.y); }
#undef DEF_OP1
};
} // namespace Math
using RVec=Math::Vector2d<LD>;
constexpr int V=1e6;
int n,W,m,a[100005],b[100005];
map<int,int> mp;
int f[100005][20],dep[100005];
RVec p[100005];
RVec intersect(int x,int y)
{
if(x==1) return RVec(W,b[y]);
if(y==1) return RVec(W,b[x]);
return RVec(LD(a[x]-a[y])*W/(a[x]-a[y]-b[x]+b[y]),
-((LD)a[y]*b[x]-(LD)a[x]*b[y])/(a[x]-a[y]-b[x]+b[y]));
}
void norm(LL &num,LL &den)
{
LL g=__gcd(num,den);
num/=g,den/=g;
}
void add(int u,int fa)
{
f[u][0]=fa,dep[u]=dep[fa]+1;
for(int i=1;(1<<i)<=dep[u];i++)
f[u][i]=f[f[u][i-1]][i-1];
mp[a[u]]=u;
p[u]=intersect(u,fa);
}
int lca(int u,int v)
{
if(dep[u]<dep[v]) swap(u,v);
for(int i=18;i>=0;i--)
if(dep[f[u][i]]>=dep[v])
u=f[u][i];
if(u==v) return u;
for(int i=18;i>=0;i--)
if(f[u][i]!=f[v][i])
u=f[u][i],v=f[v][i];
return f[u][0];
}
int main()
{
qin>>n>>W;
m=3;
a[2]=b[2]=0,add(2,1);
a[3]=b[3]=V+1,add(3,1);
for(int o=1;o<=n;o++)
{
int opt,s,t;
qin>>s>>t>>opt;
auto it=mp.lower_bound(s);
RVec vs(0,s),vt(W,t);
int u=prev(it)->second,v=it->second,w=lca(u,v);
for(int i=__lg(dep[u]-dep[w]);i>=0;i--)
if(dep[f[u][i]]>dep[w] && cross(vt-vs,p[f[u][i]]-vs)<=0)
u=f[u][i];
for(int i=__lg(dep[v]-dep[w]);i>=0;i--)
if(dep[f[v][i]]>dep[w] && cross(vt-vs,p[f[v][i]]-vs)>=0)
v=f[v][i];
if(cross(vt-vs,p[u]-vs)<=0)
u=f[u][0];
if(cross(vt-vs,p[v]-vs)>=0)
v=f[v][0];
w=(u==w?v:v==w?u:0);
assert(w);
LL xnum=(w==1?W:LL(s-a[w])*W),xden=(w==1?1:(s-a[w]-t+b[w])),
ynum=(w==1?t:-((LL)a[w]*t-(LL)s*b[w])),yden=(w==1?1:(s-a[w]-t+b[w]));
norm(xnum,xden);
norm(ynum,yden);
qout<<'('<<xnum<<'/'<<xden<<','
<<ynum<<'/'<<yden<<")\n";
if(opt) m++,a[m]=s,b[m]=t,add(m,w);
}
return 0;
}
/*
4 3
1 2 1
2 1 1
3 1 0
3 2 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8000kb
input:
4 3 1 2 1 2 1 1 3 1 0 3 2 1
output:
(3/1,2/1) (3/2,3/2) (2/1,5/3) (3/1,2/1)
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 144ms
memory: 8104kb
input:
300000 894665 1 1000000 1 2 999999 1 3 999997 1 4 999994 1 5 999990 1 6 999985 1 7 999979 1 8 999972 1 9 999964 1 10 999955 1 11 999945 1 12 999934 1 13 999922 1 14 999909 1 15 999895 1 16 999880 1 17 999864 1 18 999847 1 19 999829 1 20 999810 1 21 999790 1 22 999769 1 23 999747 1 24 999724 1 25 999...
output:
(894665/1,1000000/1) (894665/2,1000001/2) (894665/3,1000003/3) (894665/4,500003/2) (178933/1,200002/1) (894665/6,1000015/6) (894665/7,1000021/7) (894665/8,250007/2) (894665/9,1000036/9) (178933/2,200009/2) (894665/11,1000055/11) (894665/12,500033/6) (894665/13,1000078/13) (894665/14,1000091/14) (178...
result:
ok 300000 lines
Test #3:
score: 0
Accepted
time: 133ms
memory: 8548kb
input:
300000 748539 1 1000000 1 2 999999 1 3 999997 1 4 999994 1 5 999990 1 6 999985 1 7 999979 1 8 999972 1 9 999964 1 10 999955 1 11 999945 1 12 999934 1 13 999922 1 14 999909 1 15 999895 1 16 999880 1 17 999864 1 18 999847 1 19 999829 1 20 999810 1 21 999790 1 22 999769 1 23 999747 1 24 999724 1 25 999...
output:
(748539/1,1000000/1) (748539/2,1000001/2) (249513/1,1000003/3) (748539/4,500003/2) (748539/5,200002/1) (249513/2,1000015/6) (748539/7,1000021/7) (748539/8,250007/2) (83171/1,1000036/9) (748539/10,200009/2) (68049/1,1000055/11) (249513/4,500033/6) (748539/13,1000078/13) (748539/14,1000091/14) (249513...
result:
ok 300000 lines
Test #4:
score: -100
Runtime Error
input:
300000 329779 725400 466189 0 162004 217124 0 17706 369295 0 143330 449439 0 974743 495692 0 476940 609424 0 307270 769869 0 664031 252064 0 350818 610178 1 432310 398376 1 578066 277363 0 891345 770652 0 815291 550496 0 756083 89624 0 867560 132663 0 668047 648059 0 758279 558971 0 647877 798646 0 ...