이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+15;
#define ll long long
ll tree[N*4];
void update_ind(int pos,int l,int r,int ind,ll upd){
if(l==r){
tree[pos] = upd;
return;
}
int mid = (l+r)/2;
if(ind<=mid){
update_ind(pos*2,l,mid,ind,upd);
}
else
update_ind(pos*2+1,mid+1,r,ind,upd);
tree[pos] = max(tree[pos*2],tree[pos*2+1]);
}
ll query(int pos,int l,int r,int ql,int qr){
if(qr<l || r<ql)return -3e18;
if(ql<=l && r<=qr){
return tree[pos];
}
int mid = (l+r)/2;
return max(query(pos*2,l,mid,ql,qr),query(pos*2+1,mid+1,r,ql,qr));
}
ll x[N],b[N];
int main(){
//freopen("input.txt","r",stdin);
ll k,m,d,a,n;
cin>>k>>m>>d>>a>>n;
for(int i=0;i<N*4;++i)tree[i] = -3e18;
map<int,int> Hash;
ll pos = (k/d);
ll value = -a*pos;
for(int i=1;i<=n;++i){
scanf("%lld%lld",&x[i],&b[i]);
Hash[x[i]%d];
}
x[n+1] = m;
int ind=0,id;
Hash[k%d];
Hash[m%d];
for(map<int,int>::iterator it= Hash.begin();it!= Hash.end();++it){
it->second = ind++;
}
update_ind(1,0,ind-1,Hash[k%d],-value);
ll q;
for(int i=1;i<=n+1;++i){
id = x[i]%d;
id = Hash[id];
pos = (x[i]/d);
value = -a*pos;
q = -3e18;
if(id>0){
q = query(1,0,ind-1,0,id-1)-a;
}
q= max(q,query(1,0,ind-1,id,ind-1)) ;
q += value + b[i];
update_ind(1,0,ind-1,id,q-value);
}
cout<<q<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
koala.cpp: In function 'int main()':
koala.cpp:54:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&x[i],&b[i]);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |