QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687503 | #5310. Painting | FreeTimeLove | RE | 709ms | 49576kb | C++14 | 3.9kb | 2024-10-29 19:23:52 | 2024-10-29 19:23:53 |
Judging History
answer
#include<bits/stdc++.h>
namespace FRTMLV{
#define ll long long
#define LD long double
#define i7 __int128
#define re return
#define con continue
using namespace std;
template<class T>inline bool ckmin(T &a,T b){re b<a?a=b,1:0;}
template<class T>inline bool ckmax(T &a,T b){re a<b?a=b,1:0;}
const int N=6e5+5;
inline int rd(){
int ans=0,f=0;
char ch=getchar();
while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
re f?-ans:ans;
}
const int MX=1e6+1;
int n,W,tt;
int nx[N][20],siz[N];
//
set<int>st;
int hd[MX+5];
//
inline i7 abs(i7 x){re x<0?-x:x;}
struct frac{
// ll x,y;
i7 x,y;
// void clr(){if(y<0)y=-y,x=-x;ll g=llabs(__gcd(x,y));x/=g,y/=g;}
void clr(){if(y<0)y=-y,x=-x;i7 g=abs(__gcd(x,y));x/=g,y/=g;}
frac operator +(const frac &a)const{frac ans={x*a.y+y*a.x,y*a.y};ans.clr();re ans;}
frac operator -(const frac &a)const{frac ans={x*a.y-y*a.x,y*a.y};ans.clr();re ans;}
frac operator *(const frac &a)const{frac ans={x*a.x,y*a.y};ans.clr();re ans;}
frac operator /(const frac &a)const{frac ans={x*a.y,y*a.x};ans.clr();re ans;}
bool operator <(const frac &a)const{re x*a.y<a.x*y;}
bool operator ==(const frac &a)const{re x*a.y==a.x*y;}
};
struct point{
frac x,y;
void out(){
printf("(%lld/%lld,%lld/%lld)\n",(ll)x.x,(ll)x.y,(ll)y.x,(ll)y.y);
}
}p[N];
struct line{
frac k,b;
inline frac gty(frac x){re k*x+b;}
};
inline frac gtx(line &l1,line &l2){re (l1.b-l2.b)/(l2.k-l1.k);}
int addfront(point P,int id){
p[++tt]=P,siz[tt]=siz[id]+1,nx[tt][0]=id;
for(int i=1;i<20;i++)nx[tt][i]=nx[nx[tt][i-1]][i-1];
re tt;
}
int gt(int id,int sum){
for(int i=19;i>=0;i--)
if(sum>=(1<<i))sum-=1<<i,id=nx[id][i];
re id;
}
void addback(int id,point P){
p[++tt]=P,siz[id]++;
int cnt=0;
while(siz[id]-1>=(1<<(cnt+1)))++cnt;
// int nid=gt(id,siz[id]-(1<<cnt));
id=gt(id,siz[id]-1-(1<<cnt));
for(int i=cnt;i;i--)nx[id][i]=tt,id=nx[id][i-1];
nx[id][0]=tt;
}
signed main(){
n=rd(),W=rd();
while(n--){
int y1=rd(),y2=rd(),fl=rd();
frac tmp={y2-y1,W};tmp.clr();
point P={(frac){0,1},(frac){y1,1}};
line li={tmp,(frac){y1,1}};
if(!tt){
printf("(%d/1,%d/1)\n",W,y2);
if(fl){
p[++tt]=P;
p[++tt]={(frac){W,1},(frac){y2,1}};
p[++tt]={(frac){0,1},(frac){0,1}};
nx[2][0]=1,nx[3][0]=2,nx[3][1]=1,siz[3]=3;
hd[0]=3,st.insert(0);
p[++tt]={(frac){0,1},(frac){MX,1}};
p[++tt]={(frac){W,1},(frac){y2,1}};
p[++tt]=P;
nx[5][0]=4,nx[6][0]=5,nx[6][1]=4,siz[6]=3;
hd[y1]=6,st.insert(y1);
}
con;
}
int id=hd[*(--st.lower_bound(y1))],H=id;
int sum=siz[id]-1;
// int testid=id;
// for(int i=1;i<=siz[id];i++)printf("%d ",testid),testid=nx[testid][0];
// puts("");
for(int i=18;i>=0;i--){
if(sum<(1<<i))con;
int nwid=nx[id][i];
if(li.gty(p[nwid].x)==p[nwid].y){
id=nwid,sum-=1<<i;
break;
}
if(p[nwid].y<li.gty(p[nwid].x))id=nwid,sum-=1<<i;
}
if(li.gty(p[id].x)==p[id].y){//split
p[id].out();
if(fl){
siz[nx[id][0]]=sum,siz[H]-=sum;//
int num1=addfront(p[id],nx[id][0]);
int num2=addfront(P,num1);
st.insert(y1),hd[y1]=num2;
addback(H,P);
}
con;
}
//common
point p1=p[id],p2=p[nx[id][0]],np;
if(p2.y==(frac){1000001,1}||p1.y==(frac){0,1}||p1.x==p2.x)np={(frac){W,1},(frac){y2,1}};
// if(p1.x==p2.x)np={(frac){W,1},(frac){y2,1}};
else {
frac k1=(p1.y-p2.y)/(p1.x-p2.x);
line tmp={k1,p1.y-p1.x*k1};
np.x=gtx(li,tmp),np.y=li.gty(np.x);
}
np.out();
if(fl){
siz[nx[id][0]]=sum,siz[H]-=sum;//
int num1=addfront(np,nx[id][0]);
int num2=addfront(P,num1);
st.insert(y1),hd[y1]=num2;
addback(H,np);
addback(H,P);
}
}
re 0;
}
/*
4 5
1 4 1
4 1 1
3 2 1
2 5 1
10 10
4 6 1
5 8 1
2 7 1
9 2 1
1 1 1
3 10 1
10 3 1
8 4 1
7 5 1
6 9 1
*/
}signed main(){re FRTMLV::main();}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 10164kb
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: 570ms
memory: 10392kb
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: 520ms
memory: 12440kb
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: 709ms
memory: 49576kb
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: -100
Runtime Error
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/...