QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686849 | #5417. Chat Program | wangxiaorui# | TL | 1ms | 5716kb | C++14 | 1.4kb | 2024-10-29 16:01:22 | 2024-10-29 16:01:25 |
Judging History
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];
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=1e16,mid,res=-1;
while(l<=r){
mid=(l+r)>>1;
// cout<<l<<' '<<r<<' '<<mid<<endl;
if(!check(mid)) r=mid-1;
else l=mid+1,res=mid;
}
cout<<res<<endl;
}
int main()
{
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: 5640kb
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: 0ms
memory: 5640kb
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: 5716kb
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: -100
Time Limit Exceeded
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 ...