QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#686904#5417. Chat Programwangxiaorui#WA 1482ms33168kbC++141.5kb2024-10-29 16:19:062024-10-29 16:19:18

Judging History

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

  • [2024-10-29 16:19:18]
  • 评测
  • 测评结果:WA
  • 用时:1482ms
  • 内存:33168kb
  • [2024-10-29 16:19:06]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200010; 
int n,a[N],m,k,c,d;
ll p[N],sum[N];
ll b[N*3],idx;
ll tr[N*3];
unordered_map <ll,int> mp;
int lowbit(int x){
	return x&(-x);
}
void add(int x,int v){
	for(;x<=idx;x+=lowbit(x)) tr[x]+=v;
}
int query(int x){
	int res=0;
	for(;x;x-=lowbit(x)) res+=tr[x];
	return res;
}
bool check(ll mid){
//	cout<<mid<<endl;
	for(int i=1;i<=idx;i++) tr[i]=0;
	mp.clear();idx=0;
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1];
		if(mid<=a[i]){
			sum[i]=sum[i-1]+1;
			p[i]=0;
		}
		else{
			p[i]=mid-a[i];
			if(p[i]<=c) p[i]=1;
			else{
				if(!d){
					p[i]=1e16;
				}
				else{
					if((p[i]-c)%d==0) p[i]=1+(p[i]-c)/d;
					else p[i]=1+(p[i]-c)/d+1;
				}
			}
		}
		b[++idx]=p[i]-i;b[++idx]=m-i; 
	}
	
	sort(b+1,b+1+idx);
	idx=unique(b+1,b+1+idx)-b-1;
	int t;
	for(int i=1;i<=idx;i++) mp[b[i]]=i;
	for(int i=1;i<=n;i++){
		add(mp[p[i]-i],1);
		if(i>=m){
			t=query(mp[m-i])-(sum[i]-sum[i-m]);
			if(t+sum[n]>=k) return 1;
			add(mp[i-m+1-(i-m+1)],-1);
		}
	}
	return 0;
}
void solve(){
	cin>>n>>k>>m>>c>>d;
	for(int i=1;i<=n;i++) cin>>a[i];
	ll l=0,r=1e15,mid,res=-1;
	while(l<=r){
		mid=(l+r)>>1;
		if(n>=200010) cout<<l<<' '<<r<<' '<<mid<<endl;
		if(!check(mid)) r=mid-1;
		else l=mid+1,res=mid;
	}
	cout<<res<<endl;
}
int main()
{	
	//freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5908kb

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

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

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: 1482ms
memory: 31512kb

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: 750ms
memory: 32656kb

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: 707ms
memory: 33168kb

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: -100
Wrong Answer
time: 1304ms
memory: 30692kb

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:

964475746

result:

wrong answer 1st numbers differ - expected: '964474978', found: '964475746'