QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791408#5417. Chat ProgramkircoWA 63ms6832kbC++231.8kb2024-11-28 18:28:352024-11-28 18:28:35

Judging History

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

  • [2024-11-28 18:28:35]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:6832kb
  • [2024-11-28 18:28:35]
  • 提交

answer

#include<bits/stdc++.h>
#define iosy ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
using namespace std;
const int N = 2e5+10;
// 有这样一个trick:区间长度固定为m,那么就将整个区间看作一个整体,用左端点来代表整个区间
// https://blog.csdn.net/m0_74087709/article/details/143310592?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522a286dd218f60e2a822a4a1eab3a4ba53%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=a286dd218f60e2a822a4a1eab3a4ba53&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-5-143310592-null-null.142^v100^pc_search_result_base4&utm_term=chat%20program%E5%8D%97%E4%BA%AC%E7%AB%99&spm=1018.2226.3001.4187
int n,k,m,c,d,a[N],pre[N];
int check(int mid){//第K大的数>=mid 等效于 有超过k个>=mid的数
	for(int i=0;i<=n+1;i++)pre[i]=0;
	int cnt=0;
	for(int i=1;i<=n;i++)if(a[i]>=mid)cnt++;
	if(cnt>=k)return 1;
	for(int i=1;i<=n;i++){
		if(a[i]>=mid)continue;//只要<mid的a[i];
		int l=max(1ll,i-m+1);
		int mx=a[i]+c+(i-l)*d;//a[i]能被加到的最大值
		if(mx<mid)continue;//最大值<mid则跳过
		
		int tot,mi=a[i]+c;//先把a[i]+c
		if(d==0)tot=0;
		else{
			tot=((mid-mi)+d-1)/d;//至少需要加多少次d才能>=mid
		}
		int r=i-tot;//r之后的点无法通过加上d使得a[i]>=mid
		pre[l]++;
		pre[r+1]--;//差分
	}
	for(int i=1;i<=n;i++){
		pre[i]+=pre[i-1];
	}
	int ans=0;
	for(int i=1;i<=n-m+1;i++){//遍历区间
		ans=max(ans,pre[i]);
	}
	return cnt+ans>=k;
}

void solve(){
	cin>>n>>k>>m>>c>>d;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int l=0,r=1e18;
	while(l<r){
		int mid=l+r+1>>1;
		if(check(mid))l=mid;
		else r=mid-1;
	}
	cout<<l<<"\n";
}

signed main(){ 
	iosy;int _=1;
	// cin>>_;
	while(_--){solve();}
	return 0;
}

詳細信息

Test #1:

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

input:

6 4 3 1 2
1 1 4 5 1 4

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

7 3 2 4 0
1 9 1 9 8 1 0

output:

9

result:

ok 1 number(s): "9"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5636kb

input:

8 3 5 0 0
2 0 2 2 1 2 1 8

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 53ms
memory: 6788kb

input:

200000 200000 100000 0 1000000000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 48ms
memory: 6712kb

input:

200000 1 100000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

100001000000000

result:

ok 1 number(s): "100001000000000"

Test #6:

score: 0
Accepted
time: 37ms
memory: 6768kb

input:

200000 1 200000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

200001000000000

result:

ok 1 number(s): "200001000000000"

Test #7:

score: 0
Accepted
time: 63ms
memory: 6792kb

input:

200000 24420 17993 881138881 700368758
231187558 519018952 260661004 740633836 931672020 155904999 647179942 13217847 779799803 382810661 242588977 708308843 309853544 225488875 389115097 588643904 644409212 704920939 231829287 39891424 881158891 341251089 486868469 808002305 629160633 317239613 771...

output:

964474978

result:

ok 1 number(s): "964474978"

Test #8:

score: 0
Accepted
time: 61ms
memory: 6704kb

input:

200000 31878 34175 753689504 94554240
764252685 385025201 185233994 886343186 532991571 477855721 681289648 908112797 112162074 199451201 408329780 674092805 896613552 521026518 597166827 166901445 503106595 958954753 464273450 431481790 32269637 998211679 557906218 821269178 46577165 394469258 5350...

output:

218913332405

result:

ok 1 number(s): "218913332405"

Test #9:

score: 0
Accepted
time: 61ms
memory: 6752kb

input:

200000 66779 68097 331272836 488739723
665914031 251031451 773370496 810714172 839343832 504839150 83995574 139444234 739491638 942462815 647699510 49942183 188406268 595225798 436622337 155224403 656771269 212988566 991684904 118039448 141911186 286576049 628943968 834536050 463993698 103102683 298...

output:

645490226257

result:

ok 1 number(s): "645490226257"

Test #10:

score: 0
Accepted
time: 62ms
memory: 6832kb

input:

200000 81680 76838 613888876 587957914
198979157 822070409 771572414 956423522 735630675 195386090 413072573 370775671 366821201 759103355 887069240 425791562 480198984 964392370 571045139 69918434 105403235 130585891 929161775 173193325 587989225 533471222 699981718 847802923 586442939 180332329 61...

output:

960936852

result:

ok 1 number(s): "960936852"

Test #11:

score: 0
Accepted
time: 59ms
memory: 6756kb

input:

200000 91220 105205 669606004 726732973
405615679 508461591 318840594 861409998 284631403 936958719 947250328 347040871 121416461 99394333 909156607 370576415 378572464 877013117 152690261 992392798 908066995 281718650 822652735 474896480 407144540 554646021 805052591 301197617 583099837 1953227 277...

output:

10165030223607

result:

ok 1 number(s): "10165030223607"

Test #12:

score: 0
Accepted
time: 63ms
memory: 6772kb

input:

200000 127232 120467 895980455 492723394
67974256 451968973 76401255 93977911 241791237 47804708 449338922 918134740 663986817 479932840 38924404 319676905 350139438 427462753 171072159 971709621 283613979 507344968 142793571 933555229 899830335 24231006 846677144 441919608 211146097 783125953 34819...

output:

915538143

result:

ok 1 number(s): "915538143"

Test #13:

score: -100
Wrong Answer
time: 60ms
memory: 6712kb

input:

200000 143295 141614 955791474 268985895
276555321 556167768 537607093 476166006 132948564 971746533 785402476 871110069 838805339 820188359 777901312 795957142 37915179 710693261 353090372 95835377 270446384 383039611 224736705 6220228 322677117 670856025 250928705 582340637 484301279 806539754 243...

output:

972294904

result:

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