QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127310#6632. Minimize Medianwinoua#WA 302ms11768kbC++142.8kb2023-07-19 15:33:562023-07-19 15:33:57

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){
    int x = 0, f = 1; char ch;
    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);
    for(x = ch ^ 48 ; isdigit(ch = getchar()) ; x = (x << 3) + (x << 1) + (ch ^ 48));
    return x * f;
}
const int N = 1e6 + 9;
int n,m,k,a[N],b[N],c[N * 3],lz[N * 4],mx;
struct node{int l,r,w;} t[N * 4];
void build(int p,int l,int r){
	t[p].l=l,t[p].r=r;lz[p]=1e18;
	if(t[p].l==t[p].r){
		t[p].w=c[l];return;
	}
	int mid=(l+r)/2;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	t[p].w=min(t[p*2].w,t[p*2+1].w);
}
void spread(int p){
	if(lz[p]==1e18) return;
	t[p*2].w=min(t[p*2].w,lz[p]);
	t[p*2+1].w=min(t[p*2+1].w,lz[p]);
	lz[p*2]=min(lz[p*2],lz[p]);
	lz[p*2+1]=min(lz[p*2+1],lz[p]);
	lz[p]=1e18;
}
void change(int p,int l,int r,int k){
	if(l<=t[p].l&&t[p].r<=r){
		t[p].w=min(t[p].w,k);
		lz[p]=min(lz[p],k);
		return;
	}
	spread(p);
	int mid=(t[p].l+t[p].r)/2;
	if(l<=mid) change(2*p,l,r,k);
	if(r>mid) change(2*p+1,l,r,k);
	t[p].w=min(t[p*2].w,t[p*2+1].w);
}
int ask(int p,int l,int r){
	if(t[p].l>=l&&t[p].r<=r){
		return t[p].w;
	}
	spread(p);
	int mid=(t[p].l+t[p].r)/2,res=1e18;
	if(l<=mid) res=min(res,ask(p*2,l,r));
	if(r>mid) res=min(res,ask(p*2+1,l,r));
	return res;
}
void solve(){
	for(int i=m+1;i<=mx;i++) c[i]=1e18;
	build(1,1,mx);
	for(int i=2;i<=m;i++){
		int w=0;
		for(int j=i;;j*=i){
			w+=c[i];
			if(j/i+1>mx) break;
			int r=min(mx,j);
			change(1,j/i+1,r,w);
		}
	}
	for(int i=2;i<=mx;i++) c[i]=ask(1,i,i);
}                           
bool judge(int mid){
	int num = 0, ans = 0;
	//cout<<mid<<" -- > "<<"\n"; 
	for(int i = 1 ; i <= n ; i ++){
		if(a[i] >= mid) {
			int kk;
			if(mid != 0) kk = a[i] / mid + 2;
			else kk = a[i] + 1;
			//cout<<kk<<"\n";
			while(kk > 1 && floor(a[i] / (kk - 1)) < mid) {
				kk --;
				//cout<<kk - 1<<" "<<floor(a[i] / (kk - 1))<<"\n";
			}
			b[++num] = c[kk];
			//cout<<a[i]<<" "<<kk<<" "<<c[kk]<<"\n";
		}
	}
	sort(b + 1,b + num + 1);
	for(int i = 1 ; i <= num - (n / 2) ; i ++) ans += b[i];
	//cout<<" -- > "<<ans<<"\n";
	if(ans <= k) return true;
	return false;
}
signed main(){
	int T = read();
	while(T --){
		n = read(), m = read(), k = read(), mx = m;
		for(int i = 1 ; i <= n ; i ++) a[i] = read(), mx = max(mx,a[i]);
		for(int i = 1 ; i <= m ; i ++) c[i] = read(), mx = max(mx,c[i]);
		solve(); c[1] = 0;
		for(int i = mx - 1 ; i >= 1 ; i --) c[i] = min(c[i],c[i + 1]);
		//for(int i = 1 ; i <= mx ; i ++) cout<<c[i]<<" "; cout<<"\n";
		sort(a + 1,a + n + 1);
		int l = 0, r = a[(n / 2) + 1] + 1, ans = r;
		while(l <= r){
			int mid = (l + r) >> 1;
			if(judge(mid)) ans = mid, r = mid - 1;
			else l = mid + 1;
		}
		cout<<ans - 1<<"\n";
	}
	return 0;
}
/*
3
3 5 0
2 5 2
3 2 4 6 13
3 5 3
2 5 3
3 2 4 6 13
3 5 6
2 5 2
3 2 4 6 13

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 5 0
2 5 2
3 2 4 6 13
3 5 3
2 5 3
3 2 4 6 13
3 5 6
2 5 2
3 2 4 6 13

output:

2
2
1

result:

ok 3 number(s): "2 2 1"

Test #2:

score: -100
Wrong Answer
time: 302ms
memory: 11768kb

input:

100000
5 10 5
3 7 1 10 10
11 6 11 6 1 8 9 1 3 1
5 6 51
2 2 2 5 1
42 61 26 59 100 54
5 10 76
7 5 8 4 7
97 4 44 83 61 45 24 88 44 44
5 8 90
1 1 5 1 3
35 15 53 97 71 83 26 7
5 3 52
1 1 3 1 1
22 6 93
5 6 28
6 6 1 3 1
9 31 2 19 10 27
5 8 31
3 6 2 1 2
32 29 13 7 57 34 9 5
5 6 75
3 3 4 5 4
40 56 38 60 17 3...

output:

-1
2
-1
-1
-1
-1
-1
-1
3
4
-1
-1
-1
-1
1
1
-1
-1
-1
-1
1
1
-1
2
2
-1
-1
-1
-1
-1
2
-1
-1
-1
2
2
-1
1
-1
-1
-1
-1
1
-1
2
4
1
1
-1
-1
2
-1
-1
7
-1
1
-1
-1
-1
1
1
-1
1
-1
1
-1
-1
2
1
-1
6
3
-1
-1
1
-1
2
-1
-1
3
-1
1
-1
1
-1
2
-1
-1
-1
-1
1
2
1
4
-1
-1
-1
-1
-1
-1
1
2
2
1
2
2
-1
1
1
-1
-1
-1
-1
-1
1
2
1...

result:

wrong answer 1st numbers differ - expected: '0', found: '-1'