QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#75760#5310. PaintingA_zjzjWA 896ms38116kbC++142.3kb2023-02-06 10:01:392023-02-06 10:01:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-06 10:01:41]
  • 评测
  • 测评结果:WA
  • 用时:896ms
  • 内存:38116kb
  • [2023-02-06 10:01:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3e5+10,K=__lg(N)+2;
int n,W,a[N],b[N],fa[K][N],dep[N];
struct cmp{
	bool operator () (const int &x,const int &y)const{
		return a[x]<a[y];
	}
};
set<int,cmp>s;
struct frac{
	ll x,y;
	frac trs()const{
		ll g=__gcd(abs(x),abs(y));
		return {x/g,y/g};
	}
	bool operator < (const frac &a)const{
		return x*a.y<y*a.x;
	}
	bool operator <= (const frac &a)const{
		return x*a.y<=y*a.x;
	}
	frac operator * (const int &a)const{
		return {x*a,y};
	}
	frac operator + (const frac &a)const{
		return {x*a.y+a.x*y,y*a.y};
	}
}r[N];
void write(frac x){
	x=x.trs(),printf("%lld/%lld",x.x,x.y);
}
frac calc(int i,int j){
	ll x=a[i]-a[j],y=b[j]-a[j]-b[i]+a[i];
	if(y<0)x=-x,y=-y;
	return {x,y};
}
int LCA(int u,int v){
	if(dep[u]<dep[v])swap(u,v);
	for(int i=K-1;~i;i--)if(dep[fa[i][u]]>=dep[v])u=fa[i][u];
	if(u==v)return u;
	for(int i=K-1;~i;i--)if(fa[i][u]^fa[i][v])u=fa[i][u],v=fa[i][v];
	return fa[0][u];
}
bool find(int p,int u,int t){
	for(int i=K-1;~i;i--){
		int v=fa[i][u];
		if(v==t)continue;
		frac tmp=calc(v,p);
		if(tmp.x<0||!tmp.y||r[v]<tmp)
			u=v;
	}
	frac tmp=calc(u,p);
	if(r[u]<tmp||!tmp.y||tmp.x<0)u=fa[0][u];
	tmp=calc(u,p);
	if(r[u]<tmp||!tmp.y||tmp.x<0||u==t)return 0;
	if(tmp.x>tmp.y)return 0;
	fa[0][p]=u;
	dep[p]=dep[u]+1;
	r[p]=tmp;
	for(int i=1;i<K;i++)fa[i][p]=fa[i-1][fa[i-1][p]];
	return 1;
}
int main(){
	scanf("%d%d",&n,&W);
	a[0]=b[0]=0,s.insert(0);
	a[n+1]=b[n+1]=1e6+1,s.insert(n+1);
	r[0]=r[n+1]={1,1};
	dep[0]=dep[n+1]=1;
	for(int i=0;i<K;i++)fa[i][0]=0,fa[i][n+1]=n+1;
	for(int i=1,op;i<=n;i++){
		scanf("%d%d%d",&a[i],&b[i],&op);
		auto it=s.lower_bound(i);
		int v=*it,u=*prev(it);
		if(fa[K-1][u]!=fa[K-1][v]){
			bool x=find(i,u,-1),y=find(i,v,-1);
			if(!x&&!y){
				dep[i]=1;
				for(int j=0;j<K;j++)fa[j][i]=i;
				r[i]=(frac){1,1};
			}
		}
		else{
			int t=LCA(u,v);
			bool x=find(i,u,t),y=find(i,v,t);
			if(!x&&!y){
				dep[i]=dep[t]+1;
				fa[0][i]=t;
				for(int j=1;j<K;j++)fa[j][i]=fa[j-1][fa[j-1][i]];
				r[i]=calc(i,t);
			}
		}
		if(op)s.insert(i);
		putchar('(');
		write(r[i]*W);
		putchar(',');
		write(r[i]*b[i]+(frac){r[i].y-r[i].x,r[i].y}*a[i]);
		puts(")");
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 14108kb

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: 364ms
memory: 35504kb

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: 318ms
memory: 35252kb

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
Wrong Answer
time: 896ms
memory: 38116kb

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:

wrong answer 31st lines differ - expected: '(25808834319/122168,36177202171/61084)', found: '(90787499142/370985,40309901002/74197)'