QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687522#5310. PaintingFreeTimeLoveAC ✓980ms191948kbC++143.6kb2024-10-29 19:29:222024-10-29 19:29:22

Judging History

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

  • [2024-10-29 19:29:22]
  • 评测
  • 测评结果:AC
  • 用时:980ms
  • 内存:191948kb
  • [2024-10-29 19:29:22]
  • 提交

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=1.2e6+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{
	i7 x,y;
	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;
	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();
	
	p[++tt]={(frac){0,1},(frac){MX,1}};
	p[++tt]={(frac){0,1},(frac){0,1}};
	hd[0]=2,st.insert(0),siz[2]=2,nx[2][0]=1;
	
	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;
		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}};
		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;
}
/*
*/
}signed main(){re FRTMLV::main();}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 12348kb

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: 523ms
memory: 10364kb

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: 751ms
memory: 51796kb

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: 859ms
memory: 107860kb

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: 935ms
memory: 163208kb

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: 941ms
memory: 178348kb

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: 980ms
memory: 191948kb

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: 528ms
memory: 35760kb

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: 585ms
memory: 51320kb

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: 666ms
memory: 89208kb

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: 830ms
memory: 162336kb

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