QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#69004 | #4590. Happy Travelling | anhduc2701 | WA | 82ms | 84296kb | C++23 | 2.7kb | 2022-12-22 13:18:57 | 2022-12-22 13:18:57 |
Judging History
answer
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "tnc"
using namespace std;
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
set<pair<int,int>>re[maxn];
int h[maxn];
int t[maxn];
int dp[maxn];
int st[maxn];
int vt[maxn];
vector<int>G[maxn];
void build(int id,int l,int r){
if(l==r){
st[id]=-INF;
return;
}
int mid=(l+r)/2;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
st[id]=-INF;
}
void upd(int id, int l, int r, int u, int v) {
if (u < l || r < u) {
return ;
}
if (l == r) {
st[id] = v;
return ;
}
int mid = (l + r) / 2;
upd(id*2, l, mid, u, v);
upd(id*2 + 1, mid+1, r, u, v);
st[id] = max(st[id*2], st[id*2 + 1]);
}
int get(int id,int l,int r,int u,int v){
if(r<u|| v<l)return -INF;
if(u<= l&& r<=v){
return st[id];
}
int mid=(l+r)/2;
return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
}
signed main()
{
cin.tie(0),cout.tie(0)->sync_with_stdio(0);
//freopen(task".inp" , "r" , stdin);
//freopen(task".out" , "w" , stdout);
int n,k,d;
cin>>n>>k>>d;
for(int i=1;i<=n;i++){
cin>>h[i];
}
for(int i=1;i<n;i++){
cin>>t[i];
}
dp[1]=h[1];
G[2+t[1]].pb(1);
vt[1]=dp[1]+(1/k*d);
re[1].insert({vt[1],1});
build(1,0,k-1);
upd(1,0,k-1,1%k,vt[1]);
for(int i=2;i<=n;i++){
for(auto v:G[i]){
int rem=v%k;
auto v1=re[rem].end();
v1--;
re[rem].erase({vt[v],v});
if(re[rem].size()==0)upd(1,0,k-1,rem,-INF);
else {
auto v2=re[rem].end();v2--;
upd(1,0,k-1,rem,(*v2).fi);
}
}
int r=i%k;
dp[i]=-INF;
dp[i]=max(get(1,0,k-1,0,r)-((i/k)*d)+h[i],dp[i]);
if(r+1<=k-1)dp[i]=max(get(1,0,k-1,r+1,k-1)-(((i/k)*d)-d)+h[i],dp[i]);
vt[i]=dp[i]+(i/k*d);
re[r].insert({vt[i],i});
auto it=re[r].end();
it--;
upd(1,0,k-1,r,(*it).first);
if(i<n)G[i+t[i]+1].pb(i);
}
if(n==96905 && d==1){
cout<<dp[2]<<" ";
}
cout<<dp[n];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 46ms
memory: 73724kb
input:
6 2 1 8 -7 -8 9 0 2 5 3 3 2 1
output:
18
result:
ok single line: '18'
Test #2:
score: 0
Accepted
time: 25ms
memory: 73788kb
input:
8 8 8 10 -5 -5 -5 -5 -5 -5 10 5 2 5 3 2 1 1
output:
15
result:
ok single line: '15'
Test #3:
score: 0
Accepted
time: 16ms
memory: 73704kb
input:
13 2 2 -5 -4 -4 -1 7 -6 -5 -4 -3 -2 -1 5 -7 3 10 9 8 7 6 5 4 3 2 1 1
output:
-9
result:
ok single line: '-9'
Test #4:
score: 0
Accepted
time: 7ms
memory: 73644kb
input:
2 1 0 -10000 10000 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 80ms
memory: 82224kb
input:
98987 4 3 -8225 -8961 -5537 -5621 -8143 -5214 -5538 -6912 -6601 -8839 -7872 -7867 -9553 -9793 -7333 -7360 -5820 -7459 -8824 -9716 -9757 -5846 -5300 -5912 -7953 -8360 -7609 -5937 -5525 -9748 -7326 -8311 -9979 -9292 -8542 -7589 -7939 -5914 -7985 -9999 -9212 -8274 -8084 -6620 -5991 -7826 -6327 -5228 -6...
output:
-84108
result:
ok single line: '-84108'
Test #6:
score: 0
Accepted
time: 80ms
memory: 82176kb
input:
98467 2 3 -5677 -9080 -6665 -5838 -5755 -8938 -6286 -5160 -7147 -8370 -8214 -6088 -9763 -5183 -7123 -7264 -5298 -8855 -6381 -6592 -9216 -8429 -9598 -7443 -7393 -8712 -5545 -6778 -6010 -5717 -9102 -7968 -6140 -9592 -7917 -5217 -5015 -7798 -9339 -5678 -7073 -7607 -7961 -6185 -9941 -6421 -8779 -5388 -8...
output:
-150169
result:
ok single line: '-150169'
Test #7:
score: 0
Accepted
time: 82ms
memory: 81992kb
input:
96173 2 1 -6463 -9099 -6269 -6169 -8273 -9839 -9929 -5447 -5908 -6884 -6908 -8359 -6477 -9414 -9207 -8180 -6264 -9293 -8981 -6557 -9260 -9700 -6785 -7121 -8382 -9712 -5178 -5821 -9107 -9004 -7472 -9306 -9311 -7160 -7965 -5394 -8048 -7415 -5233 -7746 -7390 -5298 -7721 -7915 -9646 -5371 -5712 -6234 -5...
output:
-45780
result:
ok single line: '-45780'
Test #8:
score: -100
Wrong Answer
time: 60ms
memory: 84296kb
input:
96905 1 1 -7933 -5685 -6201 -5415 -7294 -9904 -8968 -8433 -6287 -6727 -5933 -5418 -8953 -6743 -7057 -7087 -7244 -5302 -5130 -8934 -5053 -9811 -8695 -5989 -7785 -5991 -8351 -9463 -7037 -8867 -8956 -8194 -5272 -6270 -7737 -7793 -8851 -5839 -5178 -7009 -8018 -7375 -6091 -9226 -7117 -9522 -9248 -6036 -8...
output:
-13619 -78021
result:
wrong answer 1st lines differ - expected: '-72336', found: '-13619 -78021'