QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#68996 | #4590. Happy Travelling | anhduc2701 | WA | 18ms | 75684kb | C++23 | 2.7kb | 2022-12-22 11:59:28 | 2022-12-22 11:59:29 |
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,vt[1]);
for(int i=2;i<=n;i++){
for(auto v:G[i]){
int rem=v%k;
auto v1=re[rem].end();
v1--;
if((*v1).se==v){
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);
}
}
else{
re[rem].erase({vt[v],v});
}
}
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);
}
cout<<dp[n];
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 9ms
memory: 74912kb
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: 18ms
memory: 75484kb
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: 3ms
memory: 75636kb
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: -100
Wrong Answer
time: 10ms
memory: 75684kb
input:
2 1 0 -10000 10000 1
output:
-999999999999990000
result:
wrong answer 1st lines differ - expected: '0', found: '-999999999999990000'