QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#603118 | #8524. Weather Forecast | WilliamHu | WA | 2ms | 14104kb | C++20 | 2.2kb | 2024-10-01 14:48:24 | 2024-10-01 14:48:25 |
Judging History
answer
#include<bits/stdc++.h>
//#define int long long
using namespace std;
int ans[1000010], a[1000010];
int read()
{
int x = 0,f = 1;
char c = getchar();
while (c != EOF && !isdigit(c)) {if (c == '-') f = -1;c = getchar();}
while (isdigit(c)) {x = x * 10 + c - '0';c = getchar();}
return x * f;
}
int n, m;
int ls(int p){return p << 1;}
int rs(int p){return p << 1 | 1;}
void pushup(int p){ans[p] = max(ans[ls(p)],ans[rs(p)]);}
void update(int dx, int dy, int l, int r, int p, int k)
{
if(dx <= l and r <= dy)
{
ans[p] = max(ans[p], k);
return ;
}
int mid = l + r >> 1;
if(dx <= mid)update(dx, dy, l, mid, ls(p), k);
if(mid < dy)update(dx, dy, mid + 1, r, rs(p), k);
pushup(p);
}
int query(int dx, int dy, int l, int r, int p)
{
if(dx <= l and r <= dy)return ans[p];
int mid = l + r >> 1, res = -0x3f3f3f3f;
if(dx <= mid)res = max(res, query(dx, dy, l, mid, ls(p)));
if(mid < dy)res = max(res, query(dx, dy, mid + 1, r, rs(p)));
return res;
}
int dp[1000010], b[1000010];
int sum[1000010];
pair<int, int>tmp[1000010];
bool check(int x)
{
//cout<<x<<endl;
sum[0] = 0;
b[0] = 0;
for(int i=1;i<=2*n;i++)ans[i] = -1;
for(int i = 1;i <= n;i ++)
{
dp[i] = -1;
tmp[i] = make_pair(tmp[i-1].first+(a[i]-x), i);
b[i] = b[i-1]+(a[i]-x);
//cout<<b[i]<<' ';
}
//cout<<endl;
sort(tmp+1, tmp+n+1);
int cnt = 0, tot = -11451419;
for(int i=1;i<=n;i++)
{
if(tot == tmp[i].first)sum[tmp[i].second] = cnt;
else{
tot = tmp[i].first;
sum[tmp[i].second] = ++cnt;
}
}
// for(int i = 1;i <= n;i ++)cout<<sum[i]<<" ";
// cout<<endl;
dp[0] = 0;
for(int i = 1;i <= n;i ++)
{
dp[i] = query(1, sum[i], 1, n, 1);
if(dp[i] == -1 and b[i] < 0)continue;
if(dp[i] == -1)dp[i] = 1;
else dp[i] += 1;
//cout<<sum[i]<<" "<<dp[i]<<endl;
update(sum[i], sum[i], 1, n, 1, dp[i]);
}
// for(int i = 1;i <= n;i ++)cout<<dp[i]<<" ";
// cout<<endl;
return dp[n] >= m;
}
signed main()
{
n = read();
m = read();
for(int i=1;i<=n;i++)a[i]=read()*10000;
int l = 1, r = 1e7, ans = 0;
while(l<=r)
{
int mid = l+r>>1;
if(check(mid))
{
ans = mid;
l = mid+1;
}
else r = mid-1;
}
printf("%.4f", double(ans)/10000.0);
return 0;
}
//7 3
//1 3 1 2 2 2 1
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 14036kb
input:
7 3 1 3 1 2 2 2 1
output:
1.6666
result:
ok found '1.66660', expected '1.66667', error '0.00007'
Test #2:
score: 0
Accepted
time: 0ms
memory: 14056kb
input:
1 1 1
output:
1.0000
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 14096kb
input:
2 1 2 1
output:
1.5000
result:
ok found '1.50000', expected '1.50000', error '0.00000'
Test #4:
score: 0
Accepted
time: 2ms
memory: 14060kb
input:
3 2 2 4 4
output:
3.0000
result:
ok found '3.00000', expected '3.00000', error '0.00000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 14052kb
input:
4 2 6 7 3 12
output:
6.5000
result:
ok found '6.50000', expected '6.50000', error '0.00000'
Test #6:
score: 0
Accepted
time: 2ms
memory: 14044kb
input:
5 3 17 23 13 12 21
output:
16.5000
result:
ok found '16.50000', expected '16.50000', error '0.00000'
Test #7:
score: 0
Accepted
time: 2ms
memory: 14104kb
input:
7 4 3 37 46 23 46 6 31
output:
23.0000
result:
ok found '23.00000', expected '23.00000', error '0.00000'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 14048kb
input:
10 5 30 91 36 53 74 91 37 1 76 3
output:
41.5999
result:
wrong answer 1st numbers differ - expected: '39.50000', found: '41.59990', error = '2.09990'