QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202230#5123. StreetsA_zjzjWA 880ms5452kbC++142.7kb2023-10-05 20:57:142023-10-05 20:57:14

Judging History

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

  • [2023-10-05 20:57:14]
  • 评测
  • 测评结果:WA
  • 用时:880ms
  • 内存:5452kb
  • [2023-10-05 20:57:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
	cerr<<x<<' ',debug(y...);
}
const int N=5e3+10,M=1e5+10,K=1e2+10,INF=1e9;
int n,m,T,ta,tb,a[N],b[N],px[N],py[N],va[M],vb[M];
ll c[K],ans[K];
int cur[M],fa[M];
struct frac{
	int x,y;
	frac(int a=0,int b=1):x(a),y(b){}
};
bool operator < (const frac &a,const frac &b){
	return 1ll*a.y*b.x<1ll*a.x*b.y;
}
ll calc(frac a,frac b){
	return 1ll*a.x*b.y+1ll*a.y*b.x;
}
ll dot(frac a,frac b){
	return 1ll*a.x*b.x+1ll*a.y*b.y;
}
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
int vis[N];
void del(int x){
	fa[x]=find(x-1),vis[x]=1;
}
int main(){
	scanf("%d%d%d",&n,&m,&T);
	for(int i=1;i<=n;i++)scanf("%d",&px[i]);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=m;i++)scanf("%d",&py[i]);
	for(int i=1;i<=m;i++)scanf("%d",&b[i]);
	for(int i=1;i<=T;i++)scanf("%lld",&c[i]);
	ta=px[n]-px[1],tb=py[m]-py[1];
	fill(va+1,va+1+ta,INF),fill(vb+1,vb+1+tb,INF);
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++){
			va[px[i]-px[j]]=min(va[px[i]-px[j]],a[i]+a[j]);
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<i;j++){
			vb[py[i]-py[j]]=min(vb[py[i]-py[j]],b[i]+b[j]);
		}
	}
	// debug(ary(va,1,ta),ary(vb,1,tb));
	iota(cur,cur+1+ta,0);
	sort(cur+1,cur+1+ta,[&](int x,int y){
		return frac(x,va[x])<frac(y,va[y]);
	});
	using S=tuple<frac,int,int>;
	priority_queue<S,vector<S>,greater<S> >q;
	for(int i=1;i<=tb;i++)fa[i]=i;
	for(int i=1;i<=tb;i++){
		if(vb[i]==INF)del(i);
	}
	auto ins=[&](int x,int y){
		q.push({frac(y-x,vb[y]-vb[x]),x,y});
	};
	for(int i=1;i<=tb;i++){
		if(!vis[i]&&find(i-1))ins(find(i-1),i);
	}
	for(int x=1,i;i=cur[x],x<=ta;x++){
		frac now(i,va[i]);
		for(;!q.empty();){
			frac val;
			int x,y;
			tie(val,x,y)=q.top();
			if(vis[y]||find(y-1)!=x){
				q.pop();continue;
			}
			// debug(i,x,y);
			if(dot(val,now)>0)break;
			q.pop(),del(x);
			if(find(y-1))ins(find(y-1),y);
		}
		// debug(i,ary(vis,1,tb),q.size());
		for(int j=1;j<=T;j++){
			int l=0,r=tb+1,mid;
			for(;l+1<r;){
				mid=(l+r)>>1;
				int x=find(mid);
				if(!x||calc(now,frac(x,vb[x]))<=c[j])l=mid;
				else r=mid;
			}
			// debug(j,find(l));
			if(find(l))ans[j]=max(ans[j],1ll*i*find(l));
		}
	}
	for(int i=1;i<=T;i++)printf("%lld\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3760kb

input:

3 4 20
1 3 4
3 1 2
1 3 4 7
4 2 1 2
1
5
6
7
9
10
11
12
15
16
17
22
23
28
30
35
43
47
49
57

output:

0
0
1
1
1
2
2
3
3
4
4
6
6
9
9
12
12
12
18
18

result:

ok 20 numbers

Test #2:

score: -100
Wrong Answer
time: 880ms
memory: 5452kb

input:

4995 4998 100
4 7 20 34 44 100 102 130 175 198 205 250 257 259 267 278 300 324 337 346 353 364 403 427 439 440 451 523 532 534 555 599 634 639 756 802 805 825 855 859 890 905 912 915 953 989 1014 1031 1052 1059 1097 1124 1183 1216 1297 1308 1337 1342 1361 1392 1400 1421 1451 1471 1523 1537 1542 1619...

output:

9991201920
9548989760
489413595
8507756400
3595191600
9928119996
9498500968
8507756400
4715139000
2710336200
4180605000
1279964400
3317714400
6455592000
9549985110
8546075100
7491884400
5481504600
6624961200
2710336200
583354200
3859198200
9227036728
1397424600
3483994800
5843065800
1045044000
41378...

result:

wrong answer 2nd numbers differ - expected: '9941157660', found: '9548989760'