QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#603160#8524. Weather ForecastWilliamHuWA 4ms14180kbC++202.2kb2024-10-01 15:00:522024-10-01 15:00:52

Judging History

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

  • [2024-10-01 15:00:52]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:14180kb
  • [2024-10-01 15:00:52]
  • 提交

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<=4*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: 13980kb

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: 14104kb

input:

1 1
1

output:

1.0000

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

score: 0
Accepted
time: 2ms
memory: 13964kb

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: 0ms
memory: 14000kb

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: 2ms
memory: 14092kb

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: 0ms
memory: 14048kb

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: 0ms
memory: 14120kb

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: 0
Accepted
time: 2ms
memory: 14180kb

input:

10 5
30 91 36 53 74 91 37 1 76 3

output:

39.5000

result:

ok found '39.50000', expected '39.50000', error '0.00000'

Test #9:

score: 0
Accepted
time: 0ms
memory: 14100kb

input:

100 50
593 336 577 842 505 78 665 825 990 895 952 782 721 242 421 951 786 994 238 154 356 483 686 143 220 473 920 353 738 690 96 915 913 157 412 882 465 585 963 635 68 72 901 143 50 558 310 504 987 97 588 987 841 829 780 497 758 909 503 585 91 657 912 870 663 606 748 492 175 92 375 768 773 206 676 8...

output:

483.0000

result:

ok found '483.00000', expected '483.00000', error '0.00000'

Test #10:

score: -100
Wrong Answer
time: 4ms
memory: 14160kb

input:

1000 500
74 796 330 98 801 45 160 90 432 788 873 109 714 307 407 94 360 136 198 912 744 902 549 398 478 590 663 983 956 267 201 332 610 249 698 268 700 755 902 485 327 539 203 397 721 971 951 378 674 159 269 182 473 993 84 832 808 908 73 608 842 411 465 886 348 153 924 871 729 1 279 949 475 71 982 3...

output:

0.0000

result:

wrong answer 1st numbers differ - expected: '395.00000', found: '0.00000', error = '395.00000'