이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e5 + 9;
const ll inf = 1e16 + 7;
struct place{
ll T,B,rm;
};
place a[N];
ll K,M,D,A,n,dp[N];
vector<ll> v;
void compress(){
sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
for (ll i = 1;i <= n;i++){
ll p = a[i].T % D;
a[i].rm = lower_bound(v.begin(),v.end(),p) - v.begin() + 1;
}
}
ll st[2][4*N];
void upd(ll cond,ll id,ll l,ll r,ll u,ll val){
if (u < l||r < u) return;
if (l == r){
st[cond][id] = max(st[cond][id],val); return;
}
ll mid = (l + r)/2;
upd(cond,id*2,l,mid,u,val); upd(cond,id*2 + 1,mid + 1,r,u,val);
st[cond][id] = max(st[cond][id*2],st[cond][id*2 + 1]);
}
ll Get(ll cond,ll id,ll l,ll r,ll u,ll v){
if (v < l||r < u) return -inf;
if (u <= l&&r <= v) return st[cond][id];
ll mid = (l + r)/2;
return max(Get(cond,id*2,l,mid,u,v),Get(cond,id*2 + 1,mid + 1,r,u,v));
}
/// 1 if Ti >= Tj 0 if Ti < Tj
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>K>>M>>D>>A>>n; a[1].T = K; a[n + 2].T = M; n += 2;
for (ll i = 2;i < n;i++) cin>>a[i].T>>a[i].B;
for (ll i = 1;i < 4*N;i++) st[0][i] = st[1][i] = -inf;
for (ll i = 1;i <= n;i++) v.push_back(a[i].T % D);
compress();
for (ll i = 1;i <= n;i++){
ll now = a[i].rm;
ll kq = max(Get(1,1,1,n,1,now - 1),Get(0,1,1,n,now,n));
dp[i] = kq - (a[i].T/D) * A; if (i == 1) dp[i] = 0;
ll val = dp[i] + a[i].B + (a[i].T/D)*A; //cout<<val; return 0;
upd(1,1,1,n,now,val - A); upd(0,1,1,n,now,val);
}
//for (ll i = 1;i <= n;i++) cout<<dp[i]<<" "; exit(0);
cout<<dp[n];
}
컴파일 시 표준 에러 (stderr) 메시지
koala.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
koala.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
koala.cpp: In function 'int main()':
koala.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
54 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |