QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135558 | #6632. Minimize Median | Fran188 | WA | 315ms | 5508kb | C++14 | 2.8kb | 2023-08-05 18:01:46 | 2023-08-05 18:01:48 |
Judging History
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;
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;
vector<int>v, c(m+2), dp(m+2);
for(int i=0;i<n;i++)
{
int x;
cin >> x;
v.push_back(x);
}
for(int i=1;i<=m;i++)cin >> dp[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.end());
build(1, 1, m);
int help = INF;
for(int i=2;i<=m;i++)
{
int tmp = (m+1)/(i+1);
tmp++;
tmp = query(1, 1, m, tmp, m);
help = min(help , tmp + dp[i]);
}
//cout << help << " ";
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;
int tmp = (v[i]/(mid+1));
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5508kb
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: 315ms
memory: 5500kb
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 1 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 1 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 4108th numbers differ - expected: '1', found: '0'