QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188910 | #5310. Painting | ExplodingKonjac | AC ✓ | 324ms | 53908kb | C++17 | 7.3kb | 2023-09-26 16:30:25 | 2023-09-26 16:30:27 |
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[300005],b[300005];
map<int,int> mp;
int f[300005][20],dep[300005];
RVec p[300005];
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,dep[1]=1;
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=18;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=18;i>=0;i--)
if(dep[f[v][i]]>dep[w] && cross(vt-vs,p[f[v][i]]-vs)>0)
v=f[v][i];
if(u!=w && cross(vt-vs,p[u]-vs)<0)
u=f[u][0];
if(v!=w && 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: 5ms
memory: 19456kb
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: 19408kb
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: 134ms
memory: 17100kb
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: 0
Accepted
time: 205ms
memory: 25512kb
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 ...
output:
(329779/1,466189/1) (329779/1,217124/1) (329779/1,369295/1) (329779/1,449439/1) (329779/1,495692/1) (329779/1,609424/1) (329779/1,769869/1) (329779/1,252064/1) (329779/1,610178/1) (13437175134/146647,62014289806/146647) (10705945456/80009,36488460402/80009) (329779/1,770652/1) (153173441467/524155,6...
result:
ok 300000 lines
Test #5:
score: 0
Accepted
time: 263ms
memory: 36300kb
input:
300000 694159 107635 109585 0 534761 296221 0 144102 179000 0 538335 642812 1 51653 789858 1 260572 297502 0 422312 230960 1 323495 527460 0 117743 91695 1 875390 106429 0 592512 956940 1 429082 37803 1 711668 658986 1 614065 738921 1 667461 145160 1 480889 809090 0 468893 650474 1 945932 974900 0 8...
output:
(694159/1,109585/1) (694159/1,296221/1) (694159/1,179000/1) (694159/1,642812/1) (168917345219/316864,196002519097/316864) (145023004121/701275,38089601594/140255) (257296280781/929557,321636734816/929557) (68594709903/395317,148038282320/395317) (15292322770/254751,29421309553/254751) (233969761745/...
result:
ok 300000 lines
Test #6:
score: 0
Accepted
time: 280ms
memory: 47068kb
input:
300000 841571 864537 929867 1 827774 222788 1 594947 97405 1 136507 869841 1 767546 276887 0 214999 287658 1 193877 95397 1 880581 221638 1 435653 172067 1 708385 794804 1 112241 426357 1 269382 890618 1 639737 968391 1 984457 815612 1 178024 935648 1 786418 222454 1 698936 199097 1 604327 637464 1 ...
output:
(841571/1,929867/1) (841571/1,222788/1) (841571/1,97405/1) (96452452310/307719,126053207273/307719) (5631793132/12703,6466646810/12703) (22018863644/220225,49249204851/220225) (24140464135/415907,77809902639/415907) (13502165124/724273,627208961121/724273) (125876299183/498460,88865122801/249230) (1...
result:
ok 300000 lines
Test #7:
score: 0
Accepted
time: 309ms
memory: 52716kb
input:
300000 423599 702291 13316 0 823376 324624 1 332084 339170 1 796909 473709 0 414801 475840 1 712638 235854 1 613165 447937 1 252983 673258 1 622687 27409 1 982234 935915 1 444618 148018 0 902272 211128 1 318963 363730 1 447033 949507 0 219549 778365 1 903735 908804 1 830179 642747 1 383246 554384 1 ...
output:
(423599/1,13316/1) (423599/1,324624/1) (104055399954/252919,85731000752/252919) (11211394733/175552,2052263037/2743) (173071961425/559791,257140876016/559791) (11469405033/48893,21933562806/48893) (42136663327/311556,2078565594/3709) (33507104499/413189,137773965562/413189) (672251613/71675,43686384...
result:
ok 300000 lines
Test #8:
score: 0
Accepted
time: 324ms
memory: 53908kb
input:
300000 606503 969162 499887 1 982467 476155 1 813898 466871 1 919610 819701 1 267484 907609 1 824721 490861 1 387197 878325 1 809204 742752 1 35348 71222 1 75368 820418 1 733140 325762 1 121959 320121 1 104047 533979 1 845038 737152 0 827435 615384 1 982300 340253 1 50533 570452 1 734351 776533 1 92...
output:
(606503/1,499887/1) (8069522415/37037,29651149119/37037) (606503/1,466871/1) (15026718328/184683,55786996082/61561) (165700865121/493576,306910313659/493576) (606503/1,490861/1) (258795436603/838155,534095910263/838155) (2846925082/280575,226730486612/280575) (606503/1,71222/1) (447920660590/1092077...
result:
ok 300000 lines
Test #9:
score: 0
Accepted
time: 144ms
memory: 21460kb
input:
300000 879149 116071 862 0 158243 245 0 148791 414 0 696577 955 0 382289 841 1 753537 277 0 691381 102 0 902273 638 0 636078 121 0 846069 338 0 209415 476 0 938281 286 0 567567 812 0 395269 317 0 638750 19 0 822890 57 0 529243 137 1 784931 595 0 904266 457 0 281103 606 0 207471 884 0 953117 757 0 87...
output:
(879149/1,862/1) (879149/1,245/1) (879149/1,414/1) (879149/1,955/1) (879149/1,841/1) (81595576988/92953,131957641/92953) (271737922708/309831,542457943/309831) (457143413616/520187,514911211/520187) (223118345561/254509,488684629/254509) (407731723220/464283,582330347/464283) (879149/1,476/1) (48879...
result:
ok 300000 lines
Test #10:
score: 0
Accepted
time: 182ms
memory: 24272kb
input:
300000 310835 319788 772 0 497504 964 0 894936 618 0 294654 90 0 881733 706 0 245858 983 0 559020 541 0 736248 666 0 453767 954 0 158758 958 0 763887 432 0 536922 327 0 882208 941 0 674991 503 0 92620 448 0 168993 777 1 645752 987 0 354095 426 0 356444 434 0 250356 643 1 279019 297 0 64002 163 0 804...
output:
(310835/1,772/1) (310835/1,964/1) (310835/1,618/1) (310835/1,90/1) (310835/1,706/1) (310835/1,983/1) (310835/1,541/1) (310835/1,666/1) (310835/1,954/1) (310835/1,958/1) (310835/1,432/1) (310835/1,327/1) (310835/1,941/1) (310835/1,503/1) (310835/1,448/1) (310835/1,777/1) (310835/1,987/1) (57536180170...
result:
ok 300000 lines
Test #11:
score: 0
Accepted
time: 207ms
memory: 32884kb
input:
300000 735537 701978 710 1 317350 506 1 994500 510 0 29112 354 1 595720 267 0 187266 549 0 778998 808 1 611272 914 0 99687 461 0 99147 712 0 156253 168 0 700158 863 0 39453 626 0 855867 553 0 841635 917 0 644146 114 1 519578 971 1 753580 742 1 219545 199 0 564270 186 0 26278 263 1 128304 400 0 34213...
output:
(735537/1,710/1) (735537/1,506/1) (35860125719/48787,58014370/48787) (735537/1,354/1) (204751434690/278609,216701870/278609) (95681595108/130127,79468554/130127) (735537/1,808/1) (33358809561/45455,103802386/45455) (735537/1,461/1) (53498793337/72803,175784818/218409) (93516909717/127327,50422746/12...
result:
ok 300000 lines
Test #12:
score: 0
Accepted
time: 275ms
memory: 49164kb
input:
300000 737138 938874 996 0 236261 342 1 294733 837 1 495487 53 1 767065 449 1 527431 967 1 769556 678 1 190570 261 0 937523 748 1 132549 535 1 666839 915 1 587237 49 1 621620 405 1 349581 510 1 234810 702 1 324423 189 1 201382 183 1 928491 1 0 616164 513 1 197342 29 1 49493 565 1 764718 8 1 657160 5...
output:
(737138/1,996/1) (737138/1,342/1) (737138/1,837/1) (73991701026/100769,199550885/100769) (43521733227/59090,31856143/29545) (44160831873/60038,63116917/30019) (175005038287/237491,222144699/237491) (737138/1,261/1) (473824935020/642879,564246467/642879) (76450056256/103905,81067877/103905) (18470098...
result:
ok 300000 lines