QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#40767#3998. The ProfiteerBuildNoMoreWA 3ms7868kbC++141.9kb2022-07-26 15:45:542022-07-26 15:45:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-26 15:45:57]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7868kb
  • [2022-07-26 15:45:54]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define per(i,x,y) for(int i=x;i>=y;--i)
#define lon long long
#define vi vector <lon>
using namespace std;
mt19937 rng( time(0) );
const int n7=201234;
int n;lon K,hug,val[n7],wa[n7],wb[n7],ans[n7],anss;

int rd(){
	int shu=0;bool fu=0;char ch=getchar();
	while( !isdigit(ch) ){if(ch=='-')fu=1;ch=getchar();}
	while( isdigit(ch) )shu=(shu<<1)+(shu<<3)+ch-'0',ch=getchar();
	return fu?-shu:shu;
}

void bug(vi f){
	return;
	puts("!");
	for(auto i:f)printf("%lld ",i);
	putchar('\n');
}

void add(vi &f,int Val,int Wgt){
	per(i,K,Wgt)f[i]=max(f[i],f[i-Wgt]+Val);
}

bool check(vi f,int l,int r,int L,int R){
	rep(i,l,r){
		if(L<=i&&i<=R)add(f,val[i],wb[i]);
		else add(f,val[i],wa[i]);
	}
	bug(f);
	lon s=0;
	for(auto i:f)s+=i;
	return s<=K*hug;
}

void dopart(int l,int r,int L,int R,vi f){//l,r下标,L,R值 
	if(l>r)return;
	if(L==R){
		rep(i,l,r)ans[i]=L;return;
	}
	int mid=(l+r)>>1;vi g1=f,g2=f;
	rep(i,l,mid-1)add(f,val[i],wa[i]);
	bug(f);
	rep(i,mid, min(L-1,r) )add(f,val[i],wb[i]);
	int ll=max(L,mid),rr=min(R,n);
	bug(f);
	ans[mid]=n+1;
	while(ll<=rr){
		int midd=(ll+rr)>>1;
		if( check(f,ll,rr,mid,midd) ){
			rep(i,midd,rr)add(f,val[i],wa[i]);
			ans[mid]=midd,rr=midd-1;
		}
		else{
			bug(f);
			rep(i,ll,midd)add(f,val[i],wb[i]);
			ll=midd+1;
			bug(f);
		}
	}
	rep(i,ans[mid]+1, min(R,n) )add(g1,val[i],wa[i]);
	rep(i,max(L,r+1),ans[mid]-1)add(g2,val[i],wb[i]);
	rep(i,mid, min(r,L-1) )add(g1,val[i],wb[i]);
	rep(i,l,mid)add(g2,val[i],wa[i]);
	dopart(l,mid-1,L,ans[mid],g1);
	dopart(mid+1,r,ans[mid],R,g2);
}

int main(){
	n=rd(),K=rd(),hug=rd();
	rep(i,1,n)val[i]=rd(),wa[i]=rd(),wb[i]=rd();
	vi vec0;rep(i,0,K)vec0.emplace_back(0);
	dopart(1,n,1,n+1,vec0);
	rep(i,1,n)printf("%lld ",ans[i]);putchar('\n');
	rep(i,1,n)anss+=n-ans[i]+1;
	printf("%lld",anss);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 7868kb

input:

4 5 3
3 2 4
1 2 3
2 1 2
3 1 3

output:

4 5 5 5 
1

result:

wrong answer 1st lines differ - expected: '1', found: '4 5 5 5 '