QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135542#6632. Minimize MedianFran188WA 290ms28396kbC++142.9kb2023-08-05 17:41:262023-08-05 17:41:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 17:41:29]
  • 评测
  • 测评结果:WA
  • 用时:290ms
  • 内存:28396kb
  • [2023-08-05 17:41:26]
  • 提交

answer

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long

const int INF=1e9+7;
const int N=1e6+10;
const int M=1e8+7;
const int M2=1e9+13;
const double pi=3.1415926535897932384626433832795028841971; 

vector<int>v(N), c(N), dp(N);

int arr[N], trees[4*N];

void build(int node, int start, int end)
{
    if(start == end)
    {
        // Leaf node will have a single element
        trees[node] = arr[start];
    }
    else
    {
        int mid = (start + end) / 2;
        // Recurse on the left child
        build(2*node, start, mid);
        // Recurse on the right child
        build(2*node+1, mid+1, end);
        // Internal node will have the sum of both of its children
        trees[node] = min(trees[2*node] , trees[2*node+1]);
    }
}

int query(int node, int start, int end, int l, int r)
{
    if(r < start or end < l)
    {
        // range represented by a node is completely outside the given range
        return INF;
    }
    if(l <= start and end <= r)
    {
        // range represented by a node is completely inside the given range
        return trees[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2*node, start, mid, l, r);
    int p2 = query(2*node+1, mid+1, end, l, r);
    return min(p1 , p2);
}

void solve()
{
	int n, m, k;
	cin >> n >> m >> k;
	for(int i=1;i<=m;i++)dp[i] = INF;
	for(int i=0;i<n;i++)cin >> v[i];
	for(int i=0;i<m;i++)cin >> c[i], dp[i+1] = c[i];
	for(int i=1;i<=m;i++)
	{
		for(int j=1;i*j<=m;j++)dp[i*j] = min(dp[i*j], dp[i]+dp[j]);
	}
	for(int i=1;i<=m;i++)arr[i] = dp[i];
	sort(v.begin(), v.begin()+n);
	build(1, 1, m);
	int help = INF;
	for(int i=2;i<=m;i++)
	{
		int tmp = (m+1)/i;
		if((m+1)%i)tmp++;
		tmp = query(1, 1, m, tmp, m);
		help = min(help , tmp + dp[i]);	
	}
	dp[m+1] = arr[m+1] = help; 
	build(1, 1, m+1);
	int lo = 0, hi = m, ans = -1;
	//cout << query(1, 1, m+1, m+1, m+1) << "\n"; 
	while(lo<=hi)
	{
		int mid = (lo+hi)/2;
		int c = 0;
		for(int i=0;i<=(n/2);i++)
		{
			if(v[i] <= mid)continue;
			if(mid==0)
			{
				int tmp = query(1, 1, m+1, v[i]+1, m+1);
				//cout << tmp << "\n";
				c+=tmp;
			}
			else{
				int tmp = (v[i]/mid);
				if(v[i]%mid) tmp++;
				tmp = query(1, 1, m+1, tmp, m+1);
				c += tmp;
			}
		}
		//cout << mid << " " << c << "\n"; 
		if(c > k) lo = mid+1;
		else
		{
			ans = mid;
			hi = mid-1;
		}
	}
	cout << ans << "\n";
}	

signed main()
{
	int t = 1;
	cin >> t;
	for(int i=1;i<=t;i++)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 28336kb

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: 290ms
memory: 28396kb

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:

0
2
0
0
0
0
0
0
3
4
0
0
0
0
1
1
0
0
0
0
1
1
0
2
2
0
0
0
0
0
2
0
0
0
2
2
0
1
0
0
0
0
1
0
2
4
1
1
0
0
2
0
0
7
0
2
0
0
0
1
1
0
1
0
1
0
0
2
1
0
6
3
0
0
1
0
2
0
0
3
0
1
0
1
0
2
0
0
0
0
1
2
2
4
0
0
0
0
0
0
1
2
2
1
2
2
0
1
1
0
0
0
0
0
1
2
1
4
1
0
4
1
2
1
0
0
0
0
1
2
1
0
0
2
3
1
0
1
1
1
0
1
5
0
1
2
0
2
0
0
...

result:

wrong answer 56th numbers differ - expected: '1', found: '2'