QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#75902#5310. PaintingA_zjzjWA 221ms35192kbC++142.3kb2023-02-06 16:27:082023-02-06 16:27:21

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 16:27:21]
  • 评测
  • 测评结果:WA
  • 用时:221ms
  • 内存:35192kb
  • [2023-02-06 16:27:08]
  • 提交

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 x=dep[u]-dep[v];x;x^=x&-x)u=fa[__builtin_ctz(x)][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){
	if(dep[u]>t)for(int x=dep[u]-t-1;x;x^=x&-x){
		int i=__builtin_ctz(x),v=fa[i][u];
		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||dep[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,0),y=find(i,v,0);
			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,dep[t]),y=find(i,v,dep[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: 0ms
memory: 30280kb

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: -100
Wrong Answer
time: 221ms
memory: 35192kb

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:

wrong answer 1401st lines differ - expected: '(147564792569/342960,824693955521/1714800)', found: '(894665/1,109892/1)'